## com.sun.grizzly
Class TCPConnectorHandler

    java.lang.Object
      com.sun.grizzly.TCPConnectorHandler

All Implemented Interfaces:
  AsyncQueueReadable, AsyncQueueWritable, ConnectorHandler<TCPSelectorHandler,CallbackHandler>, Handler, Closeable

    public class TCPConnectorHandler

extends Object
implements ConnectorHandler<TCPSelectorHandler,CallbackHandler>, AsyncQueueWritable, AsyncQueueReadable

Non blocking TCP Connector Handler. The recommended way to use this class is by creating an external Controller and share the same SelectorHandler instance.

Recommended -----------

     Controller controller = new Controller();
     // new TCPSelectorHandler(true) means the Selector will be used only
     // for client operation (OP_READ, OP_WRITE, OP_CONNECT).
     TCPSelectorHandler tcpSelectorHandler = new TCPSelectorHandler(true);
     controller.setSelectorHandler(tcpSelectorHandler);
     TCPConnectorHandler tcpConnectorHandler = new TCPConnectorHandler();
     tcpConnectorHandler.connect(localhost,port, new CallbackHandler(){...},
                                 tcpSelectorHandler);
     TCPConnectorHandler tcpConnectorHandler2 = new TCPConnectorHandler();
     tcpConnectorHandler2.connect(localhost,port, new CallbackHandler(){...},
                                 tcpSelectorHandler);

Not recommended (but still works) ---------------------------------

     TCPConnectorHandler tcpConnectorHandler = new TCPConnectorHandler();
     tcpConnectorHandler.connect(localhost,port);

Internally, a new Controller will be created everytime connect(localhost,port) is invoked, which has an impact on performance.

Author:
  Jeanfrancois Arcand

Field Summary
`protected int` `connectionTimeout` Connection timeout is milliseconds
`protected int` `linger` The socket linger.
`protected boolean` `reuseAddress` The socket reuseAddress
`protected TCPSelectorHandler` `selectorHandler` The underlying TCPSelectorHandler used to mange SelectionKeys.
`protected boolean` `tcpNoDelay` The socket tcpDelay.

Constructor Summary
`TCPConnectorHandler()`

