## com.sun.grizzly
Class DefaultCallbackHandler

    java.lang.Object
      com.sun.grizzly.DefaultCallbackHandler

All Implemented Interfaces:
  CallbackHandler<Context>, Handler, SSLCallbackHandler<Context>

    public class DefaultCallbackHandler

extends Object
implements SSLCallbackHandler<Context>

Default `CallbackHandler` implementation that implements the connect operations, and delegate the read and write operations to its associated `SelectorHandler` `ProtocolChain`, like the default `SelectorHandler` is doing server side component. The code below can be used for by `ConnectorHandler` to manipulater the read and write operation of a non blocking client implementation.

A `ConnectorHandler` can use this `CallbackHandler` and delegate the processing of the bytes to a `ProtocolChain`

           Controller sel = new Controller();
           sel.setProtocolChainInstanceHandler(new DefaultProtocolChainInstanceHandler(){
               public ProtocolChain poll() {
                   ProtocolChain protocolChain = protocolChains.poll();
                   if (protocolChain == null){
                       protocolChain = new DefaultProtocolChain();
                       protocolChain.addFilter(new ReadWriteFilter());
                       protocolChain.addFilter(new LogFilter());
                   }
                   return protocolChain;
               }
           });
           TCPConnectorHandler tcph = Controller.acquireConnectorHandler(Protocol.TCP);
           tcph.connect(....);

With the above example, all read and write operations will be handled by the `ProtocolChain` instead of having to be implemented inside the `CallbackHandler.onRead(com.sun.grizzly.IOEvent<E>)` and `CallbackHandler.onWrite(com.sun.grizzly.IOEvent<E>)`

Author:
  Jeanfrancois Arcand

Constructor Summary
`DefaultCallbackHandler(ConnectorHandler connectorHandler)` Create a `CallbackHandler` that delegate the read and write operation to the `ProtocolChain` associated with the `ConnectorHandler`
`DefaultCallbackHandler(ConnectorHandler connectorHandler, boolean delegateToProtocolChain)` Create a `CallbackHandler` that delegate the read and write operation to the `ProtocolChain` associated with the `ConnectorHandler`.

Method Summary
`boolean` `isDelegateToProtocolChain()` Return `true>` if delegation to the `ProtocolChain` is enabled.
`void` `onConnect(IOEvent<Context> ioEvent)` Execute the non blocking connect operation.
`void` `onHandshake(IOEvent<Context> ioEvent)` By default, do nothing.
`void` `onRead(IOEvent<Context> ioEvent)` Delegate the processing of the read operation to the IOEvent{ associated {@link ProtocolChain}
`void` `onWrite(IOEvent<Context> ioEvent)` Delegate the processing of the write operation to the IOEvent{ associated {@link ProtocolChain}
`void` `setDelegateToProtocolChain(boolean delegateToProtocolChain)` Set to `true>` to enable delagation of the read and write operations to a `ProtocolChain` `true>` to enable delagation of the read and write operations to a `ProtocolChain`

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

Constructor Detail

### DefaultCallbackHandler

    public DefaultCallbackHandler(ConnectorHandler connectorHandler)

  Create a `CallbackHandler` that delegate the read and write operation to the `ProtocolChain` associated with the `ConnectorHandler`

  Parameters:
    `connectorHandler` - An instance of `ConnectorHandler`

### DefaultCallbackHandler

    public DefaultCallbackHandler(ConnectorHandler connectorHandler,
                                  boolean delegateToProtocolChain)

  Create a `CallbackHandler` that delegate the read and write operation to the `ProtocolChain` associated with the `ConnectorHandler`. Delegation is disabled when

  Parameters:
    `connectorHandler` - An instance of `ConnectorHandler`
    `delegateToProtocolChain` - true to delegate the read/write operation to a `ProtocolChain`

Method Detail

### onConnect

    public void onConnect(IOEvent<Context> ioEvent)

  Execute the non blocking connect operation.

  Specified by:
    `onConnect` in interface `CallbackHandler<Context>`
  Parameters:
    `ioEvent` - an `IOEvent` representing the current state of the OP_CONNECT operations.

### onRead

    public void onRead(IOEvent<Context> ioEvent)

  Delegate the processing of the read operation to the IOEvent{ associated {@link ProtocolChain}

  Specified by:
    `onRead` in interface `CallbackHandler<Context>`
  Parameters:
    `ioEvent` - an `IOEvent` representing the current state of the OP_CONNECT operations.

### onWrite

    public void onWrite(IOEvent<Context> ioEvent)

  Delegate the processing of the write operation to the IOEvent{ associated {@link ProtocolChain}

  Specified by:
    `onWrite` in interface `CallbackHandler<Context>`
  Parameters:
    `ioEvent` - an `IOEvent` representing the current state of the OP_CONNECT operations.

### onHandshake

    public void onHandshake(IOEvent<Context> ioEvent)

  By default, do nothing.

  Specified by:
    `onHandshake` in interface `SSLCallbackHandler<Context>`
  Parameters:
    `ioEvent` - an `IOEvent` representing the current state of the handshake operations.

### isDelegateToProtocolChain

    public boolean isDelegateToProtocolChain()

  Return `true>` if delegation to the `ProtocolChain` is enabled.

  Returns:
    `true>` if delegation to the `ProtocolChain` is enabled.

### setDelegateToProtocolChain

    public void setDelegateToProtocolChain(boolean delegateToProtocolChain)

  Set to `true>` to enable delagation of the read and write operations to a `ProtocolChain` `true>` to enable delagation of the read and write operations to a `ProtocolChain`

  Parameters:
    `delegateToProtocolChain` -

Copyright © 2008 SUN Microsystems. All Rights Reserved.