org.jgroups.blocks

## Class ConnectionTableNIO

- java.lang.Object
- - org.jgroups.blocks.BasicConnectionTable
  - - org.jgroups.blocks.ConnectionTableNIO

All Implemented Interfaces:
  java.lang.Runnable

    public class ConnectionTableNIO
    extends BasicConnectionTable
    implements java.lang.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

Nested Classes
`static class` `ConnectionTableNIO.MyFuture`
`static class` `ConnectionTableNIO.SelectorWriteHandler`
`static class` `ConnectionTableNIO.WriteRequest`

### Nested classes/interfaces inherited from class org.jgroups.blocks.BasicConnectionTable

`BasicConnectionTable.ConnectionListener, BasicConnectionTable.Receiver`

### Field Summary

### Fields inherited from class org.jgroups.blocks.BasicConnectionTable

`log, socket_factory`

### Constructor Summary

Constructors
Constructor and Description
`ConnectionTableNIO(BasicConnectionTable.Receiver r, java.net.InetAddress bind_addr, java.net.InetAddress external_addr, int srv_port, int max_port)`
`ConnectionTableNIO(BasicConnectionTable.Receiver r, java.net.InetAddress bind_addr, java.net.InetAddress external_addr, int srv_port, int max_port, boolean doStart)`
`ConnectionTableNIO(BasicConnectionTable.Receiver r, java.net.InetAddress bind_addr, java.net.InetAddress external_addr, int srv_port, int max_port, long reaper_interval, long conn_expire_time)`
`ConnectionTableNIO(BasicConnectionTable.Receiver r, java.net.InetAddress bind_addr, java.net.InetAddress external_addr, int srv_port, int max_port, long reaper_interval, long conn_expire_time, boolean doStart)`
`ConnectionTableNIO(int srv_port)`
`ConnectionTableNIO(int srv_port, long reaper_interval, long conn_expire_time)`

### Method Summary

Methods
`protected java.net.ServerSocket` `createServerSocket(int start_port, int end_port)` Finds first available port starting at start_port and returns server socket.
`long` `getProcessorKeepAliveTime()`
`int` `getProcessorMaxThreads()`
`int` `getProcessorMinThreads()`
`int` `getProcessorQueueSize()`
`int` `getProcessorThreads()`
`int` `getReaderThreads()`
`int` `getWriterThreads()`
`protected void` `init()`
`void` `run()` Acceptor thread.
`protected void` `runRequest(Address addr, java.nio.ByteBuffer buf)`
`void` `setProcessorKeepAliveTime(long m_processor_keepAliveTime)`
`void` `setProcessorMaxThreads(int m_processor_maxThreads)`
`void` `setProcessorMinThreads(int m_processor_minThreads)`
`void` `setProcessorQueueSize(int m_processor_queueSize)`
`void` `setProcessorThreads(int m_processor_threads)`
`void` `setReaderThreads(int m_reader_threads)`
`void` `setWriterThreads(int m_writer_threads)`
`void` `start()`
`void` `stop()` Closes all open sockets, the server socket and all threads waiting for incoming messages

### Methods inherited from class org.jgroups.blocks.BasicConnectionTable

`addConnectionListener, getLinger, getLocalAddress, getNumberOfConnectionCreations, getNumConnections, getPeerAddressReadTimeout, getReceiveBufferSize, getSendBufferSize, getSendQueueSize, getSocketConnectionTimeout, getSocketFactory, getTcpNodelay, getThreadFactory, getUseSendQueues, receive, removeConnection, removeConnectionListener, retainAll, send, setLinger, setPeerAddressReadTimeout, setReceiveBufferSize, setReceiver, setSendBufferSize, setSendQueueSize, setSocketConnectionTimeout, setSocketFactory, setTcpNodelay, setThreadFactory, setUseSendQueues, toString`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Constructor Detail

#### ConnectionTableNIO

    public ConnectionTableNIO(int srv_port)
                       throws java.lang.Exception

Parameters:
  `srv_port` -
Throws:
  `java.lang.Exception`

#### ConnectionTableNIO

    public ConnectionTableNIO(int srv_port,
                      long reaper_interval,
                      long conn_expire_time)
                       throws java.lang.Exception

