org.jgroups.blocks
Class ConnectionTable
java.lang.Object
org.jgroups.blocks.ConnectionTable
- Runnable
public class ConnectionTable
extends java.lang.Object
implements Runnable
Manages incoming and outgoing TCP connections. For each outgoing message to destination P, if there
is not yet a connection for P, one will be created. Subsequent outgoing messages will use this
connection. For incoming messages, one server socket is created at startup. For each new incoming
client connecting, a new thread from a thread pool is allocated and listens for incoming messages
until the socket is closed by the peer.
Sockets/threads with no activity will be killed
after some time.
Incoming messages from any of the sockets can be received by setting the
message listener.
- Bela Ban
ConnectionTable
public ConnectionTable(int srv_port)
throws Exception
Regular ConnectionTable without expiration of idle connections
srv_port
- The port on which the server will listen. If this port is reserved, the next
free port will be taken (incrementing srv_port).
ConnectionTable
public ConnectionTable(int srv_port,
long reaper_interval,
long conn_expire_time)
throws Exception
ConnectionTable including a connection reaper. Connections that have been idle for more than conn_expire_time
milliseconds will be closed and removed from the connection table. On next access they will be re-created.
srv_port
- The port on which the server will listenreaper_interval
- Number of milliseconds to wait for reaper between attepts to reap idle connectionsconn_expire_time
- Number of milliseconds a connection can be idle (no traffic sent or received until
it will be reaped
ConnectionTable
public ConnectionTable(ConnectionTable.Receiver r,
InetAddress bind_addr,
int srv_port)
throws Exception
Create a ConnectionTable
r
- A reference to a receiver of all messages received by this class. Method receive()
will be called.bind_addr
- The host name or IP address of the interface to which the server socket will bind.
This is interesting only in multi-homed systems. If bind_addr is null, the
server socket will bind to the first available interface (e.g. /dev/hme0 on
Solaris or /dev/eth0 on Linux systems).srv_port
- The port to which the server socket will bind to. If this port is reserved, the next
free port will be taken (incrementing srv_port).
ConnectionTable
public ConnectionTable(ConnectionTable.Receiver r,
InetAddress bind_addr,
int srv_port,
long reaper_interval,
long conn_expire_time)
throws Exception
ConnectionTable including a connection reaper. Connections that have been idle for more than conn_expire_time
milliseconds will be closed and removed from the connection table. On next access they will be re-created.
bind_addr
- The host name or IP address of the interface to which the server socket will bind.
This is interesting only in multi-homed systems. If bind_addr is null, the
server socket will bind to the first available interface (e.g. /dev/hme0 on
Solaris or /dev/eth0 on Linux systems).srv_port
- The port on which the server will listen.If this port is reserved, the next
free port will be taken (incrementing srv_port).reaper_interval
- Number of milliseconds to wait for reaper between attepts to reap idle connectionsconn_expire_time
- Number of milliseconds a connection can be idle (no traffic sent or received until
it will be reaped
getLocalAddress
public Address getLocalAddress()
getReceiveBufferSize
public int getReceiveBufferSize()
getSendBufferSize
public int getSendBufferSize()
receive
public void receive(Message msg)
Calls the receiver callback. We serialize access to this method because it may be called concurrently
by several Connection handler threads. Therefore the receiver doesn't need to synchronize.
remove
public void remove(Address addr)
Remove addr
from connection table. This is typically triggered when a member is suspected.
run
public void run()
Acceptor thread. Continuously accept new connections. Create a new thread for each new
connection and put it in conns. When the thread should stop, it is
interrupted by the thread creator.
send
public void send(Message msg)
throws SocketException
Sends a message to a unicast destination. The destination has to be set
msg
- The message to send
setReceiveBufferSize
public void setReceiveBufferSize(int recv_buf_size)
setSendBufferSize
public void setSendBufferSize(int send_buf_size)
start
public void start()
throws Exception
stop
public void stop()
Closes all open sockets, the server socket and all threads waiting for incoming messages
toString
public String toString()
Copyright B) 2001,2002 www.jgroups.com . All Rights Reserved.