## com.sun.grizzly
Interface SelectorHandler

All Superinterfaces:
  AttributeHolder, Copyable, Handler, SupportStateHolder<State>

All Known Subinterfaces:
  ComplexSelectorHandler

All Known Implementing Classes:
  RoundRobinSelectorHandler, SSLSelectorHandler, TCPSelectorHandler, UDPSelectorHandler

    public interface SelectorHandler

extends Handler, Copyable, AttributeHolder, SupportStateHolder<State>

A SelectorHandler handles all java.nio.channels.Selector operations. One or more instance of a Selector are handled by SelectorHandler. The logic for processing of SelectionKey interest (OP_ACCEPT,OP_READ, etc.) is usually defined using an instance of SelectorHandler.

Author:
  Jeanfrancois Arcand

Method Summary
`SelectableChannel` `acceptWithoutRegistration(SelectionKey key)` Accepts connection, without registering it for reading or writing
`ConnectorHandler` `acquireConnectorHandler()` Return an instance of the `ConnectorHandler`
`void` `closeChannel(SelectableChannel channel)` Closes `SelectableChannel`
`void` `configureChannel(SelectableChannel channel)` Configure the channel operations.
`AsyncQueueReader` `getAsyncQueueReader()` Returns `AsyncQueueReader` associated with this `SelectorHandler`.
`AsyncQueueWriter` `getAsyncQueueWriter()` Returns `AsyncQueueWriter` associated with this `SelectorHandler`.
`Class<? extends SelectionKeyHandler>` `getPreferredSelectionKeyHandler()` Get the preffered SelectionKeyHandler implementation for this SelectorHandler.
`ProtocolChainInstanceHandler` `getProtocolChainInstanceHandler()` Return the `ProtocolChainInstanceHandler`
`SelectionKeyHandler` `getSelectionKeyHandler()` Get the SelectionKeyHandler associated with this SelectorHandler.
`Selector` `getSelector()` Gets the underlying selector.
`boolean` `isOpen()` Is the underlying Selector open.
`Set<SelectionKey>` `keys()` The SelectionKey that has been registered.
`boolean` `onAcceptInterest(SelectionKey key, Context controllerCtx)` Handle OP_ACCEPT.
`boolean` `onConnectInterest(SelectionKey key, Context controllerCtx)` Handle OP_CONNECT.
`boolean` `onReadInterest(SelectionKey key, Context controllerCtx)` Handle OP_READ.
`boolean` `onWriteInterest(SelectionKey key, Context controllerCtx)` Handle OP_WRITE.
`void` `pause()` Pause this `SelectorHandler`
`Pipeline` `pipeline()` Return the `Pipeline` used to execute this `SelectorHandler`'s `SelectionKey` ops
`void` `postSelect(Context controllerCtx)` This method is garantee to always be called after operation Selector.select().
`void` `preSelect(Context controllerCtx)` This method is garantee to always be called before operation Selector.select().
`Controller.Protocol` `protocol()` A token decribing the protocol supported by an implementation of this interface
`void` `register(SelectableChannel channel, int ops)` Register the `SelectableChannel` on the `Selector`.
`void` `register(SelectionKey key, int ops)` Register the SelectionKey on the Selector.
`void` `releaseConnectorHandler(ConnectorHandler connectorHandler)` Release a ConnectorHandler.
`void` `resume()` Resume this `SelectorHandler`
`Set<SelectionKey>` `select(Context controllerCtx)` Invoke the Selector.select() method.
`void` `setPipeline(Pipeline pipeline)` Set the `Pipeline` used to execute this `SelectorHandler`'s `SelectionKey` ops
`void` `setProtocolChainInstanceHandler(ProtocolChainInstanceHandler protocolChainInstanceHandler)` Set the `ProtocolChainInstanceHandler` to use for creating instance of `ProtocolChain`.
`void` `setSelectionKeyHandler(SelectionKeyHandler selectionKeyHandler)` Set SelectionKeyHandler associated with this SelectorHandler.
`void` `setSelector(Selector selector)` Sets the underlying `Selector`
`void` `shutdown()` Shutdown this instance.

Methods inherited from interface com.sun.grizzly.util.Copyable
`copyTo`

Methods inherited from interface com.sun.grizzly.util.AttributeHolder
`getAttribute, getAttributes, removeAttribute, setAttribute, setAttributes`

Methods inherited from interface com.sun.grizzly.util.SupportStateHolder
`getStateHolder`

Method Detail

### protocol

    Controller.Protocol protocol()

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

  Returns:
    SelectorHandler supported protocol

### getSelector

    Selector getSelector()

  Gets the underlying selector.

  Returns:
    underlying `Selector`

### setSelector

    void setSelector(Selector selector)

  Sets the underlying `Selector`

  Parameters:
    `selector` - underlying `Selector`

### keys

    Set<SelectionKey> keys()

  The SelectionKey that has been registered.

### isOpen

    boolean isOpen()

  Is the underlying Selector open.

  Returns:
    true / false

### pause

    void pause()

  Pause this `SelectorHandler`

### resume

    void resume()

  Resume this `SelectorHandler`

### shutdown

    void shutdown()

  Shutdown this instance.

### preSelect

    void preSelect(Context controllerCtx)
                   throws IOException

  This method is garantee to always be called before operation Selector.select().

  Parameters:
    `controllerCtx` - `Context`
  Throws:
    `IOException`