Method Summary
`void` `close()` Close the underlying connection.
`void` `configureChannel(SelectableChannel channel)`
`void` `connect(SocketAddress remoteAddress)` Connect to hostname:port.
`void` `connect(SocketAddress remoteAddress, CallbackHandler callbackHandler)` Connect to hostname:port.
`void` `connect(SocketAddress remoteAddress, CallbackHandler callbackHandler, TCPSelectorHandler selectorHandler)` Connect to hostname:port.
`void` `connect(SocketAddress remoteAddress, SocketAddress localAddress)` Connect to hostname:port.
`void` `connect(SocketAddress remoteAddress, SocketAddress localAddress, CallbackHandler callbackHandler)` Connect to hostname:port.
`void` `connect(SocketAddress remoteAddress, SocketAddress localAddress, CallbackHandler callbackHandler, TCPSelectorHandler selectorHandler)` Connect to hostname:port.
`void` `finishConnect(SelectionKey key)` Finish handling the OP_CONNECT interest ops.
`CallbackHandler` `getCallbackHandler()` Return the `CallbackHandler`.
`int` `getConnectionTimeout()` Get TCP channel connection timeout in milliseconds
`Controller` `getController()` Return the `Controller`
`int` `getLinger()`
`TCPSelectorHandler` `getSelectorHandler()` Return the associated `SelectorHandler`.
`SelectableChannel` `getUnderlyingChannel()` Return the current `SocketChannel` used.
`boolean` `isConnected()` Is the underlying SocketChannel connected.
`boolean` `isReuseAddress()`
`boolean` `isTcpNoDelay()` Return the tcpNoDelay value used by the underlying accepted Sockets.
`Controller.Protocol` `protocol()` A token decribing the protocol supported by an implementation of this interface
`long` `read(ByteBuffer byteBuffer, boolean blocking)` Read bytes.
`void` `readFromAsyncQueue(ByteBuffer buffer, AsyncReadCallbackHandler callbackHandler)` Method reads data to the `ByteBuffer` using async read queue.
`void` `readFromAsyncQueue(ByteBuffer buffer, AsyncReadCallbackHandler callbackHandler, AsyncReadCondition condition)` Method reads data to the `ByteBuffer` using async read queue.
`void` `readFromAsyncQueue(ByteBuffer buffer, AsyncReadCallbackHandler callbackHandler, AsyncReadCondition condition, AsyncQueueDataProcessor readPostProcessor)` Method reads data to the `ByteBuffer` using async read queue.
`void` `setCallbackHandler(CallbackHandler callbackHandler)` Set the `CallbackHandler`.
`void` `setConnectionTimeout(int connectionTimeout)` Set TCP channel connection timeout in milliseconds
`void` `setController(Controller controller)` Set the `Controller` to use with this instance.
`void` `setLinger(int linger)`
`void` `setReuseAddress(boolean reuseAddress)`
`void` `setTcpNoDelay(boolean tcpNoDelay)` Enable (true) or disable (false) the underlying Socket's tcpNoDelay.
`protected void` `setUnderlyingChannel(SocketChannel socketChannel)` Set the `SocketChannel`.
`long` `write(ByteBuffer byteBuffer, boolean blocking)` Writes bytes.
`void` `writeToAsyncQueue(ByteBuffer buffer)` Method writes `ByteBuffer` using async write queue.
`void` `writeToAsyncQueue(ByteBuffer buffer, AsyncWriteCallbackHandler callbackHandler)` Method writes `ByteBuffer` using async write queue.
`void` `writeToAsyncQueue(ByteBuffer buffer, AsyncWriteCallbackHandler callbackHandler, AsyncQueueDataProcessor writePreProcessor)` Method writes `ByteBuffer` using async write queue.
`void` `writeToAsyncQueue(ByteBuffer buffer, AsyncWriteCallbackHandler callbackHandler, AsyncQueueDataProcessor writePreProcessor, boolean isCloneByteBuffer)` Method writes `ByteBuffer` using async write queue.
`void` `writeToAsyncQueue(SocketAddress dstAddress, ByteBuffer buffer)` Method sends `ByteBuffer` using async write queue.
`void` `writeToAsyncQueue(SocketAddress dstAddress, ByteBuffer buffer, AsyncWriteCallbackHandler callbackHandler)` Method sends `ByteBuffer` using async write queue.
`void` `writeToAsyncQueue(SocketAddress dstAddress, ByteBuffer buffer, AsyncWriteCallbackHandler callbackHandler, AsyncQueueDataProcessor writePreProcessor)` Method sends `ByteBuffer` using async write queue.
`void` `writeToAsyncQueue(SocketAddress dstAddress, ByteBuffer buffer, AsyncWriteCallbackHandler callbackHandler, AsyncQueueDataProcessor writePreProcessor, boolean isCloneByteBuffer)` Method sends `ByteBuffer` using async write queue.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### selectorHandler

    protected TCPSelectorHandler selectorHandler

  The underlying TCPSelectorHandler used to mange SelectionKeys.

### tcpNoDelay

    protected boolean tcpNoDelay

  The socket tcpDelay. Default value for tcpNoDelay.

### reuseAddress

    protected boolean reuseAddress

  The socket reuseAddress

### linger

    protected int linger

  The socket linger.

### connectionTimeout

    protected int connectionTimeout

  Connection timeout is milliseconds

Constructor Detail

### TCPConnectorHandler

    public TCPConnectorHandler()

Method Detail

