com.sun.grizzly
Class TCPSelectorHandler

java.lang.Object
  extended by com.sun.grizzly.TCPSelectorHandler
All Implemented Interfaces:
Handler, LinuxSpinningWorkaround, SelectorHandler, PendingIOhandler, AttributeHolder, Copyable, SupportStateHolder<State>
Direct Known Subclasses:
ReusableTCPSelectorHandler, RoundRobinSelectorHandler, SelectorThreadHandler, SSLSelectorHandler, UDPSelectorHandler

public class TCPSelectorHandler
extends Object
implements SelectorHandler, LinuxSpinningWorkaround

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. This class represents a TCP implementation of a SelectorHandler. This class first bind a ServerSocketChannel to a TCP port and then start waiting for NIO events.

Author:
Jeanfrancois Arcand

Nested Class Summary
protected  class TCPSelectorHandler.ConnectChannelOperation
           
protected  class TCPSelectorHandler.RegisterChannelOperation
           
protected  class TCPSelectorHandler.RegisterKeyOperation
           
protected  class TCPSelectorHandler.RunnableOperation
           
protected  class TCPSelectorHandler.SelectionKeyCancelOperation
           
 
Field Summary
protected  AsyncQueueReader asyncQueueReader
          AsyncQueueWriter
protected  AsyncQueueWriter asyncQueueWriter
          AsyncQueueWriter
protected  Map<String,Object> attributes
          Attributes, associated with the SelectorHandler instance
protected  ConnectorInstanceHandler connectorInstanceHandler
          The ConnectorInstanceHandler used to return a new or pooled ConnectorHandler
protected  InetAddress inet
          The inet address to use when binding.
protected  ProtocolChainInstanceHandler instanceHandler
          The ProtocolChainInstanceHandler used by this instance.
protected  boolean isKeepAlive
          The socket keepAlive mode.
protected  AtomicBoolean isShutDown
          Flag, which shows whether shutdown was called for this SelectorHandler
protected  int linger
          The socket linger.
protected  Logger logger
           
protected  PortRange portRange
          The default port range.
protected  Queue<SelectorHandlerTask> postponedTasks
           
protected  int receiveBufferSize
          The size to which to set the receive buffer If this value is not greater than 0, it is not used.
protected  boolean reuseAddress
          The socket reuseAddress
protected  Role role
          Is this used for client only or client/server operation.
protected  SelectionKeyHandler selectionKeyHandler
          The SelectionKeyHandler associated with this SelectorHandler.
protected  Selector selector
          The single Selector.
protected  Queue<SelectorHandlerTask> selectorHandlerTasks
          The list of SelectionKeyOP to register next time the Selector.select is invoked.
protected  long selectTimeout
          The Selector time out.
protected  int sendBufferSize
          The size to which to set the send buffer If this value is not greater than 0, it is not used.
protected  ServerSocket serverSocket
          The ServerSocket instance.
protected  ServerSocketChannel serverSocketChannel
          The ServerSocketChannel.
protected  int serverTimeout
          The server socket time out
protected  int socketTimeout
          The socket time out
protected  int ssBackLog
          Server socket backlog.
protected  StateHolder<State> stateHolder
          This SelectorHandler StateHolder, which is shared among SelectorHandler and its clones
protected  boolean tcpNoDelay
          The socket tcpDelay.
protected  ExecutorService threadPool
          The ExecutorService used by this instance.
 
Constructor Summary
TCPSelectorHandler()
           
TCPSelectorHandler(boolean isClient)
          Create a TCPSelectorHandler only used with ConnectorHandler.
TCPSelectorHandler(Role role)
          Create a TCPSelectorHandler only used with ConnectorHandler.
 
Method Summary
 SelectableChannel acceptWithoutRegistration(SelectionKey key)
          Accepts connection, without registering it for reading or writing
 ConnectorHandler acquireConnectorHandler()
          Return an instance of the default ConnectorHandler, which is the TCPConnectorHandler
 void addPendingIO(Runnable runnable)
          Enqueues runnable to be executed on Selector thread.
 void addPendingKeyCancel(SelectionKey key)
          Enqueues SelectionKey for later cancel and close on a Selector thread.
protected static Role boolean2Role(boolean isClient)
          Returns the Role, depending on isClient value
 void closeChannel(SelectableChannel channel)
          Closes SelectableChannel
 void configureChannel(SelectableChannel channel)
          Configure the channel operations.
