org.jgroups.blocks

Class ConnectionTableNIO

Implemented Interfaces:
Runnable

public class ConnectionTableNIO
extends ConnectionTable
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.

Author:
Bela Ban, Scott Marlow, Alex Fu

Nested Class Summary

static class
ConnectionTableNIO.SelectorWriteHandler
static class
ConnectionTableNIO.WriteRequest

Nested classes/interfaces inherited from class org.jgroups.blocks.ConnectionTable

ConnectionTable.ConnectionListener, ConnectionTable.Receiver

Field Summary

protected static Log
LOG

Fields inherited from class org.jgroups.blocks.ConnectionTable

log

Constructor Summary

ConnectionTableNIO(int srv_port)
ConnectionTableNIO(int srv_port, long reaper_interval, long conn_expire_time)
ConnectionTableNIO(ConnectionTable.Receiver r, InetAddress bind_addr, InetAddress external_addr, int srv_port, int max_port)
ConnectionTableNIO(ConnectionTable.Receiver r, InetAddress bind_addr, InetAddress external_addr, int srv_port, int max_port, long reaper_interval, long conn_expire_time)

Method Summary

protected ServerSocket
createServerSocket(int start_port, int end_port)
Finds first available port starting at start_port and returns server socket.
protected void
init()
void
run()
Acceptor thread.
void
stop()
Closes all open sockets, the server socket and all threads waiting for incoming messages

Methods inherited from class org.jgroups.blocks.ConnectionTable

addConnectionListener, createServerSocket, getLocalAddress, getNumConnections, getReceiveBufferSize, getSendBufferSize, getSocketConnectionTimeout, getUseSendQueues, init, receive, remove, removeConnectionListener, run, send, setReceiveBufferSize, setReceiver, setSendBufferSize, setSocketConnectionTimeout, setUseSendQueues, start, stop, toString

Field Details

LOG

protected static final Log LOG

Constructor Details

ConnectionTableNIO

public ConnectionTableNIO(int srv_port)
            throws Exception
Parameters:
srv_port -

ConnectionTableNIO

public ConnectionTableNIO(int srv_port,
                          long reaper_interval,
                          long conn_expire_time)
            throws Exception
Parameters:
srv_port -
reaper_interval -
conn_expire_time -

ConnectionTableNIO

public ConnectionTableNIO(ConnectionTable.Receiver r,
                          InetAddress bind_addr,
                          InetAddress external_addr,
                          int srv_port,
                          int max_port)
            throws Exception
Parameters:
r -
bind_addr -
external_addr -
srv_port -
max_port -

ConnectionTableNIO

public ConnectionTableNIO(ConnectionTable.Receiver r,
                          InetAddress bind_addr,
                          InetAddress external_addr,
                          int srv_port,
                          int max_port,
                          long reaper_interval,
                          long conn_expire_time)
            throws Exception
Parameters:
r -
bind_addr -
external_addr -
srv_port -
max_port -
reaper_interval -
conn_expire_time -

Method Details

createServerSocket

protected ServerSocket createServerSocket(int start_port,
                                          int end_port)
            throws Exception
Finds first available port starting at start_port and returns server socket. Sets srv_port
Overrides:
createServerSocket in interface ConnectionTable

init

protected void init()
            throws Exception
Overrides:
init in interface ConnectionTable

run

public void run()
Acceptor thread. Continuously accept new connections and assign readhandler/writehandler to them.
Overrides:
run in interface ConnectionTable

stop

public void stop()
Closes all open sockets, the server socket and all threads waiting for incoming messages
Overrides:
stop in interface ConnectionTable

Copyright B) 1998-2005 Bela Ban. All Rights Reserved.