### connect

    public void connect(SocketAddress remoteAddress,
                        CallbackHandler callbackHandler)
                 throws IOException

  Connect to hostname:port. When an aysnchronous event happens (e.g OP_READ or OP_WRITE), the `Controller` will invoke the CallBackHandler.

  Specified by:
    `connect` in interface `ConnectorHandler<TCPSelectorHandler,CallbackHandler>`
  Parameters:
    `remoteAddress` - remote address to connect
    `callbackHandler` - the handler invoked by its associated `SelectorHandler` when a non blocking operation is ready to be handled. When null, all read and write operation will be delegated to the default `ProtocolChain` and its list of `ProtocolFilter` . When null, this `ConnectorHandler` will create an instance of `DefaultCallbackHandler`.
  Throws:
    `IOException`

### connect

    public void connect(SocketAddress remoteAddress,
                        SocketAddress localAddress,
                        CallbackHandler callbackHandler)
                 throws IOException

  Connect to hostname:port. When an aysnchronous event happens (e.g OP_READ or OP_WRITE), the `Controller` will invoke the CallBackHandler.

  Specified by:
    `connect` in interface `ConnectorHandler<TCPSelectorHandler,CallbackHandler>`
  Parameters:
    `remoteAddress` - remote address to connect
    `localAddress` - local address to bind
    `callbackHandler` - the handler invoked by its associated `SelectorHandler` when a non blocking operation is ready to be handled. When null, all read and write operation will be delegated to the default `ProtocolChain` and its list of `ProtocolFilter` . When null, this `ConnectorHandler` will create an instance of `DefaultCallbackHandler`.
  Throws:
    `IOException`

### connect

    public void connect(SocketAddress remoteAddress,
                        CallbackHandler callbackHandler,
                        TCPSelectorHandler selectorHandler)
                 throws IOException

  Connect to hostname:port. When an aysnchronous event happens (e.g OP_READ or OP_WRITE), the `Controller` will invoke the CallBackHandler.

  Specified by:
    `connect` in interface `ConnectorHandler<TCPSelectorHandler,CallbackHandler>`
  Parameters:
    `remoteAddress` - remote address to connect
    `callbackHandler` - the handler invoked by its associated `SelectorHandler` when a non blocking operation is ready to be handled. When null, all read and write operation will be delegated to the default `ProtocolChain` and its list of `ProtocolFilter` . When null, this `ConnectorHandler` will create an instance of `DefaultCallbackHandler`.
    `selectorHandler` - an instance of SelectorHandler.
  Throws:
    `IOException`

### connect

    public void connect(SocketAddress remoteAddress,
                        SocketAddress localAddress,
                        CallbackHandler callbackHandler,
                        TCPSelectorHandler selectorHandler)
                 throws IOException

  Connect to hostname:port. When an aysnchronous event happens (e.g OP_READ or OP_WRITE), the `Controller` will invoke the CallBackHandler.

  Specified by:
    `connect` in interface `ConnectorHandler<TCPSelectorHandler,CallbackHandler>`
  Parameters:
    `remoteAddress` - remote address to connect
    `localAddress` - local address to bin
    `callbackHandler` - the handler invoked by its associated `SelectorHandler` when a non blocking operation is ready to be handled. When null, all read and write operation will be delegated to the default `ProtocolChain` and its list of `ProtocolFilter` . When null, this `ConnectorHandler` will create an instance of `DefaultCallbackHandler`.
    `selectorHandler` - an instance of SelectorHandler.
  Throws:
    `IOException`

### connect

    public void connect(SocketAddress remoteAddress)
                 throws IOException

  Connect to hostname:port. Internally an instance of Controller and its default SelectorHandler will be created everytime this method is called. This method should be used only and only if no external Controller has been initialized.

  Specified by:
    `connect` in interface `ConnectorHandler<TCPSelectorHandler,CallbackHandler>`
  Parameters:
    `remoteAddress` - remote address to connect
  Throws:
    `IOException`