protected  void connect(SocketAddress remoteAddress, SocketAddress localAddress, CallbackHandler callbackHandler)
          Register a CallBackHandler to this Selector.
 void copyTo(Copyable copy)
          Copies current object content to copy object
 AsyncQueueReader getAsyncQueueReader()
          Returns AsyncQueueReader associated with this SelectorHandler.
 AsyncQueueWriter getAsyncQueueWriter()
          Returns AsyncQueueWriter associated with this SelectorHandler.
 Object getAttribute(String key)
          Return an object based on a key.
 Map<String,Object> getAttributes()
          Return a Map of attribute name/value pairs.
protected  Callable<ConnectorHandler> getConnectorInstanceHandlerDelegate()
          Return factory object, which knows how to create ConnectorInstanceHandler corresponding to the protocol
 InetAddress getInet()
           
 int getLinger()
           
 Logger getLogger()
           
 int getPort()
           
 int getPortLowLevel()
          Deprecated. Use getPort
 PortRange getPortRange()
           
 Class<? extends SelectionKeyHandler> getPreferredSelectionKeyHandler()
          Get the preffered SelectionKeyHandler implementation for this SelectorHandler.
 ProtocolChainInstanceHandler getProtocolChainInstanceHandler()
          Return the ProtocolChainInstanceHandler
 Role getRole()
          Gets this SelectorHandler current role.
protected  SelectableChannel getSelectableChannel(SocketAddress remoteAddress, SocketAddress localAddress)
           
 SelectionKeyHandler getSelectionKeyHandler()
          Get the SelectionKeyHandler associated with this SelectorHandler.
 Selector getSelector()
          Max number of pendingIO tasks that will be executed per worker thread.
 long getSelectTimeout()
           
 int getServerTimeout()
           
 int getSocketTimeout()
           
 int getSpinRate()
          Returns the Selector spinrate
 int getSsBackLog()
           
 StateHolder<State> getStateHolder()
          Gets StateHolder for this object
 ExecutorService getThreadPool()
          Return the ExecutorService used to execute this SelectorHandler's SelectionKey ops
protected  void invokeAsyncQueueReader(NIOContext context)
          Invoke a AsyncQueueReader
protected  void invokeAsyncQueueWriter(NIOContext context)
          Invoke a AsyncQueueWriter
protected  void invokeCallbackHandler(CallbackHandler callbackHandler, NIOContext context)
          Invoke a CallbackHandler via a Context instance.
 boolean isExecutePendingIOUsingSelectorThread()
          Return true, if selector thread has to be applied to execute I/O operation, or false (by default), meaning that I/O operation could be executed in the current thread.
 boolean isKeepAlive()
           
 boolean isOpen()
          Is the Selector open.
 boolean isReuseAddress()
           
 boolean isTcpNoDelay()
          Return the tcpNoDelay value used by the underlying accepted Sockets.
 SelectionKey keyFor(SelectableChannel channel)
          Returns SelectionKey, which represents binding between the SelectableChannel and this SelectorHandler
 Set<SelectionKey> keys()
          Return the set of SelectionKey registered on this Selector.
 boolean onAcceptInterest(SelectionKey key, Context ctx)
          Handle OP_ACCEPT.
 boolean onConnectInterest(SelectionKey key, Context ctx)
          Handle OP_CONNECT.
protected  void onConnectOp(Context ctx, TCPSelectorHandler.ConnectChannelOperation selectionKeyOp)
          Handle new OP_CONNECT ops.
 boolean onReadInterest(SelectionKey key, Context ctx)
          Handle OP_READ.
 boolean onWriteInterest(SelectionKey key, Context ctx)
          Handle OP_WRITE.
 void pause()
          Pause this SelectorHandler
protected  NIOContext pollContext(Context serverContext, SelectionKey key, Context.OpType opType)
          Polls Context from pool and initializes it.
 void postSelect(Context ctx)
          Invoked after Selector.select().
 void preSelect(Context ctx)
          Before invoking Selector.select(long), make sure the ServerSocketChannel has been created.
protected  void processPendingOperations(Context ctx)
           
 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 a SelectionKey to this Selector.
