## com.sun.grizzly
Interface ConnectorHandler<E extends SelectorHandler,P extends CallbackHandler>

All Superinterfaces:
  Closeable, Handler

All Known Implementing Classes:
  CacheableConnectorHandler, SSLConnectorHandler, TCPConnectorHandler, UDPConnectorHandler

    public interface ConnectorHandler<E extends SelectorHandler,P extends CallbackHandler>

extends Handler, Closeable

Client side interface used to implement non blocking client operation. Implementation of this class must make sure the following methods are invoked in that order: (1) connect() (2) read() or write().

Author:
  Jeanfrancois Arcand

Method Summary
`void` `close()` Close the underlying connection.
`void` `connect(SocketAddress remoteAddress)` Connect to hostname:port.
`void` `connect(SocketAddress remoteAddress, P callbackHandler)` Connect to hostname:port.
`void` `connect(SocketAddress remoteAddress, P callbackHandler, E e)` Connect to hostname:port.
`void` `connect(SocketAddress remoteAddress, SocketAddress localAddress)` Connect to hostname:port.
`void` `connect(SocketAddress remoteAddress, SocketAddress localAddress, P callbackHandler)` Connect to hostname:port.
`void` `connect(SocketAddress remoteAddress, SocketAddress localAddress, P callbackHandler, E e)` Connect to hostname:port.
`void` `finishConnect(SelectionKey key)` Decide how the OP_CONNECT final steps are handled.
`P` `getCallbackHandler()` Returns `ConnectorHandler`'s callback handler instance, which is used to process occuring events
`Controller` `getController()` Return the `Controller`
`E` `getSelectorHandler()` Method returns `SelectorHandler`, which manages this `ConnectorHandler`
`SelectableChannel` `getUnderlyingChannel()` Method returns `ConnectorHandler`'s underlying channel
`Controller.Protocol` `protocol()` A token decribing the protocol supported by an implementation of this interface
`long` `read(ByteBuffer byteBuffer, boolean blocking)` Read bytes.
`void` `setCallbackHandler(P 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.
`long` `write(ByteBuffer byteBuffer, boolean blocking)` Writes bytes.

Method Detail

### protocol

    Controller.Protocol protocol()

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

  Returns:
    `Controller.Protocol`

### connect

    void connect(SocketAddress remoteAddress,
                 P callbackHandler,
                 E e)
                 throws IOException

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

  Parameters:
    `remoteAddress` - remote address to connect
    `callbackHandler` - the handler invoked by the Controller when an non blocking operation is ready to be handled.
    `e` - `SelectorHandler`
  Throws:
    `IOException`

### connect

    void connect(SocketAddress remoteAddress,
                 P 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.

  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

    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.

  Parameters:
    `remoteAddress` - remote address to connect
  Throws:
    `IOException`

### connect

    void connect(SocketAddress remoteAddress,
                 SocketAddress localAddress,
                 P callbackHandler,
                 E e)
                 throws IOException

  Connect to hostname:port. When an aysnchronous event happens (e.g OP_READ or OP_WRITE), the `Controller` will invoke the 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.
    `e` - `SelectorHandler`
  Throws:
    `IOException`

### connect

    void connect(SocketAddress remoteAddress,
                 SocketAddress localAddress,
                 P 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.

  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

    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.

  Parameters:
    `remoteAddress` - remote address to connect
    `localAddress` - local address to bind
  Throws:
    `IOException`

### read

    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.

  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

    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.

  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`

### close

    void close()
               throws IOException

  Close the underlying connection.

  Specified by:
    `close` in interface `Closeable`
  Throws:
    `IOException`

### finishConnect

    void finishConnect(SelectionKey key)
                       throws IOException

  Decide how the OP_CONNECT final steps are handled.

  Parameters:
    `key` - `SelectionKey`
  Throws:
    `IOException`

### setController

    void setController(Controller controller)

  Set the `Controller` associated with this instance.

  Parameters:
    `controller` - `Controller`

### getController

    Controller getController()

  Return the `Controller`

  Returns:

### getSelectorHandler

    E getSelectorHandler()

  Method returns `SelectorHandler`, which manages this `ConnectorHandler`

  Returns:
    `SelectorHandler`

### getUnderlyingChannel

    SelectableChannel getUnderlyingChannel()

  Method returns `ConnectorHandler`'s underlying channel

  Returns:
    channel

### getCallbackHandler

    P getCallbackHandler()

  Returns `ConnectorHandler`'s callback handler instance, which is used to process occuring events

  Returns:
    callback handler

### setCallbackHandler

    void setCallbackHandler(P callbackHandler)

  Sets `ConnectorHandler`'s callback handler instance, which is used to process occuring events

  Parameters:
    `callbackHandler` - handler

Copyright © 2008 SUN Microsystems. All Rights Reserved.