### connect

    public void connect(SocketAddress remoteAddress,
                        SocketAddress localAddress)
                 throws IOException

  Connect to hostname:port. Internally an instance of Controller and its default SelectorHandler will be created everytime this method is called. This method should be used only and only if no external Controller has been initialized.

  Specified by:
    `connect` in interface `ConnectorHandler<TCPSelectorHandler,CallbackHandler>`
  Parameters:
    `remoteAddress` - remote address to connect
    `localAddress` - local address to bin
  Throws:
    `IOException`

### read

    public long read(ByteBuffer byteBuffer,
                     boolean blocking)
              throws IOException

  Read bytes. If blocking is set to `true`, a pool of temporary `Selector` will be used to read bytes.

  Specified by:
    `read` in interface `ConnectorHandler<TCPSelectorHandler,CallbackHandler>`
  Parameters:
    `byteBuffer` - The byteBuffer to store bytes.
    `blocking` - `true` if a a pool of temporary Selector is required to handle a blocking read.
  Returns:
    number of bytes read
  Throws:
    `IOException`

### write

    public long write(ByteBuffer byteBuffer,
                      boolean blocking)
               throws IOException

  Writes bytes. If blocking is set to `true`, a pool of temporary `Selector` will be used to writes bytes.

  Specified by:
    `write` in interface `ConnectorHandler<TCPSelectorHandler,CallbackHandler>`
  Parameters:
    `byteBuffer` - The byteBuffer to write.
    `blocking` - `true` if a a pool of temporary Selector is required to handle a blocking write.
  Returns:
    number of bytes written
  Throws:
    `IOException`

### readFromAsyncQueue

    public void readFromAsyncQueue(ByteBuffer buffer,
                                   AsyncReadCallbackHandler callbackHandler)
                            throws IOException

  Method reads data to the `ByteBuffer` using async read queue. First, if read queue is empty - it tries to read to the `ByteBuffer` directly (without putting to the queue). If associated read queue is not empty or after direct reading `ByteBuffer` still has remaining place for next read - `ByteBuffer` will be added to `AsyncQueue`. If an exception occurs, during direct reading - it will be propagated to the caller directly, otherwise, if the `ByteBuffer` is added to a reading queue - exception notification will come via `AsyncReadCallbackHandler.onIOException()`

  Specified by:
    `readFromAsyncQueue` in interface `AsyncQueueReadable`
  Parameters:
    `buffer` - `ByteBuffer`
    `callbackHandler` - `AsyncReadCallbackHandler`, which will get notified, when `ByteBuffer` will get full
  Throws:
    `IOException`

### readFromAsyncQueue

    public void readFromAsyncQueue(ByteBuffer buffer,
                                   AsyncReadCallbackHandler callbackHandler,
                                   AsyncReadCondition condition)
                            throws IOException

  Method reads data to the `ByteBuffer` using async read queue. First, if read queue is empty - it tries to read to the `ByteBuffer` directly (without putting to the queue). If associated read queue is not empty or after direct reading `ByteBuffer` still has remaining place for next read - `ByteBuffer` will be added to `AsyncQueue`. If an exception occurs, during direct reading - it will be propagated to the caller directly, otherwise, if the `ByteBuffer` is added to a reading queue - exception notification will come via `AsyncReadCallbackHandler.onIOException()`

  Specified by:
    `readFromAsyncQueue` in interface `AsyncQueueReadable`
  Parameters:
    `buffer` - `ByteBuffer`
    `callbackHandler` - `AsyncReadCallbackHandler`, which will get notified, when `ByteBuffer` will get full
    `condition` - `AsyncReadCondition`, which will be called to check if read data is complete, and callbackHandler could be called
  Throws:
    `IOException`