Storing each interest type in different queues removes the need of wrapper (SelectionKeyOP) while lowering thread contention due to the load is spread out on different queues.
 void releaseConnectorHandler(ConnectorHandler connectorHandler)
          Release a ConnectorHandler.
 Object removeAttribute(String key)
          Remove a key/value object.
 void resetSpinCounter()
          Resets the spincounter
 void resume()
          Resume this SelectorHandler
 Set<SelectionKey> select(Context ctx)
          Execute the Selector.select(...) operations.
 void setAttribute(String key, Object value)
          Set a key/value object.
 void setAttributes(Map<String,Object> attributes)
          Set a Map of attribute name/value pairs.
 void setExecutePendingIOUsingSelectorThread(boolean executePendingIOUsingSelectorThread)
          Set true, if selector thread has to be applied to execute I/O operation, or false (by default), meaning that I/O operation could be executed in the current thread.
 void setInet(InetAddress inet)
           
 void setKeepAlive(boolean isKeepAlive)
           
 void setLinger(int linger)
           
 void setLogger(Logger logger)
           
 void setMaxAcceptRetries(int maxAcceptRetries)
          Max number of accept() failures before abording.
 void setPort(int port)
           
 void setPortRange(PortRange portRange)
           
 void setProtocolChainInstanceHandler(ProtocolChainInstanceHandler instanceHandler)
          Set the ProtocolChainInstanceHandler to use for creating instance of ProtocolChain.
 void setReceiveBufferSize(int size)
          Sets the receiveBufferSize to the specified value
 void setReuseAddress(boolean reuseAddress)
           
 void setRole(Role role)
          Sets this SelectorHandler current role.
 void setSelectionKeyHandler(SelectionKeyHandler selectionKeyHandler)
          Set SelectionKeyHandler associated with this SelectorHandler.
 void setSelector(Selector selector)
          Sets the underlying Selector
 void setSelectTimeout(long selectTimeout)
           
 void setSendBufferSize(int size)
          Sets the sendBufferSize to the specified value
 void setServerTimeout(int serverTimeout)
           
 void setSocketTimeout(int socketTimeout)
           
 void setSsBackLog(int ssBackLog)
           
 void setTcpNoDelay(boolean tcpNoDelay)
          Enable (true) or disable (false) the underlying Socket's tcpNoDelay.
 void setThreadPool(ExecutorService threadPool)
          Set the ExecutorService used to execute this SelectorHandler's SelectionKey ops
 void shutdown()
          Shutdown this instance by closing its Selector and associated channels.
 void workaroundSelectorSpin()
          Execute workaround for selector spin issue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

connectorInstanceHandler

protected ConnectorInstanceHandler connectorInstanceHandler
The ConnectorInstanceHandler used to return a new or pooled ConnectorHandler


selectorHandlerTasks

protected final Queue<SelectorHandlerTask> selectorHandlerTasks
The list of SelectionKeyOP to register next time the Selector.select is invoked. can be combined read+write interest or Connect


postponedTasks

protected final Queue<SelectorHandlerTask> postponedTasks

tcpNoDelay

protected boolean tcpNoDelay
The socket tcpDelay. Default value for tcpNoDelay is disabled (set to true).


reuseAddress

protected boolean reuseAddress
The socket reuseAddress


isKeepAlive

protected boolean isKeepAlive
The socket keepAlive mode.


linger

protected int linger
The socket linger.


socketTimeout

protected int socketTimeout
The socket time out


logger

protected Logger logger

serverTimeout

protected int serverTimeout
The server socket time out


inet

protected InetAddress inet
The inet address to use when binding.


portRange

protected PortRange portRange
The default port range.


serverSocket

protected ServerSocket serverSocket
The ServerSocket instance.


serverSocketChannel

protected ServerSocketChannel serverSocketChannel
The ServerSocketChannel.


selector

protected Selector selector
The single Selector.


selectTimeout

protected long selectTimeout
The Selector time out.


ssBackLog

protected int ssBackLog
Server socket backlog.


role

protected Role role
Is this used for client only or client/server operation.


selectionKeyHandler

protected SelectionKeyHandler selectionKeyHandler
The SelectionKeyHandler associated with this SelectorHandler.


instanceHandler

protected ProtocolChainInstanceHandler instanceHandler
The ProtocolChainInstanceHandler used by this instance. If not set, and instance of the DefaultInstanceHandler will be created.


threadPool

protected ExecutorService threadPool
The ExecutorService used by this instance. If null - Controller's ExecutorService will be used


asyncQueueWriter

protected AsyncQueueWriter asyncQueueWriter
AsyncQueueWriter


asyncQueueReader

