## com.sun.grizzly.connectioncache.client
Class CacheableConnectorHandler

    java.lang.Object
      com.sun.grizzly.connectioncache.client.CacheableConnectorHandler

All Implemented Interfaces:
  CallbackHandler, ContactInfo<ConnectorHandler>, ConnectorHandler<SelectorHandler,CallbackHandler>, Handler, Closeable

    public class CacheableConnectorHandler

extends Object
implements ConnectorHandler<SelectorHandler,CallbackHandler>, ContactInfo<ConnectorHandler>, CallbackHandler

Extended implementation of the DefaultSelectionKeyHandler with ConnectionManagement integrated in it

Author:
  Alexey Stashok

Constructor Summary
`CacheableConnectorHandler(CacheableConnectorHandlerPool parentPool)`

Method Summary
`void` `close()` Close the underlying connection.
`void` `connect(SocketAddress remoteAddress)` Connect to hostname:port.
`void` `connect(SocketAddress remoteAddress, CallbackHandler callbackHandler)` Connect to hostname:port.
`void` `connect(SocketAddress remoteAddress, CallbackHandler callbackHandler, SelectorHandler 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, SelectorHandler selectorHandler)` Connect to hostname:port.
`ConnectorHandler` `createConnection()` Create a new Connection from this ContactInfo.
`boolean` `equals(Object o)`
`void` `finishConnect(SelectionKey key)` Decide how the OP_CONNECT final steps are handled.
`CallbackHandler` `getCallbackHandler()` Returns `ConnectorHandler`'s callback handler instance, which is used to process occuring events
`Controller` `getController()` Return the `Controller`
`SelectorHandler` `getSelectorHandler()` Method returns `SelectorHandler`, which manages this `ConnectorHandler`
`SelectableChannel` `getUnderlyingChannel()` Method returns `ConnectorHandler`'s underlying channel
`int` `hashCode()`
`void` `onConnect(IOEvent ioEvent)` This method is called when an non blocking OP_CONNECT is ready to get processed.
`void` `onRead(IOEvent ioEvent)` This method is called when an non blocking OP_READ is ready to get processed.
`void` `onWrite(IOEvent ioEvent)` This method is called when an non blocking OP_WRITE is ready to get processed.
`Controller.Protocol` `protocol()` A token decribing the protocol supported by an implementation of this interface
`long` `read(ByteBuffer byteBuffer, boolean blocking)` Read bytes.
`void` `release(int expectedResponseCount)` Releases underlying connection, which means it could be reused for writing by other `CacheableConnectorHandler`, however this `CacheableConnectorHandler` will be still interested in getting expectedResponseCount responses on it.
`void` `responseReceived()` Notifies connection cache, that response was received.
`void` `setCallbackHandler(CallbackHandler callbackHandler)` Sets `ConnectorHandler`'s callback handler instance, which is used to process occuring events
`void` `setController(Controller controller)` Set the `Controller` associated with this instance.
`String` `toString()`
`long` `write(ByteBuffer byteBuffer, boolean blocking)` Writes bytes.

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

Constructor Detail

### CacheableConnectorHandler

    public CacheableConnectorHandler(CacheableConnectorHandlerPool parentPool)

Method Detail

### protocol

    public Controller.Protocol protocol()

  Description copied from interface: `ConnectorHandler`
  A token decribing the protocol supported by an implementation of this interface

  Specified by:
    `protocol` in interface `ConnectorHandler<SelectorHandler,CallbackHandler>`
  Returns:
    `Controller.Protocol`

### connect

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

  Description copied from interface: `ConnectorHandler`
  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<SelectorHandler,CallbackHandler>`
  Parameters:
    `remoteAddress` - remote address to connect
    `callbackHandler` - the handler invoked by the Controller when an non blocking operation is ready to be handled.
    `selectorHandler` - `SelectorHandler`
  Throws:
    `IOException`

### connect

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

  Description copied from interface: `ConnectorHandler`
  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<SelectorHandler,CallbackHandler>`
  Parameters:
    `remoteAddress` - remote address to connect
    `callbackHandler` - the handler invoked by the Controller when an non blocking operation is ready to be handled.
  Throws:
    `IOException`

### connect

    public void connect(SocketAddress remoteAddress)
                 throws IOException

  Description copied from interface: `ConnectorHandler`
  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<SelectorHandler,CallbackHandler>`
  Parameters:
    `remoteAddress` - remote address to connect
  Throws:
    `IOException`

### connect

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

  Description copied from interface: `ConnectorHandler`
  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<SelectorHandler,CallbackHandler>`
  Parameters:
    `remoteAddress` - remote address to connect
    `localAddress` - local address to bind
    `callbackHandler` - the handler invoked by the Controller when an non blocking operation is ready to be handled.
    `selectorHandler` - `SelectorHandler`
  Throws:
    `IOException`