### readFromAsyncQueue

    public void readFromAsyncQueue(ByteBuffer buffer,
                                   AsyncReadCallbackHandler callbackHandler,
                                   AsyncReadCondition condition,
                                   AsyncQueueDataProcessor readPostProcessor)
                            throws IOException

  Method reads data to the `ByteBuffer` using async read queue. First, if read queue is empty - it tries to read to the `ByteBuffer` directly (without putting to the queue). If associated read queue is not empty or after direct reading `ByteBuffer` still has remaining place for next read - `ByteBuffer` will be added to `AsyncQueue`. If an exception occurs, during direct reading - it will be propagated to the caller directly, otherwise, if the `ByteBuffer` is added to a reading queue - exception notification will come via `AsyncReadCallbackHandler.onIOException()`

  Specified by:
    `readFromAsyncQueue` in interface `AsyncQueueReadable`
  Parameters:
    `buffer` - `ByteBuffer`
    `callbackHandler` - `AsyncReadCallbackHandler`, which will get notified, when `ByteBuffer` will get full
    `condition` - `AsyncReadCondition`, which will be called to check if read data is complete, and callbackHandler could be called
    `readPostProcessor` - post processor, to be called to process read data
  Throws:
    `IOException`

### writeToAsyncQueue

    public void writeToAsyncQueue(ByteBuffer buffer)
                           throws IOException

  Method writes `ByteBuffer` using async write queue. First, if write queue is empty - it tries to write `ByteBuffer` directly (without putting to the queue). If associated write queue is not empty or after direct writing `ByteBuffer` still has ready data to be written - `ByteBuffer` will be added to `AsyncQueue`. If an exception occurs, during direct writing - it will be propagated to the caller directly, otherwise it will be just logged by Grizzly framework.

  Specified by:
    `writeToAsyncQueue` in interface `AsyncQueueWritable`
  Parameters:
    `buffer` - `ByteBuffer`
  Throws:
    `IOException`

### writeToAsyncQueue

    public void writeToAsyncQueue(ByteBuffer buffer,
                                  AsyncWriteCallbackHandler callbackHandler)
                           throws IOException

  Method writes `ByteBuffer` using async write queue. First, if write queue is empty - it tries to write `ByteBuffer` directly (without putting to the queue). If associated write queue is not empty or after direct writing `ByteBuffer` still has ready data to be written - `ByteBuffer` will be added to `AsyncQueue`. If an exception occurs, during direct writing - it will be propagated to the caller directly, otherwise, if the `ByteBuffer` is added to a writing queue - exception notification will come via `AsyncWriteCallbackHandler.onIOException()`

  Specified by:
    `writeToAsyncQueue` in interface `AsyncQueueWritable`
  Parameters:
    `buffer` - `ByteBuffer`
    `callbackHandler` - `AsyncWriteCallbackHandler`, which will get notified, when `ByteBuffer` will be completely written
  Throws:
    `IOException`

### writeToAsyncQueue

    public void writeToAsyncQueue(ByteBuffer buffer,
                                  AsyncWriteCallbackHandler callbackHandler,
                                  AsyncQueueDataProcessor writePreProcessor)
                           throws IOException

  Method writes `ByteBuffer` using async write queue. First, if write queue is empty - it tries to write `ByteBuffer` directly (without putting to the queue). If associated write queue is not empty or after direct writing `ByteBuffer` still has ready data to be written - `ByteBuffer` will be added to `AsyncQueue`. If an exception occurs, during direct writing - it will be propagated to the caller directly, otherwise, if the `ByteBuffer` is added to a writing queue - exception notification will come via `AsyncWriteCallbackHandler.onIOException()` Before data will be written on `SelectableChannel`, first it will be passed for preprocessing to `AsyncQueueDataProcessor`, and then preprocessor result data (`AsyncQueueDataProcessor.getResultByteBuffer()`) will be written on the `SelectableChannel`.

  Specified by:
    `writeToAsyncQueue` in interface `AsyncQueueWritable`
  Parameters:
    `buffer` - `ByteBuffer`
    `callbackHandler` - `AsyncWriteCallbackHandler`, which will get notified, when `ByteBuffer` will be completely written
    `writePreProcessor` - `AsyncQueueDataProcessor`, which will perform data processing, before it will be written on `SelectableChannel`
  Throws:
    `IOException`