protected AsyncQueueReader asyncQueueReader
AsyncQueueWriter


attributes

protected Map<String,Object> attributes
Attributes, associated with the SelectorHandler instance


stateHolder

protected StateHolder<State> stateHolder
This SelectorHandler StateHolder, which is shared among SelectorHandler and its clones


isShutDown

protected final AtomicBoolean isShutDown
Flag, which shows whether shutdown was called for this SelectorHandler


sendBufferSize

protected int sendBufferSize
The size to which to set the send buffer If this value is not greater than 0, it is not used.


receiveBufferSize

protected int receiveBufferSize
The size to which to set the receive buffer If this value is not greater than 0, it is not used.

Constructor Detail

TCPSelectorHandler

public TCPSelectorHandler()

TCPSelectorHandler

public TCPSelectorHandler(boolean isClient)
Create a TCPSelectorHandler only used with ConnectorHandler.

Parameters:
isClient - true if this SelectorHandler is only used to handle ConnectorHandler.

TCPSelectorHandler

public TCPSelectorHandler(Role role)
Create a TCPSelectorHandler only used with ConnectorHandler.

Parameters:
role - the TCPSelectorHandler Role
Method Detail

copyTo

public void copyTo(Copyable copy)
Description copied from interface: Copyable
Copies current object content to copy object

Specified by:
copyTo in interface Copyable
Parameters:
copy - represents target object, where current object's content will be copied

keys

public Set<SelectionKey> keys()
Return the set of SelectionKey registered on this Selector.

Specified by:
keys in interface SelectorHandler

isOpen

public boolean isOpen()
Is the Selector open.

Specified by:
isOpen in interface SelectorHandler
Returns:
true / false

preSelect

public void preSelect(Context ctx)
               throws IOException
Before invoking Selector.select(long), make sure the ServerSocketChannel has been created. If true, then register all SelectionKey to the Selector.

Specified by:
preSelect in interface SelectorHandler
Parameters:
ctx - Context
Throws:
IOException

processPendingOperations

protected void processPendingOperations(Context ctx)
                                 throws IOException
Parameters:
ctx -
Throws:
IOException

onConnectOp

protected void onConnectOp(Context ctx,
                           TCPSelectorHandler.ConnectChannelOperation selectionKeyOp)
                    throws IOException
Handle new OP_CONNECT ops.

Throws:
IOException

select

public Set<SelectionKey> select(Context ctx)
                         throws IOException
Execute the Selector.select(...) operations.

Specified by:
select in interface SelectorHandler
Parameters:
ctx - Context
Returns:
Set of SelectionKey
Throws:
IOException

postSelect

public void postSelect(Context ctx)
Invoked after Selector.select().

Specified by:
postSelect in interface SelectorHandler
Parameters:
ctx - Context

addPendingIO

public void addPendingIO(Runnable runnable)
Enqueues runnable to be executed on Selector thread.

Specified by:
addPendingIO in interface PendingIOhandler

addPendingKeyCancel

public void addPendingKeyCancel(SelectionKey key)
Enqueues SelectionKey for later cancel and close on a Selector thread.

Specified by:
addPendingKeyCancel in interface PendingIOhandler

register

public void register(SelectionKey key,
                     int ops)
Register a SelectionKey to this Selector.
Storing each interest type in different queues removes the need of wrapper (SelectionKeyOP) while lowering thread contention due to the load is spread out on different queues.

Specified by:
register in interface SelectorHandler
Parameters:
key -
ops -

register

public void register(SelectableChannel channel,
                     int ops)
Description copied from interface: SelectorHandler
Register the SelectableChannel on the Selector.

Specified by:
register in interface SelectorHandler
ops - interested operations

register

public void register(SelectableChannel channel,
                     int ops,
                     Object attachment)
Description copied from interface: SelectorHandler
Register the SelectableChannel on the Selector.

Specified by:
register in interface SelectorHandler
ops - interested operations

connect

protected void connect(SocketAddress remoteAddress,
                       SocketAddress localAddress,
                       CallbackHandler callbackHandler)
                throws IOException
Register a CallBackHandler to this Selector.

Parameters:
remoteAddress - remote address to connect
localAddress - local address to bin
callbackHandler - CallbackHandler
Throws:
IOException

getSelectableChannel

protected SelectableChannel getSelectableChannel(SocketAddress remoteAddress,
                                                 SocketAddress localAddress)
                                          throws IOException
