Package org.jgroups.stack
Class RouterStub
java.lang.Object
org.jgroups.blocks.cs.ReceiverAdapter
org.jgroups.stack.RouterStub
- All Implemented Interfaces:
Comparable<RouterStub>,ConnectionListener,Receiver
public class RouterStub
extends ReceiverAdapter
implements Comparable<RouterStub>, ConnectionListener
Client stub that talks to a remote GossipRouter via blocking or non-blocking TCP
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfacestatic interfacestatic interface -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected BaseServerprotected RouterStub.CloseListenerprotected final Map<String, List<RouterStub.MembersNotification>> protected booleanprotected longprotected intprotected IpAddressprotected static final Logprotected intprotected booleanprotected RouterStub.StubReceiverprotected IpAddressprotected InetSocketAddressprotected intprotected SocketFactoryprotected booleanprotected final boolean -
Constructor Summary
ConstructorsConstructorDescriptionRouterStub(InetSocketAddress local_sa, InetSocketAddress remote_sa, boolean use_nio, RouterStub.CloseListener l, SocketFactory sf) RouterStub(InetSocketAddress local_sa, InetSocketAddress remote_sa, boolean use_nio, RouterStub.CloseListener l, SocketFactory sf, int linger) RouterStub(InetSocketAddress local_sa, InetSocketAddress remote_sa, boolean use_nio, RouterStub.CloseListener l, SocketFactory sf, int linger, boolean non_blocking_sends, int max_send_queue) Creates a stub to a remote_saGossipRouter. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidintvoidconnect()voidconnect(String group, Address addr, 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) voidprotected BaseServervoiddestroy()voiddisconnect(String group, Address addr) booleanintvoidgetMembers(String group, RouterStub.MembersNotification callback) Fetches a list ofPingDatafrom the GossipRouter, one for each member in the given group.booleanhandleHeartbeats(boolean f) inthashCode()booleanlonglocal()intmaxSendQueue(int s) booleannonBlockingSends(boolean b) protected voidnotifyResponse(String group, List<PingData> list) voidDelivers a message from a given sender to the applicationvoidReceive data from the given senderreceiver()remote()protected voidremoveResponse(String group, RouterStub.MembersNotification notif) protected booleanCreates remote from remote_sa.voidsendToAllMembers(String group, Address sender, byte[] data, int offset, int length) voidsendToMember(String group, Address dest, Address sender, byte[] data, int offset, int length) setLinger(int l) intsocketConnectionTimeout(int timeout) booleantcpNoDelay(boolean tcp_nodelay) toString()booleanuseNio()voidwriteRequest(GossipData req)
-
Field Details
-
client
-
local
-
remote
-
remote_sa
-
use_nio
protected final boolean use_nio -
receiver
-
close_listener
-
socket_factory
-
log
-
sock_conn_timeout
protected int sock_conn_timeout -
tcp_nodelay
protected boolean tcp_nodelay -
linger
protected int linger -
handle_heartbeats
protected boolean handle_heartbeats -
last_heartbeat
protected volatile long last_heartbeat -
non_blocking_sends
protected boolean non_blocking_sends -
max_send_queue
protected int max_send_queue -
get_members_map
-
-
Constructor Details
-
RouterStub
public RouterStub(InetSocketAddress local_sa, InetSocketAddress remote_sa, boolean use_nio, RouterStub.CloseListener l, SocketFactory sf) -
RouterStub
public RouterStub(InetSocketAddress local_sa, InetSocketAddress remote_sa, boolean use_nio, RouterStub.CloseListener l, SocketFactory sf, int linger) -
RouterStub
public RouterStub(InetSocketAddress local_sa, InetSocketAddress remote_sa, boolean use_nio, RouterStub.CloseListener l, SocketFactory sf, int linger, boolean non_blocking_sends, int max_send_queue) Creates a stub to a remote_saGossipRouter.- Parameters:
local_sa- The local_sa bind address and portremote_sa- The address:port of the GossipRouteruse_nio- Whether to use (TCP_NIO2) orTCPl- TheRouterStub.CloseListenersf- TheSocketFactoryto use to create the client socketlinger- SO_LINGER timeoutnon_blocking_sends- When true and a TcpClient is used, non-blocking sends are enabled (https://issues.redhat.com/browse/JGRP-2759)max_send_queue- The max size of the send queue for non-blocking sends
-
-
Method Details
-
local
-
remote
-
receiver
-
receiver
-
tcpNoDelay
public boolean tcpNoDelay() -
tcpNoDelay
-
connectionListener
-
connectionListener
-
socketConnectionTimeout
public int socketConnectionTimeout() -
socketConnectionTimeout
-
useNio
public boolean useNio() -
gossipRouterAddress
-
isConnected
public boolean isConnected() -
handleHeartbeats
-
handleHeartbeats
public boolean handleHeartbeats() -
lastHeartbeat
public long lastHeartbeat() -
getLinger
public int getLinger() -
setLinger
-
nonBlockingSends
public boolean nonBlockingSends() -
nonBlockingSends
-
maxSendQueue
public int maxSendQueue() -
maxSendQueue
-
connect
public void connect(String group, Address addr, String logical_name, PhysicalAddress phys_addr) throws Exception Registers 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:
Exception- Thrown when the registration failed
-
connect
- Throws:
Exception
-
_doConnect
- Throws:
Exception
-
disconnect
- Throws:
Exception
-
destroy
public void destroy() -
getMembers
Fetches 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:
Exception
-
sendToAllMembers
public void sendToAllMembers(String group, Address sender, byte[] data, int offset, int length) throws Exception - Throws:
Exception
-
sendToMember
public void sendToMember(String group, Address dest, Address sender, byte[] data, int offset, int length) throws Exception - Throws:
Exception
-
receive
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
Description copied from interface:ReceiverReceive data from the given sender -
connectionClosed
- Specified by:
connectionClosedin interfaceConnectionListener
-
connectionEstablished
- Specified by:
connectionEstablishedin interfaceConnectionListener
-
compareTo
- Specified by:
compareToin interfaceComparable<RouterStub>
-
hashCode
public int hashCode() -
equals
-
toString
-
resolveRemoteAddress
protected boolean resolveRemoteAddress()Creates remote from remote_sa. If the latter is unresolved, tries to resolve it one more time (e.g. via DNS) -
createClient
-
writeRequest
- Throws:
Exception
-
removeResponse
-
notifyResponse
-