### writeToAsyncQueue

    public void writeToAsyncQueue(ByteBuffer buffer,
                                  AsyncWriteCallbackHandler callbackHandler,
                                  AsyncQueueDataProcessor writePreProcessor,
                                  boolean isCloneByteBuffer)
                           throws IOException

  Method writes `ByteBuffer` using async write queue. First, if write queue is empty - it tries to write `ByteBuffer` directly (without putting to the queue). If associated write queue is not empty or after direct writing `ByteBuffer` still has ready data to be written - `ByteBuffer` will be added to `AsyncQueue`. If an exception occurs, during direct writing - it will be propagated to the caller directly, otherwise, if the `ByteBuffer` is added to a writing queue - exception notification will come via `AsyncWriteCallbackHandler.onIOException()` Before data will be written on `SelectableChannel`, first it will be passed for preprocessing to `AsyncQueueDataProcessor`, and then preprocessor result data (`AsyncQueueDataProcessor.getResultByteBuffer()`) will be written on the `SelectableChannel`.

  Specified by:
    `writeToAsyncQueue` in interface `AsyncQueueWritable`
  Parameters:
    `buffer` - `ByteBuffer`
    `callbackHandler` - `AsyncWriteCallbackHandler`, which will get notified, when `ByteBuffer` will be completely written
    `writePreProcessor` - `AsyncQueueDataProcessor`, which will perform data processing, before it will be written on `SelectableChannel`
    `isCloneByteBuffer` - if true - `AsyncQueueWriter` will clone given `ByteBuffer` before puting it to the `AsyncQueue`
  Throws:
    `IOException`

### writeToAsyncQueue

    public void writeToAsyncQueue(SocketAddress dstAddress,
                                  ByteBuffer buffer)
                           throws IOException

  Method sends `ByteBuffer` using async write queue. First, if write queue is empty - it tries to send `ByteBuffer` to the given `SocketAddress` directly (without putting to the queue). If associated write queue is not empty or after direct sending `ByteBuffer` still has ready data to be written - `ByteBuffer` will be added to `AsyncQueue`. If an exception occurs, during direct writing - it will be propagated to the caller directly, otherwise it will be just logged by Grizzly framework.

  Specified by:
    `writeToAsyncQueue` in interface `AsyncQueueWritable`
  Parameters:
    `dstAddress` - destination `SocketAddress` data will be sent to
    `buffer` - `ByteBuffer`
  Throws:
    `IOException`

### writeToAsyncQueue

    public void writeToAsyncQueue(SocketAddress dstAddress,
                                  ByteBuffer buffer,
                                  AsyncWriteCallbackHandler callbackHandler)
                           throws IOException

  Method sends `ByteBuffer` using async write queue. First, if write queue is empty - it tries to send `ByteBuffer` to the given `SocketAddress` directly (without putting to the queue). If associated write queue is not empty or after direct sending `ByteBuffer` still has ready data to be written - `ByteBuffer` will be added to `AsyncQueue`. If an exception occurs, during direct writing - it will be propagated to the caller directly, otherwise, if the `ByteBuffer` is added to a writing queue - exception notification will come via `AsyncWriteCallbackHandler.onIOException()`

  Specified by:
    `writeToAsyncQueue` in interface `AsyncQueueWritable`
  Parameters:
    `dstAddress` - destination `SocketAddress` data will be sent to
    `buffer` - `ByteBuffer`
    `callbackHandler` - `AsyncWriteCallbackHandler`, which will get notified, when `ByteBuffer` will be completely written
  Throws:
    `IOException`

