com.sun.grizzly
Class RoundRobinSelectorHandler

java.lang.Object
  extended by com.sun.grizzly.TCPSelectorHandler
      extended by com.sun.grizzly.RoundRobinSelectorHandler
All Implemented Interfaces:
ComplexSelectorHandler, Handler, LinuxSpinningWorkaround, SelectorHandler, PendingIOhandler, AttributeHolder, Copyable, SupportStateHolder<State>

public class RoundRobinSelectorHandler
extends TCPSelectorHandler
implements ComplexSelectorHandler

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, which handles "accept" events by registering newly accepted connections to auxiliary Controllers in a round robin fashion.

Author:
Alexey Stashok

Nested Class Summary
 
Nested classes/interfaces inherited from class com.sun.grizzly.TCPSelectorHandler
TCPSelectorHandler.ConnectChannelOperation, TCPSelectorHandler.RegisterChannelOperation, TCPSelectorHandler.RegisterKeyOperation, TCPSelectorHandler.RunnableOperation, TCPSelectorHandler.SelectionKeyCancelOperation
 
Field Summary
 
Fields inherited from class com.sun.grizzly.TCPSelectorHandler
asyncQueueReader, asyncQueueWriter, attributes, connectorInstanceHandler, inet, instanceHandler, isKeepAlive, isShutDown, linger, logger, portRange, postponedTasks, receiveBufferSize, reuseAddress, role, selectionKeyHandler, selector, selectorHandlerTasks, selectTimeout, sendBufferSize, serverSocket, serverSocketChannel, serverTimeout, socketTimeout, ssBackLog, stateHolder, tcpNoDelay, threadPool
 
Constructor Summary
RoundRobinSelectorHandler()
           
RoundRobinSelectorHandler(ReadController[] rrControllers)
           
 
Method Summary
 void addProtocolSupport(Controller.Protocol customProtocol)
          Add custom protocol support
 void copyTo(Copyable copy)
          Copies current object content to copy object
 ReadController nextController()
          Return next aux.
 boolean onAcceptInterest(SelectionKey key, Context context)
          Handle OP_ACCEPT.
 void shutdown()
          Shutdown this instance by closing its Selector and associated channels.
 boolean supportsClient(SelectorHandler selectorHandler)
          Checks if given SelectorHandler is supported on client-side by RoundRobinSelectorHandler
 boolean supportsProtocol(Controller.Protocol protocol)
          Checks if protocol is supported by RoundRobinSelectorHandler
 
Methods inherited from class com.sun.grizzly.TCPSelectorHandler
acceptWithoutRegistration, acquireConnectorHandler, addPendingIO, addPendingKeyCancel, boolean2Role, closeChannel, configureChannel, connect, getAsyncQueueReader, getAsyncQueueWriter, getAttribute, getAttributes, getConnectorInstanceHandlerDelegate, getInet, getLinger, getLogger, getPort, getPortLowLevel, getPortRange, getPreferredSelectionKeyHandler, getProtocolChainInstanceHandler, getRole, getSelectableChannel, getSelectionKeyHandler, getSelector, getSelectTimeout, getServerTimeout, getSocketTimeout, getSpinRate, getSsBackLog, getStateHolder, getThreadPool, invokeAsyncQueueReader, invokeAsyncQueueWriter, invokeCallbackHandler, isExecutePendingIOUsingSelectorThread, isKeepAlive, isOpen, isReuseAddress, isTcpNoDelay, keyFor, keys, onConnectInterest, onConnectOp, onReadInterest, onWriteInterest, pause, pollContext, postSelect, preSelect, processPendingOperations, protocol, register, register, register, releaseConnectorHandler, removeAttribute, resetSpinCounter, resume, select, setAttribute, setAttributes, setExecutePendingIOUsingSelectorThread, setInet, setKeepAlive, setLinger, setLogger, setMaxAcceptRetries, setPort, setPortRange, setProtocolChainInstanceHandler, setReceiveBufferSize, setReuseAddress, setRole, setSelectionKeyHandler, setSelector, setSelectTimeout, setSendBufferSize, setServerTimeout, setSocketTimeout, setSsBackLog, setTcpNoDelay, setThreadPool, workaroundSelectorSpin
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.sun.grizzly.SelectorHandler
acceptWithoutRegistration, acquireConnectorHandler, closeChannel, configureChannel, getAsyncQueueReader, getAsyncQueueWriter, getPreferredSelectionKeyHandler, getProtocolChainInstanceHandler, getSelectionKeyHandler, getSelector, getThreadPool, isOpen, keyFor, keys, onConnectInterest, onReadInterest, onWriteInterest, pause, postSelect, preSelect, protocol, register, register, register, releaseConnectorHandler, resume, select, setProtocolChainInstanceHandler, setSelectionKeyHandler, setSelector, setThreadPool
 
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
 

Constructor Detail

RoundRobinSelectorHandler

public RoundRobinSelectorHandler()

RoundRobinSelectorHandler

public RoundRobinSelectorHandler(ReadController[] rrControllers)
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
Overrides:
copyTo in class TCPSelectorHandler
Parameters:
copy - represents target object, where current object's content will be copied

onAcceptInterest

public boolean onAcceptInterest(SelectionKey key,
                                Context context)
                         throws IOException
Description copied from class: TCPSelectorHandler
Handle OP_ACCEPT.

Specified by:
onAcceptInterest in interface SelectorHandler
Overrides:
onAcceptInterest in class TCPSelectorHandler
Parameters:
key - SelectionKey
context - Context
Returns:
always returns false
Throws:
IOException

addProtocolSupport

public void addProtocolSupport(Controller.Protocol customProtocol)
Add custom protocol support

Parameters:
customProtocol - custom Controller.Protocol

supportsProtocol

public boolean supportsProtocol(Controller.Protocol protocol)
Checks if protocol is supported by RoundRobinSelectorHandler

Specified by:
supportsProtocol in interface ComplexSelectorHandler
Parameters:
protocol - Network protocol name
Returns:
true if protocol is supported, false otherwise

supportsClient

public boolean supportsClient(SelectorHandler selectorHandler)
Checks if given SelectorHandler is supported on client-side by RoundRobinSelectorHandler

Specified by:
supportsClient in interface ComplexSelectorHandler
Parameters:
selectorHandler - SelectorHandler
Returns:
true if selectorHandler is supported, false otherwise

nextController

public ReadController nextController()
Return next aux. ReadController to process an accepted connection

Specified by:
nextController in interface ComplexSelectorHandler
Returns:
next aux. ReadController

shutdown

public void shutdown()
Description copied from class: TCPSelectorHandler
Shutdown this instance by closing its Selector and associated channels.

Specified by:
shutdown in interface SelectorHandler
Overrides:
shutdown in class TCPSelectorHandler


Copyright © 2012 Oracle Corporation. All Rights Reserved.