Throws:
IOException

pause

public void pause()
Pause this SelectorHandler

Specified by:
pause in interface SelectorHandler

resume

public void resume()
Resume this SelectorHandler

Specified by:
resume in interface SelectorHandler

getStateHolder

public StateHolder<State> getStateHolder()
Gets StateHolder for this object

Specified by:
getStateHolder in interface SupportStateHolder<State>
Returns:
StateHolder

shutdown

public void shutdown()
Shutdown this instance by closing its Selector and associated channels.

Specified by:
shutdown in interface SelectorHandler

acceptWithoutRegistration

public SelectableChannel acceptWithoutRegistration(SelectionKey key)
                                            throws IOException
Accepts connection, without registering it for reading or writing

Specified by:
acceptWithoutRegistration in interface SelectorHandler
Returns:
accepted SelectableChannel
Throws:
IOException

onAcceptInterest

public boolean onAcceptInterest(SelectionKey key,
                                Context ctx)
                         throws IOException
Handle OP_ACCEPT.

Specified by:
onAcceptInterest in interface SelectorHandler
Parameters:
ctx - Context
key - SelectionKey
Returns:
always returns false
Throws:
IOException

onReadInterest

public boolean onReadInterest(SelectionKey key,
                              Context ctx)
                       throws IOException
Handle OP_READ.

Specified by:
onReadInterest in interface SelectorHandler
Parameters:
ctx - Context
key - SelectionKey
Returns:
false if handled by a CallbackHandler, otherwise true
Throws:
IOException

onWriteInterest

public boolean onWriteInterest(SelectionKey key,
                               Context ctx)
                        throws IOException
Handle OP_WRITE.

Specified by:
onWriteInterest in interface SelectorHandler
Parameters:
key - SelectionKey
ctx - Context
Returns:
true if and only if the ProtocolChain must be invoked after executing this method.
Throws:
IOException

onConnectInterest

public boolean onConnectInterest(SelectionKey key,
                                 Context ctx)
                          throws IOException
Handle OP_CONNECT.

Specified by:
onConnectInterest in interface SelectorHandler
Parameters:
key - SelectionKey
ctx - Context
Returns:
true if and only if the ProtocolChain must be invoked after executing this method.
Throws:
IOException

invokeCallbackHandler

protected void invokeCallbackHandler(CallbackHandler callbackHandler,
                                     NIOContext context)
                              throws IOException
Invoke a CallbackHandler via a Context instance.

Parameters:
context - Context
Throws:
IOException

invokeAsyncQueueReader

protected void invokeAsyncQueueReader(NIOContext context)
                               throws IOException
Invoke a AsyncQueueReader

Parameters:
context - Context
Throws:
IOException

invokeAsyncQueueWriter

protected void invokeAsyncQueueWriter(NIOContext context)
                               throws IOException
Invoke a AsyncQueueWriter

Parameters:
context - Context
Throws:
IOException

acquireConnectorHandler

public ConnectorHandler acquireConnectorHandler()
Return an instance of the default ConnectorHandler, which is the TCPConnectorHandler

Specified by:
acquireConnectorHandler in interface SelectorHandler
Returns:
ConnectorHandler

releaseConnectorHandler

public void releaseConnectorHandler(ConnectorHandler connectorHandler)
Release a ConnectorHandler.

Specified by:
releaseConnectorHandler in interface SelectorHandler
Parameters:
connectorHandler - ConnectorHandler

protocol

public Controller.Protocol protocol()
A token decribing the protocol supported by an implementation of this interface

Specified by:
protocol in interface SelectorHandler
Returns:
SelectorHandler supported protocol

configureChannel

public void configureChannel(SelectableChannel channel)
                      throws IOException
Configure the channel operations.

Specified by:
configureChannel in interface SelectorHandler
Parameters:
channel - SelectableChannel to configure
Throws:
IOException - on possible configuration related error

getSelector

public final Selector getSelector()
Max number of pendingIO tasks that will be executed per worker thread.

Specified by:
getSelector in interface SelectorHandler
Returns:

setSelector

public final void setSelector(Selector selector)
Description copied from interface: SelectorHandler
Sets the underlying Selector

Specified by:
setSelector in interface SelectorHandler
Parameters:
selector - underlying Selector

getAsyncQueueReader

public AsyncQueueReader getAsyncQueueReader()
Returns AsyncQueueReader associated with this SelectorHandler. Method will return null, if this SelectorHandler is not running.

