com.sun.grizzly
Interface SelectorHandler

All Superinterfaces:
AttributeHolder, Copyable, Handler, PendingIOhandler, SupportStateHolder<State>
All Known Subinterfaces:
ComplexSelectorHandler, HttpSelectorHandler
All Known Implementing Classes:
ReusableTCPSelectorHandler, ReusableUDPSelectorHandler, RoundRobinSelectorHandler, SelectorThreadHandler, SSLSelectorHandler, SSLSelectorThreadHandler, TCPSelectorHandler, UDPSelectorHandler

public interface SelectorHandler
extends Handler, Copyable, AttributeHolder, SupportStateHolder<State>, PendingIOhandler

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.
 ExecutorService getThreadPool()
          Return the ExecutorService used to execute this SelectorHandler's SelectionKey ops
 boolean isOpen()
          Is the underlying Selector open.
 SelectionKey keyFor(SelectableChannel channel)
          Returns SelectionKey, which represents binding between the SelectableChannel and this SelectorHandler
 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
 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(SelectableChannel channel, int ops, Object attachment)
          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 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 setThreadPool(ExecutorService threadPool)
          Set the ExecutorService used to execute this SelectorHandler's SelectionKey ops
 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
 
Methods inherited from interface com.sun.grizzly.tcp.PendingIOhandler
addPendingIO, addPendingKeyCancel
 

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

keyFor

SelectionKey keyFor(SelectableChannel channel)
Returns SelectionKey, which represents binding between the SelectableChannel and this SelectorHandler

Parameters:
channel - SelectableChannel
Returns:
SelectionKey, which represents binding between the SelectableChannel and this SelectorHandler

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(SelectableChannel channel,
              int ops,
              Object attachment)
Register the SelectableChannel on the Selector.

Parameters:
key -
ops - interested operations
attachment -

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

getThreadPool

ExecutorService getThreadPool()
Return the ExecutorService used to execute this SelectorHandler's SelectionKey ops

Returns:
The thread pool to use, or null if the Controller's ExecutorService should be used.

setThreadPool

void setThreadPool(ExecutorService threadPool)
Set the ExecutorService used to execute this SelectorHandler's SelectionKey ops

Parameters:
The - thread pool to use, or null if the Controller's ExecutorService 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 © 2013 Oracle Corporation. All Rights Reserved.