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 interface
RouterStub.CloseListener
static interface
RouterStub.MembersNotification
static interface
RouterStub.StubReceiver
-
Field Summary
Fields Modifier and Type Field Description protected BaseServer
client
protected RouterStub.CloseListener
close_listener
protected java.util.Map<java.lang.String,java.util.List<RouterStub.MembersNotification>>
get_members_map
protected boolean
handle_heartbeats
protected long
last_heartbeat
protected int
linger
protected IpAddress
local
protected static Log
log
protected int
max_send_queue
protected boolean
non_blocking_sends
protected RouterStub.StubReceiver
receiver
protected IpAddress
remote
protected java.net.InetSocketAddress
remote_sa
protected int
sock_conn_timeout
protected SocketFactory
socket_factory
protected boolean
tcp_nodelay
protected boolean
use_nio
-
Constructor Summary
Constructors Constructor Description RouterStub(java.net.InetSocketAddress local_sa, java.net.InetSocketAddress remote_sa, boolean use_nio, RouterStub.CloseListener l, SocketFactory sf)
RouterStub(java.net.InetSocketAddress local_sa, java.net.InetSocketAddress remote_sa, boolean use_nio, RouterStub.CloseListener l, SocketFactory sf, int linger)
RouterStub(java.net.InetSocketAddress local_sa, java.net.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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
_doConnect()
int
compareTo(RouterStub o)
void
connect()
void
connect(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.void
connectionClosed(Connection conn)
void
connectionEstablished(Connection conn)
RouterStub.CloseListener
connectionListener()
RouterStub
connectionListener(RouterStub.CloseListener l)
protected BaseServer
createClient(SocketFactory sf)
void
destroy()
void
disconnect(java.lang.String group, Address addr)
boolean
equals(java.lang.Object obj)
int
getLinger()
void
getMembers(java.lang.String group, RouterStub.MembersNotification callback)
Fetches a list ofPingData
from the GossipRouter, one for each member in the given group.IpAddress
gossipRouterAddress()
boolean
handleHeartbeats()
RouterStub
handleHeartbeats(boolean f)
int
hashCode()
boolean
isConnected()
long
lastHeartbeat()
IpAddress
local()
int
maxSendQueue()
RouterStub
maxSendQueue(int s)
boolean
nonBlockingSends()
RouterStub
nonBlockingSends(boolean b)
protected void
notifyResponse(java.lang.String group, java.util.List<PingData> list)
void
receive(Address sender, byte[] buf, int offset, int length)
Delivers a message from a given sender to the applicationvoid
receive(Address sender, java.io.DataInput in, int length)
Receive data from the given senderRouterStub.StubReceiver
receiver()
RouterStub
receiver(RouterStub.StubReceiver r)
IpAddress
remote()
protected void
removeResponse(java.lang.String group, RouterStub.MembersNotification notif)
protected boolean
resolveRemoteAddress()
Creates remote from remote_sa.void
sendToAllMembers(java.lang.String group, Address sender, byte[] data, int offset, int length)
void
sendToMember(java.lang.String group, Address dest, Address sender, byte[] data, int offset, int length)
RouterStub
setLinger(int l)
int
socketConnectionTimeout()
RouterStub
socketConnectionTimeout(int timeout)
boolean
tcpNoDelay()
RouterStub
tcpNoDelay(boolean tcp_nodelay)
java.lang.String
toString()
boolean
useNio()
void
writeRequest(GossipData req)
-
-
-
Field Detail
-
client
protected BaseServer client
-
local
protected IpAddress local
-
remote
protected IpAddress remote
-
remote_sa
protected java.net.InetSocketAddress remote_sa
-
use_nio
protected final boolean use_nio
-
receiver
protected RouterStub.StubReceiver receiver
-
close_listener
protected RouterStub.CloseListener close_listener
-
socket_factory
protected SocketFactory socket_factory
-
log
protected static final Log 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
protected final java.util.Map<java.lang.String,java.util.List<RouterStub.MembersNotification>> get_members_map
-
-
Constructor Detail
-
RouterStub
public RouterStub(java.net.InetSocketAddress local_sa, java.net.InetSocketAddress remote_sa, boolean use_nio, RouterStub.CloseListener l, SocketFactory sf)
-
RouterStub
public RouterStub(java.net.InetSocketAddress local_sa, java.net.InetSocketAddress remote_sa, boolean use_nio, RouterStub.CloseListener l, SocketFactory sf, int linger)
-
RouterStub
public RouterStub(java.net.InetSocketAddress local_sa, java.net.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
) orTCP
l
- TheRouterStub.CloseListener
sf
- TheSocketFactory
to 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 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()
-
handleHeartbeats
public RouterStub handleHeartbeats(boolean f)
-
handleHeartbeats
public boolean handleHeartbeats()
-
lastHeartbeat
public long lastHeartbeat()
-
getLinger
public int getLinger()
-
setLinger
public RouterStub setLinger(int l)
-
nonBlockingSends
public boolean nonBlockingSends()
-
nonBlockingSends
public RouterStub nonBlockingSends(boolean b)
-
maxSendQueue
public int maxSendQueue()
-
maxSendQueue
public RouterStub maxSendQueue(int s)
-
connect
public void connect(java.lang.String group, Address addr, java.lang.String logical_name, PhysicalAddress phys_addr) throws java.lang.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:
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.Exception
Fetches a list ofPingData
from 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:Receiver
Delivers a message from a given sender to the application- Specified by:
receive
in interfaceReceiver
- Overrides:
receive
in 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.io.DataInput in, int length)
Description copied from interface:Receiver
Receive data from the given sender
-
connectionClosed
public void connectionClosed(Connection conn)
- Specified by:
connectionClosed
in interfaceConnectionListener
-
connectionEstablished
public void connectionEstablished(Connection conn)
- Specified by:
connectionEstablished
in interfaceConnectionListener
-
compareTo
public int compareTo(RouterStub o)
- Specified by:
compareTo
in interfacejava.lang.Comparable<RouterStub>
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
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
protected BaseServer createClient(SocketFactory sf)
-
writeRequest
public 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)
-
-