Specified by:
getAsyncQueueReader in interface SelectorHandler
Returns:
AsyncQueueReader

getAsyncQueueWriter

public AsyncQueueWriter getAsyncQueueWriter()
Returns AsyncQueueWriter associated with this SelectorHandler. Method will return null, if this SelectorHandler is not running.

Specified by:
getAsyncQueueWriter in interface SelectorHandler
Returns:
AsyncQueueWriter

getSelectTimeout

public long getSelectTimeout()

setSelectTimeout

public void setSelectTimeout(long selectTimeout)

getServerTimeout

public int getServerTimeout()

setServerTimeout

public void setServerTimeout(int serverTimeout)

getInet

public InetAddress getInet()

setInet

public void setInet(InetAddress inet)

getRole

public Role getRole()
Gets this SelectorHandler current role. TCPSelectorHandler could act as client, which corresponds to Role.CLIENT or client-server, which corresponds to the Role.CLIENT_SERVER

Returns:
the Role

setRole

public void setRole(Role role)
Sets this SelectorHandler current role. TCPSelectorHandler could act as client, which corresponds to Role.CLIENT or client-server, which corresponds to the Role.CLIENT_SERVER

Parameters:
role - the Role

getPortLowLevel

public int getPortLowLevel()
Deprecated. Use getPort

Returns port number SelectorHandler is listening on Similar to getPort(), but getting port number directly from connection (ServerSocket, DatagramSocket). So if default port number 0 was set during initialization, then getPort() will return 0, but getPortLowLevel() will return port number assigned by OS.

Returns:
port number or -1 if SelectorHandler was not initialized for accepting connections.

getPort

public int getPort()

setPort

public void setPort(int port)

getPortRange

public PortRange getPortRange()

setPortRange

public void setPortRange(PortRange portRange)

getSsBackLog

public int getSsBackLog()

setSsBackLog

public void setSsBackLog(int ssBackLog)

isTcpNoDelay

public boolean isTcpNoDelay()
Return the tcpNoDelay value used by the underlying accepted Sockets. Also see setTcpNoDelay(boolean tcpNoDelay)


setTcpNoDelay

public void setTcpNoDelay(boolean tcpNoDelay)
Enable (true) or disable (false) the underlying Socket's tcpNoDelay. Default value for tcpNoDelay is enabled (set to true), as according to the performance tests, it performs better for most cases. The Connector side should also set tcpNoDelay the same as it is set here whenever possible.


getLinger

public int getLinger()

setLinger

public void setLinger(int linger)

isKeepAlive

public boolean isKeepAlive()

setKeepAlive

public void setKeepAlive(boolean isKeepAlive)

getSocketTimeout

public int getSocketTimeout()

setSocketTimeout

public void setSocketTimeout(int socketTimeout)

getLogger

public Logger getLogger()

setLogger

public void setLogger(Logger logger)

isReuseAddress

public boolean isReuseAddress()

setReuseAddress

public void setReuseAddress(boolean reuseAddress)

getThreadPool

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

Specified by:
getThreadPool in interface SelectorHandler
Returns:
The thread pool to use, or null if the Controller's ExecutorService should be used.

setThreadPool

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

Specified by:
setThreadPool in interface SelectorHandler

getPreferredSelectionKeyHandler

public Class<? extends SelectionKeyHandler> getPreferredSelectionKeyHandler()
Get the preffered SelectionKeyHandler implementation for this SelectorHandler.

Specified by:
getPreferredSelectionKeyHandler in interface SelectorHandler

getSelectionKeyHandler

public SelectionKeyHandler getSelectionKeyHandler()
Get the SelectionKeyHandler associated with this SelectorHandler.

Specified by:
getSelectionKeyHandler in interface SelectorHandler

setSelectionKeyHandler

public void setSelectionKeyHandler(SelectionKeyHandler selectionKeyHandler)
Set SelectionKeyHandler associated with this SelectorHandler.

Specified by:
setSelectionKeyHandler in interface SelectorHandler

setProtocolChainInstanceHandler

public void setProtocolChainInstanceHandler(ProtocolChainInstanceHandler instanceHandler)
Set the ProtocolChainInstanceHandler to use for creating instance of ProtocolChain.

Specified by:
setProtocolChainInstanceHandler in interface SelectorHandler

getProtocolChainInstanceHandler