### writeToAsyncQueue

    public void writeToAsyncQueue(SocketAddress dstAddress,
                                  ByteBuffer buffer,
                                  AsyncWriteCallbackHandler callbackHandler,
                                  AsyncQueueDataProcessor writePreProcessor)
                           throws IOException

  Method sends `ByteBuffer` using async write queue. First, if write queue is empty - it tries to send `ByteBuffer` to the given `SocketAddress` directly (without putting to the queue). If associated write queue is not empty or after direct sending `ByteBuffer` still has ready data to be written - `ByteBuffer` will be added to `AsyncQueue`. If an exception occurs, during direct writing - it will be propagated to the caller directly, otherwise, if the `ByteBuffer` is added to a writing queue - exception notification will come via `AsyncWriteCallbackHandler.onIOException()` Before data will be written on `SelectableChannel`, first it will be passed for preprocessing to `AsyncQueueDataProcessor`, and then preprocessor result data (`AsyncQueueDataProcessor.getResultByteBuffer()`) will be written on the `SelectableChannel`.

  Specified by:
    `writeToAsyncQueue` in interface `AsyncQueueWritable`
  Parameters:
    `dstAddress` - destination `SocketAddress` data will be sent to
    `buffer` - `ByteBuffer`
    `callbackHandler` - `AsyncWriteCallbackHandler`, which will get notified, when `ByteBuffer` will be completely written
    `writePreProcessor` - `AsyncQueueDataProcessor`, which will perform data processing, before it will be written on `SelectableChannel`
  Throws:
    `IOException`

### writeToAsyncQueue

    public void writeToAsyncQueue(SocketAddress dstAddress,
                                  ByteBuffer buffer,
                                  AsyncWriteCallbackHandler callbackHandler,
                                  AsyncQueueDataProcessor writePreProcessor,
                                  boolean isCloneByteBuffer)
                           throws IOException

  Method sends `ByteBuffer` using async write queue. First, if write queue is empty - it tries to send `ByteBuffer` to the given `SocketAddress` directly (without putting to the queue). If associated write queue is not empty or after direct sending `ByteBuffer` still has ready data to be written - `ByteBuffer` will be added to `AsyncQueue`. If an exception occurs, during direct writing - it will be propagated to the caller directly, otherwise, if the `ByteBuffer` is added to a writing queue - exception notification will come via `AsyncWriteCallbackHandler.onIOException()` Before data will be written on `SelectableChannel`, first it will be passed for preprocessing to `AsyncQueueDataProcessor`, and then preprocessor result data (`AsyncQueueDataProcessor.getResultByteBuffer()`) will be written on the `SelectableChannel`.

  Specified by:
    `writeToAsyncQueue` in interface `AsyncQueueWritable`
  Parameters:
    `dstAddress` - destination `SocketAddress` data will be sent to
    `buffer` - `ByteBuffer`
    `callbackHandler` - `AsyncWriteCallbackHandler`, which will get notified, when `ByteBuffer` will be completely written
    `writePreProcessor` - `AsyncQueueDataProcessor`, which will perform data processing, before it will be written on `SelectableChannel`
    `isCloneByteBuffer` - if true - `AsyncQueueWriter` will clone given `ByteBuffer` before puting it to the `AsyncQueue`
  Throws:
    `IOException`

### close

    public void close()
               throws IOException

  Close the underlying connection.

  Specified by:
    `close` in interface `ConnectorHandler<TCPSelectorHandler,CallbackHandler>`
  Specified by:
    `close` in interface `Closeable`
  Throws:
    `IOException`

### finishConnect

    public void finishConnect(SelectionKey key)
                       throws IOException

  Finish handling the OP_CONNECT interest ops.

  Specified by:
    `finishConnect` in interface `ConnectorHandler<TCPSelectorHandler,CallbackHandler>`
  Parameters:
    `key` - - a `SelectionKey`
  Throws:
    `IOException`

### configureChannel

    public void configureChannel(SelectableChannel channel)
                          throws IOException

  Throws:
    `IOException`

### protocol

    public Controller.Protocol protocol()

  A token decribing the protocol supported by an implementation of this interface

  Specified by:
    `protocol` in interface `ConnectorHandler<TCPSelectorHandler,CallbackHandler>`
  Returns:
    this `ConnectorHandler`'s protocol