### connect

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

  Description copied from interface: `ConnectorHandler`
  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<SelectorHandler,CallbackHandler>`
  Parameters:
    `remoteAddress` - remote address to connect
    `localAddress` - local address to bind
    `callbackHandler` - the handler invoked by the Controller when an non blocking operation is ready to be handled.
  Throws:
    `IOException`

### connect

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

  Description copied from interface: `ConnectorHandler`
  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<SelectorHandler,CallbackHandler>`
  Parameters:
    `remoteAddress` - remote address to connect
    `localAddress` - local address to bind
  Throws:
    `IOException`

### release

    public void release(int expectedResponseCount)

  Releases underlying connection, which means it could be reused for writing by other `CacheableConnectorHandler`, however this `CacheableConnectorHandler` will be still interested in getting expectedResponseCount responses on it.

  Parameters:
    `expectedResponseCount` - number of reponses expected on the connection

### responseReceived

    public void responseReceived()

  Notifies connection cache, that response was received. And connection cache could decrease expected response counter by 1

### close

    public void close()
               throws IOException

  Description copied from interface: `ConnectorHandler`
  Close the underlying connection.

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

### read

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

  Description copied from interface: `ConnectorHandler`
  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<SelectorHandler,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

  Description copied from interface: `ConnectorHandler`
  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<SelectorHandler,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`

### finishConnect

    public void finishConnect(SelectionKey key)

  Description copied from interface: `ConnectorHandler`
  Decide how the OP_CONNECT final steps are handled.

  Specified by:
    `finishConnect` in interface `ConnectorHandler<SelectorHandler,CallbackHandler>`
  Parameters:
    `key` - `SelectionKey`

### setController

    public void setController(Controller controller)

  Description copied from interface: `ConnectorHandler`
  Set the `Controller` associated with this instance.

  Specified by:
    `setController` in interface `ConnectorHandler<SelectorHandler,CallbackHandler>`
  Parameters:
    `controller` - `Controller`

### getController

    public Controller getController()

  Description copied from interface: `ConnectorHandler`
  Return the `Controller`

  Specified by:
    `getController` in interface `ConnectorHandler<SelectorHandler,CallbackHandler>`
  Returns:

### getUnderlyingChannel

    public SelectableChannel getUnderlyingChannel()

  Description copied from interface: `ConnectorHandler`
  Method returns `ConnectorHandler`'s underlying channel

  Specified by:
    `getUnderlyingChannel` in interface `ConnectorHandler<SelectorHandler,CallbackHandler>`
  Returns:
    channel

### getCallbackHandler

    public CallbackHandler getCallbackHandler()

  Description copied from interface: `ConnectorHandler`
  Returns `ConnectorHandler`'s callback handler instance, which is used to process occuring events

  Specified by:
    `getCallbackHandler` in interface `ConnectorHandler<SelectorHandler,CallbackHandler>`
  Returns:
    callback handler

### setCallbackHandler

    public void setCallbackHandler(CallbackHandler callbackHandler)

  Description copied from interface: `ConnectorHandler`
  Sets `ConnectorHandler`'s callback handler instance, which is used to process occuring events

  Specified by:
    `setCallbackHandler` in interface `ConnectorHandler<SelectorHandler,CallbackHandler>`
  Parameters:
    `callbackHandler` - handler

### getSelectorHandler

    public SelectorHandler getSelectorHandler()

  Description copied from interface: `ConnectorHandler`
  Method returns `SelectorHandler`, which manages this `ConnectorHandler`

  Specified by:
    `getSelectorHandler` in interface `ConnectorHandler<SelectorHandler,CallbackHandler>`
  Returns:
    `SelectorHandler`

### createConnection

    public ConnectorHandler createConnection()
                                      throws IOException

  Description copied from interface: `ContactInfo`
  Create a new Connection from this ContactInfo. Throws an IOException if Connection creation fails.

  Specified by:
    `createConnection` in interface `ContactInfo<ConnectorHandler>`
  Returns:
    a connection
  Throws:
    `IOException`

### toString

    public String toString()

  Overrides:
    `toString` in class `Object`

### hashCode

    public int hashCode()

  Overrides:
    `hashCode` in class `Object`

### equals

    public boolean equals(Object o)

  Overrides:
    `equals` in class `Object`

### onConnect

    public void onConnect(IOEvent ioEvent)

  Description copied from interface: `CallbackHandler`
  This method is called when an non blocking OP_CONNECT is ready to get processed. This method must invoke ConnectorHandler.finishConnect() to complete the connection operations.

  Specified by:
    `onConnect` in interface `CallbackHandler`
  Parameters:
    `ioEvent` - an object containing information about the current non blocking connection.

### onRead

    public void onRead(IOEvent ioEvent)

  Description copied from interface: `CallbackHandler`
  This method is called when an non blocking OP_READ is ready to get processed.

  Specified by:
    `onRead` in interface `CallbackHandler`
  Parameters:
    `ioEvent` - an object containing information about the current non blocking connection.

### onWrite

    public void onWrite(IOEvent ioEvent)

  Description copied from interface: `CallbackHandler`
  This method is called when an non blocking OP_WRITE is ready to get processed.

  Specified by:
    `onWrite` in interface `CallbackHandler`
  Parameters:
    `ioEvent` - an object containing information about the current non blocking connection.

Copyright © 2008 SUN Microsystems. All Rights Reserved.