public ProtocolChainInstanceHandler getProtocolChainInstanceHandler()
Return the ProtocolChainInstanceHandler

Specified by:
getProtocolChainInstanceHandler in interface SelectorHandler

closeChannel

public void closeChannel(SelectableChannel channel)
Closes SelectableChannel

Specified by:
closeChannel in interface SelectorHandler

pollContext

protected NIOContext pollContext(Context serverContext,
                                 SelectionKey key,
                                 Context.OpType opType)
Polls Context from pool and initializes it.

Parameters:
serverContext - Controller context
key - SelectionKey
Returns:
Context

getConnectorInstanceHandlerDelegate

protected Callable<ConnectorHandler> getConnectorInstanceHandlerDelegate()
Return factory object, which knows how to create ConnectorInstanceHandler corresponding to the protocol

Returns:
factory

removeAttribute

public Object removeAttribute(String key)
Remove a key/value object. Method is not thread safe

Specified by:
removeAttribute in interface AttributeHolder
Parameters:
key - - name of an attribute
Returns:
attribute which has been removed

setAttribute

public void setAttribute(String key,
                         Object value)
Set a key/value object. Method is not thread safe

Specified by:
setAttribute in interface AttributeHolder
Parameters:
key - - name of an attribute
value - - value of named attribute

getAttribute

public Object getAttribute(String key)
Return an object based on a key. Method is not thread safe

Specified by:
getAttribute in interface AttributeHolder
Parameters:
key - - name of an attribute
Returns:
- attribute value for the key, null if key does not exist in attributes

setAttributes

public void setAttributes(Map<String,Object> attributes)
Set a Map of attribute name/value pairs. Old AttributeHolder values will not be available. Later changes of this Map will lead to changes to the current AttributeHolder.

Specified by:
setAttributes in interface AttributeHolder
Parameters:
attributes - - map of name/value pairs

getAttributes

public Map<String,Object> getAttributes()
Return a Map of attribute name/value pairs. Updates, performed on the returned Map will be reflected in this AttributeHolder

Specified by:
getAttributes in interface AttributeHolder
Returns:
- Map of attribute name/value pairs

boolean2Role

protected static Role boolean2Role(boolean isClient)
Returns the Role, depending on isClient value

Parameters:
isClient - true>tt>, if this SelectorHandler works in the client mode, or false otherwise.
Returns:
Role

resetSpinCounter

public void resetSpinCounter()
Resets the spincounter

Specified by:
resetSpinCounter in interface LinuxSpinningWorkaround

getSpinRate

public int getSpinRate()
Returns the Selector spinrate

Specified by:
getSpinRate in interface LinuxSpinningWorkaround
Returns:

workaroundSelectorSpin

public void workaroundSelectorSpin()
                            throws IOException
Execute workaround for selector spin issue

Specified by:
workaroundSelectorSpin in interface LinuxSpinningWorkaround
Throws:
IOException

keyFor

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

Specified by:
keyFor in interface SelectorHandler
Parameters:
channel - SelectableChannel
Returns:
SelectionKey, which represents binding between the SelectableChannel and this SelectorHandler

setSendBufferSize

public void setSendBufferSize(int size)
Sets the sendBufferSize to the specified value

Parameters:
size - the size to which to set the send buffer. This value should be greater than 0.

setReceiveBufferSize

public void setReceiveBufferSize(int size)
Sets the receiveBufferSize to the specified value

Parameters:
size - the size to which to set the receive buffer. This value should be greater than 0.

isExecutePendingIOUsingSelectorThread

public boolean isExecutePendingIOUsingSelectorThread()
Return true, if selector thread has to be applied to execute I/O operation, or false (by default), meaning that I/O operation could be executed in the current thread.

Returns:
the executePendingIOUsingSelectorThread

setExecutePendingIOUsingSelectorThread

public void setExecutePendingIOUsingSelectorThread(boolean executePendingIOUsingSelectorThread)
Set true, if selector thread has to be applied to execute I/O operation, or false (by default), meaning that I/O operation could be executed in the current thread. It's not safe to change this value, when TCPSelectorHandler has been already started.

Parameters:
executePendingIOUsingSelectorThread - the executePendingIOUsingSelectorThread to set

setMaxAcceptRetries

public void setMaxAcceptRetries(int maxAcceptRetries)
Max number of accept() failures before abording.

Parameters:
maxAcceptRetries -


Copyright © 2013 Oracle Corporation. All Rights Reserved.