### isConnected

    public boolean isConnected()

  Is the underlying SocketChannel connected.

  Returns:
    `true` if connected, otherwise `false`

### getController

    public Controller getController()

  Return the `Controller`

  Specified by:
    `getController` in interface `ConnectorHandler<TCPSelectorHandler,CallbackHandler>`
  Returns:
    the `Controller`

### setController

    public void setController(Controller controller)

  Set the `Controller` to use with this instance.

  Specified by:
    `setController` in interface `ConnectorHandler<TCPSelectorHandler,CallbackHandler>`
  Parameters:
    `controller` - the `Controller` to use with this instance.

### getUnderlyingChannel

    public SelectableChannel getUnderlyingChannel()

  Return the current `SocketChannel` used.

  Specified by:
    `getUnderlyingChannel` in interface `ConnectorHandler<TCPSelectorHandler,CallbackHandler>`
  Returns:
    the current `SocketChannel` used.

### setUnderlyingChannel

    protected void setUnderlyingChannel(SocketChannel socketChannel)

  Set the `SocketChannel`.

  Parameters:
    `the` - `SocketChannel` to use.

### getCallbackHandler

    public CallbackHandler getCallbackHandler()

  Return the `CallbackHandler`.

  Specified by:
    `getCallbackHandler` in interface `ConnectorHandler<TCPSelectorHandler,CallbackHandler>`
  Returns:
    the `CallbackHandler`.

### setCallbackHandler

    public void setCallbackHandler(CallbackHandler callbackHandler)

  Set the `CallbackHandler`.

  Specified by:
    `setCallbackHandler` in interface `ConnectorHandler<TCPSelectorHandler,CallbackHandler>`
  Parameters:
    `callbackHandler` - the `CallbackHandler`.

### getSelectorHandler

    public TCPSelectorHandler getSelectorHandler()

  Return the associated `SelectorHandler`.

  Specified by:
    `getSelectorHandler` in interface `ConnectorHandler<TCPSelectorHandler,CallbackHandler>`
  Returns:
    the associated `SelectorHandler`.

### isTcpNoDelay

    public boolean isTcpNoDelay()

  Return the tcpNoDelay value used by the underlying accepted Sockets. Also see setTcpNoDelay(boolean tcpNoDelay)

### setTcpNoDelay

    public void setTcpNoDelay(boolean tcpNoDelay)

  Enable (true) or disable (false) the underlying Socket's tcpNoDelay. Default value for tcpNoDelay is disabled (set to false). Disabled by default since enabling tcpNoDelay for most applications can cause packets to appear to arrive in a fragmented fashion where it takes multiple OP_READ events (i.e. multiple calls to read small messages). The common behaviour seen when this occurs is that often times a small number of bytes, as small as 1 byte at a time is read per OP_READ event dispatch. This results in a large number of system calls to read(), system calls to enable and disable interest ops and potentially a large number of thread context switches between a thread doing the Select(ing) and a worker thread doing the read. The Connector side should also set tcpNoDelay the same as it is set here whenever possible.

### getLinger

    public int getLinger()

  Returns:
    the linger value.
  See Also:
    `java.net.Socket#setLinger()`

### setLinger

    public void setLinger(int linger)

  See Also:
    `java.net.Socket#setLinger()`

### getConnectionTimeout

    public int getConnectionTimeout()

  Get TCP channel connection timeout in milliseconds

  Returns:
    TCP channel connection timeout in milliseconds

### setConnectionTimeout

    public void setConnectionTimeout(int connectionTimeout)

  Set TCP channel connection timeout in milliseconds

  Parameters:
    `connectionTimeout` - TCP channel connection timeout in milliseconds

### isReuseAddress

    public boolean isReuseAddress()

  See Also:
    `java.net.Socket#setReuseAddress()`

### setReuseAddress

    public void setReuseAddress(boolean reuseAddress)

  See Also:
    `java.net.Socket#setReuseAddress()`

Copyright © 2008 SUN Microsystems. All Rights Reserved.