### select

    Set<SelectionKey> select(Context controllerCtx)
                             throws IOException

  Invoke the Selector.select() method.

  Parameters:
    `controllerCtx` -
  Throws:
    `IOException`

### postSelect

    void postSelect(Context controllerCtx)
                    throws IOException

  This method is garantee to always be called after operation Selector.select().

  Parameters:
    `controllerCtx` - `Context`
  Throws:
    `IOException`

### register

    void register(SelectableChannel channel,
                  int ops)

  Register the `SelectableChannel` on the `Selector`.

  Parameters:
    `key` -
    `ops` - interested operations

### register

    void register(SelectionKey key,
                  int ops)

  Register the SelectionKey on the Selector.

  Parameters:
    `key` -
    `ops` - interested operations

### acceptWithoutRegistration

    SelectableChannel acceptWithoutRegistration(SelectionKey key)
                                                throws IOException

  Accepts connection, without registering it for reading or writing

  Parameters:
    `key` -
  Returns:
    accepted `SelectableChannel`
  Throws:
    `IOException`

### onAcceptInterest

    boolean onAcceptInterest(SelectionKey key,
                             Context controllerCtx)
                             throws IOException

  Handle OP_ACCEPT.

  Parameters:
    `key` - `SelectionKey`
    `controllerCtx` - `Context`
  Returns:
    true if and only if the ProtocolChain must be invoked after executing this method.
  Throws:
    `IOException`

### onReadInterest

    boolean onReadInterest(SelectionKey key,
                           Context controllerCtx)
                           throws IOException

  Handle OP_READ.

  Parameters:
    `key` - `SelectionKey`
    `controllerCtx` - `Context`
  Returns:
    true if and only if the ProtocolChain must be invoked after executing this method.
  Throws:
    `IOException`

### onWriteInterest

    boolean onWriteInterest(SelectionKey key,
                            Context controllerCtx)
                            throws IOException

  Handle OP_WRITE.

  Parameters:
    `key` - `SelectionKey`
    `controllerCtx` - `Context`
  Returns:
    true if and only if the ProtocolChain must be invoked after executing this method.
  Throws:
    `IOException`

### onConnectInterest

    boolean onConnectInterest(SelectionKey key,
                              Context controllerCtx)
                              throws IOException

  Handle OP_CONNECT.

  Parameters:
    `key` - `SelectionKey`
    `controllerCtx` - `Context`
  Returns:
    true if and only if the ProtocolChain must be invoked after executing this method.
  Throws:
    `IOException`

### acquireConnectorHandler

    ConnectorHandler acquireConnectorHandler()

  Return an instance of the `ConnectorHandler`

  Returns:
    `ConnectorHandler`

### releaseConnectorHandler

    void releaseConnectorHandler(ConnectorHandler connectorHandler)

  Release a ConnectorHandler.

  Parameters:
    `connectorHandler` - `ConnectorHandler`

### configureChannel

    void configureChannel(SelectableChannel channel)
                          throws IOException

  Configure the channel operations.

  Parameters:
    `channel` - `SelectableChannel` to configure
  Throws:
    `IOException` - on possible configuration related error

### getAsyncQueueReader

    AsyncQueueReader getAsyncQueueReader()

  Returns `AsyncQueueReader` associated with this `SelectorHandler`. Method will return null, if this `SelectorHandler` is not running.

  Returns:
    `AsyncQueueReader`

### getAsyncQueueWriter

    AsyncQueueWriter getAsyncQueueWriter()

  Returns `AsyncQueueWriter` associated with this `SelectorHandler`. Method will return null, if this `SelectorHandler` is not running.

  Returns:
    `AsyncQueueWriter`

### pipeline

    Pipeline pipeline()

  Return the `Pipeline` used to execute this `SelectorHandler`'s `SelectionKey` ops

  Returns:
    The pipeline to use, or null if the `Controller`'s `Pipeline` should be used.

### setPipeline

    void setPipeline(Pipeline pipeline)

  Set the `Pipeline` used to execute this `SelectorHandler`'s `SelectionKey` ops

  Parameters:
    `The` - pipeline to use, or null if the `Controller`'s `Pipeline` should be used.

### getPreferredSelectionKeyHandler

    Class<? extends SelectionKeyHandler> getPreferredSelectionKeyHandler()

  Get the preffered SelectionKeyHandler implementation for this SelectorHandler.

### getSelectionKeyHandler

    SelectionKeyHandler getSelectionKeyHandler()

  Get the SelectionKeyHandler associated with this SelectorHandler.

### setSelectionKeyHandler

    void setSelectionKeyHandler(SelectionKeyHandler selectionKeyHandler)

  Set SelectionKeyHandler associated with this SelectorHandler.

### setProtocolChainInstanceHandler

    void setProtocolChainInstanceHandler(ProtocolChainInstanceHandler protocolChainInstanceHandler)

  Set the `ProtocolChainInstanceHandler` to use for creating instance of `ProtocolChain`.

### getProtocolChainInstanceHandler

    ProtocolChainInstanceHandler getProtocolChainInstanceHandler()

  Return the `ProtocolChainInstanceHandler`

### closeChannel

    void closeChannel(SelectableChannel channel)

  Closes `SelectableChannel`

Copyright © 2008 SUN Microsystems. All Rights Reserved.