Parameters:
  `srv_port` -
  `reaper_interval` -
  `conn_expire_time` -
Throws:
  `java.lang.Exception`

#### ConnectionTableNIO

    public ConnectionTableNIO(BasicConnectionTable.Receiver r,
                      java.net.InetAddress bind_addr,
                      java.net.InetAddress external_addr,
                      int srv_port,
                      int max_port)
                       throws java.lang.Exception

Parameters:
  `r` -
  `bind_addr` -
  `external_addr` -
  `srv_port` -
  `max_port` -
Throws:
  `java.lang.Exception`

#### ConnectionTableNIO

    public ConnectionTableNIO(BasicConnectionTable.Receiver r,
                      java.net.InetAddress bind_addr,
                      java.net.InetAddress external_addr,
                      int srv_port,
                      int max_port,
                      boolean doStart)
                       throws java.lang.Exception

Throws:
  `java.lang.Exception`

#### ConnectionTableNIO

    public ConnectionTableNIO(BasicConnectionTable.Receiver r,
                      java.net.InetAddress bind_addr,
                      java.net.InetAddress external_addr,
                      int srv_port,
                      int max_port,
                      long reaper_interval,
                      long conn_expire_time)
                       throws java.lang.Exception

Parameters:
  `r` -
  `bind_addr` -
  `external_addr` -
  `srv_port` -
  `max_port` -
  `reaper_interval` -
  `conn_expire_time` -
Throws:
  `java.lang.Exception`

#### ConnectionTableNIO

    public ConnectionTableNIO(BasicConnectionTable.Receiver r,
                      java.net.InetAddress bind_addr,
                      java.net.InetAddress external_addr,
                      int srv_port,
                      int max_port,
                      long reaper_interval,
                      long conn_expire_time,
                      boolean doStart)
                       throws java.lang.Exception

Throws:
  `java.lang.Exception`

### Method Detail

#### getReaderThreads

    public int getReaderThreads()

#### setReaderThreads

    public void setReaderThreads(int m_reader_threads)

#### getWriterThreads

    public int getWriterThreads()

#### setWriterThreads

    public void setWriterThreads(int m_writer_threads)

#### getProcessorThreads

    public int getProcessorThreads()

#### setProcessorThreads

    public void setProcessorThreads(int m_processor_threads)

#### getProcessorMinThreads

    public int getProcessorMinThreads()

#### setProcessorMinThreads

    public void setProcessorMinThreads(int m_processor_minThreads)

#### getProcessorMaxThreads

    public int getProcessorMaxThreads()

#### setProcessorMaxThreads

    public void setProcessorMaxThreads(int m_processor_maxThreads)

#### getProcessorQueueSize

    public int getProcessorQueueSize()

#### setProcessorQueueSize

    public void setProcessorQueueSize(int m_processor_queueSize)

#### getProcessorKeepAliveTime

    public long getProcessorKeepAliveTime()

#### setProcessorKeepAliveTime

    public void setProcessorKeepAliveTime(long m_processor_keepAliveTime)

#### start

    public final void start()
                     throws java.lang.Exception

Overrides:
  `start` in class `BasicConnectionTable`
Throws:
  `java.lang.Exception`

#### init

    protected void init()
                 throws java.lang.Exception

Throws:
  `java.lang.Exception`

#### stop

    public void stop()

Closes all open sockets, the server socket and all threads waiting for incoming messages

Overrides:
  `stop` in class `BasicConnectionTable`

#### run

    public void run()

Acceptor thread. Continuously accept new connections and assign readhandler/writehandler to them.

Specified by:
  `run` in interface `java.lang.Runnable`

#### createServerSocket

    protected java.net.ServerSocket createServerSocket(int start_port,
                                           int end_port)
                                                throws java.lang.Exception

Finds first available port starting at start_port and returns server socket. Sets srv_port

Throws:
  `java.lang.Exception`

#### runRequest

    protected void runRequest(Address addr,
                  java.nio.ByteBuffer buf)
                       throws java.lang.InterruptedException

Throws:
  `java.lang.InterruptedException`