Package org.jgroups.stack
Class RouterStub
- java.lang.Object
-
- org.jgroups.blocks.cs.ReceiverAdapter
-
- org.jgroups.stack.RouterStub
-
- All Implemented Interfaces:
java.lang.Comparable<RouterStub>,ConnectionListener,Receiver
public class RouterStub extends ReceiverAdapter implements java.lang.Comparable<RouterStub>, ConnectionListener
Client stub that talks to a remote GossipRouter via blocking or non-blocking TCP- Author:
- Bela Ban
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceRouterStub.CloseListenerstatic interfaceRouterStub.MembersNotificationstatic interfaceRouterStub.StubReceiver
-
Field Summary
Fields Modifier and Type Field Description protected BaseServerclientprotected RouterStub.CloseListenerclose_listenerprotected java.util.Map<java.lang.String,java.util.List<RouterStub.MembersNotification>>get_members_mapprotected IpAddresslocalprotected static Loglogprotected RouterStub.StubReceiverreceiverprotected IpAddressremoteprotected intsock_conn_timeoutprotected booleantcp_nodelayprotected booleanuse_nio
-
Constructor Summary
Constructors Constructor Description RouterStub(java.net.InetAddress bind_addr, int bind_port, java.net.InetAddress router_host, int router_port, boolean use_nio, RouterStub.CloseListener l, SocketFactory socketFactory)Creates a stub to a remote GossipRouterRouterStub(IpAddress local, IpAddress remote, boolean use_nio, RouterStub.CloseListener l, SocketFactory socketFactory)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void_doConnect()intcompareTo(RouterStub o)voidconnect()voidconnect(java.lang.String group, Address addr, java.lang.String logical_name, PhysicalAddress phys_addr)Registers mbr with the GossipRouter under the given group, with the given logical name and physical address.voidconnectionClosed(Connection conn)voidconnectionEstablished(Connection conn)RouterStub.CloseListenerconnectionListener()RouterStubconnectionListener(RouterStub.CloseListener l)voiddestroy()voiddisconnect(java.lang.String group, Address addr)booleanequals(java.lang.Object obj)voidgetMembers(java.lang.String group, RouterStub.MembersNotification callback)Fetches a list ofPingDatafrom the GossipRouter, one for each member in the given group.IpAddressgossipRouterAddress()inthashCode()booleanisConnected()IpAddresslocal()protected voidnotifyResponse(java.lang.String group, java.util.List<PingData> list)voidreceive(Address sender, byte[] buf, int offset, int length)Delivers a message from a given sender to the applicationvoidreceive(Address sender, java.io.DataInput in)voidreceive(Address sender, java.nio.ByteBuffer buf)The default implementation assumes thatByteBuffer.flip()orByteBuffer.rewind()was called on buf before invoking this callbackRouterStub.StubReceiverreceiver()RouterStubreceiver(RouterStub.StubReceiver r)IpAddressremote()protected voidremoveResponse(java.lang.String group, RouterStub.MembersNotification notif)voidsendToAllMembers(java.lang.String group, Address sender, byte[] data, int offset, int length)voidsendToMember(java.lang.String group, Address dest, Address sender, byte[] data, int offset, int length)RouterStubset(java.lang.String attr, java.lang.Object val)intsocketConnectionTimeout()RouterStubsocketConnectionTimeout(int timeout)booleantcpNoDelay()RouterStubtcpNoDelay(boolean tcp_nodelay)java.lang.StringtoString()booleanuseNio()protected voidwriteRequest(GossipData req)
-
-
-
Field Detail
-
client
protected BaseServer client
-
local
protected final IpAddress local
-
remote
protected final IpAddress remote
-
use_nio
protected final boolean use_nio
-
receiver
protected RouterStub.StubReceiver receiver
-
close_listener
protected RouterStub.CloseListener close_listener
-
log
protected static final Log log
-
sock_conn_timeout
protected int sock_conn_timeout
-
tcp_nodelay
protected boolean tcp_nodelay
-
get_members_map
protected final java.util.Map<java.lang.String,java.util.List<RouterStub.MembersNotification>> get_members_map
-
-
Constructor Detail
-
RouterStub
public RouterStub(java.net.InetAddress bind_addr, int bind_port, java.net.InetAddress router_host, int router_port, boolean use_nio, RouterStub.CloseListener l, SocketFactory socketFactory)Creates a stub to a remote GossipRouter- Parameters:
bind_addr- The local address to bind to. If null, one will be pickedbind_port- The local port. If 0, a random port will be usedrouter_host- The address of the remoteGossipRouterrouter_port- The port on which the remote GossipRouter is listeninguse_nio- Whether to use blocking or non-blocking IOl- TheRouterStub.CloseListener
-
RouterStub
public RouterStub(IpAddress local, IpAddress remote, boolean use_nio, RouterStub.CloseListener l, SocketFactory socketFactory)
-
-
Method Detail
-
local
public IpAddress local()
-
remote
public IpAddress remote()
-
receiver
public RouterStub receiver(RouterStub.StubReceiver r)
-
receiver
public RouterStub.StubReceiver receiver()
-
tcpNoDelay
public boolean tcpNoDelay()
-
tcpNoDelay
public RouterStub tcpNoDelay(boolean tcp_nodelay)
-
connectionListener
public RouterStub.CloseListener connectionListener()
-
connectionListener
public RouterStub connectionListener(RouterStub.CloseListener l)
-
socketConnectionTimeout
public int socketConnectionTimeout()
-
socketConnectionTimeout
public RouterStub socketConnectionTimeout(int timeout)
-
useNio
public boolean useNio()
-
gossipRouterAddress
public IpAddress gossipRouterAddress()
-
isConnected
public boolean isConnected()
-
set
public RouterStub set(java.lang.String attr, java.lang.Object val)
-
connect
public void connect(java.lang.String group, Address addr, java.lang.String logical_name, PhysicalAddress phys_addr) throws java.lang.ExceptionRegisters mbr with the GossipRouter under the given group, with the given logical name and physical address. Establishes a connection to the GossipRouter and sends a CONNECT message.- Parameters:
group- The group cluster) name under which to register the memberaddr- The address of the memberlogical_name- The logical name of the memberphys_addr- The physical address of the member- Throws:
java.lang.Exception- Thrown when the registration failed
-
connect
public void connect() throws java.lang.Exception- Throws:
java.lang.Exception
-
_doConnect
protected void _doConnect() throws java.lang.Exception- Throws:
java.lang.Exception
-
disconnect
public void disconnect(java.lang.String group, Address addr) throws java.lang.Exception- Throws:
java.lang.Exception
-
destroy
public void destroy()
-
getMembers
public void getMembers(java.lang.String group, RouterStub.MembersNotification callback) throws java.lang.ExceptionFetches a list ofPingDatafrom the GossipRouter, one for each member in the given group. This call returns immediately and when the results are available, theRouterStub.MembersNotification.members(List)callback will be invoked.- Parameters:
group- The group for which we need members informationcallback- The callback to be invoked.- Throws:
java.lang.Exception
-
sendToAllMembers
public void sendToAllMembers(java.lang.String group, Address sender, byte[] data, int offset, int length) throws java.lang.Exception- Throws:
java.lang.Exception
-
sendToMember
public void sendToMember(java.lang.String group, Address dest, Address sender, byte[] data, int offset, int length) throws java.lang.Exception- Throws:
java.lang.Exception
-
receive
public void receive(Address sender, byte[] buf, int offset, int length)
Description copied from interface:ReceiverDelivers a message from a given sender to the application- Specified by:
receivein interfaceReceiver- Overrides:
receivein classReceiverAdapter- Parameters:
sender- The sender of the messagebuf- The buffer. An application typically de-serializes data from the buffer into objects used by the application. Note that when receive() returns, it is not safe to use the buffer any longer; if an application needs to use a buffer after this callback returns, it must make a copy.offset- The offset at which the received data startslength- The length of the received data
-
receive
public void receive(Address sender, java.nio.ByteBuffer buf)
Description copied from class:ReceiverAdapterThe default implementation assumes thatByteBuffer.flip()orByteBuffer.rewind()was called on buf before invoking this callback- Specified by:
receivein interfaceReceiver- Overrides:
receivein classReceiverAdapter- Parameters:
sender- The sender of the messagebuf- The buffer. An application typically de-serializes data from the buffer into objects used by the application. Note that when receive() returns, it is not safe to use the buffer any longer; if an application needs to use a buffer after this callback returns, it must make a copy. Note that buf could be a direct ByteBuffer.
-
receive
public void receive(Address sender, java.io.DataInput in) throws java.lang.Exception
- Specified by:
receivein interfaceReceiver- Overrides:
receivein classReceiverAdapter- Throws:
java.lang.Exception
-
connectionClosed
public void connectionClosed(Connection conn)
- Specified by:
connectionClosedin interfaceConnectionListener
-
connectionEstablished
public void connectionEstablished(Connection conn)
- Specified by:
connectionEstablishedin interfaceConnectionListener
-
compareTo
public int compareTo(RouterStub o)
- Specified by:
compareToin interfacejava.lang.Comparable<RouterStub>
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
writeRequest
protected void writeRequest(GossipData req) throws java.lang.Exception
- Throws:
java.lang.Exception
-
removeResponse
protected void removeResponse(java.lang.String group, RouterStub.MembersNotification notif)
-
notifyResponse
protected void notifyResponse(java.lang.String group, java.util.List<PingData> list)
-
-