com.sun.grizzly
Class ReusableTCPSelectorHandler
java.lang.Object
com.sun.grizzly.TCPSelectorHandler
com.sun.grizzly.ReusableTCPSelectorHandler
- All Implemented Interfaces:
- Handler, LinuxSpinningWorkaround, SelectorHandler, PendingIOhandler, AttributeHolder, Copyable, SupportStateHolder<State>
public class ReusableTCPSelectorHandler
- extends TCPSelectorHandler
This class extends a TCP implementation of a SelectorHandler
and reuses the accepted SocketChannel if a user tries to connect the same remote address.
This class is useful for only CLIENT_SERVER Role.
When the ServerSocketChannel of TCPSelectorHandler accepts a SocketChannel,
it is stored in acceptedSocketChannelMap which is based on
the key(remote SocketAddress) and the value(SocketChannel) pair.
Because of reusing the SocketChannel,
if a user has initialized the Selectorhandler with inet,
when a user tries to connect the remote with a local address for binding it,
duplicated binding will be prevented.
Here is scenario.
- accepted a SocketChannel from a remoteAddress
- tries to connect the remoteAddress with Controller like this.
"connectorHandler = controller.acquireConnectorHandler( Protocol.TCP );"
"connectorHandler.connect( remoteAddress, localAddress );"
Then, the accepted SocketChannel of the remoteAddress is reused for I/O operations.
Note: Actually, connectorHandler.close() doesn't allow the SocketChannel to be closed
because the SocketChannel is shared between server-side and client-side.
But you should guarantee calling connectorHandler.close() in order to prevent any connection leak,
after you have used connectorHandler.connect() once.
- Author:
- Bongjae Chang
| Fields inherited from class com.sun.grizzly.TCPSelectorHandler |
asyncQueueReader, asyncQueueWriter, attributes, connectorInstanceHandler, inet, instanceHandler, isShutDown, linger, logger, opToRegister, port, receiveBufferSize, reuseAddress, role, selectionKeyHandler, selector, selectTimeout, sendBufferSize, serverSocket, serverSocketChannel, serverTimeout, socketTimeout, ssBackLog, stateHolder, tcpNoDelay, threadPool |
| Methods inherited from class com.sun.grizzly.TCPSelectorHandler |
acquireConnectorHandler, addPendingIO, addPendingKeyCancel, boolean2Role, configureChannel, connect, getAsyncQueueReader, getAsyncQueueWriter, getAttribute, getAttributes, getConnectorInstanceHandlerDelegate, getInet, getLinger, getLogger, getPendingIOlimitPerThread, getPort, getPortLowLevel, getPreferredSelectionKeyHandler, getProtocolChainInstanceHandler, getRole, getSelectionKeyHandler, getSelector, getSelectTimeout, getServerTimeout, getSocketTimeout, getSpinRate, getSsBackLog, getStateHolder, getThreadPool, invokeAsyncQueueReader, invokeAsyncQueueWriter, invokeCallbackHandler, isFinishIOUsingCurrentThread, isOpen, isReuseAddress, isTcpNoDelay, keyFor, keys, onAcceptInterest, onConnectInterest, onConnectOp, onReadInterest, onWriteInterest, pause, pollContext, postSelect, preSelect, processPendingOperations, protocol, register, register, releaseConnectorHandler, removeAttribute, resetSpinCounter, resume, select, setAttribute, setAttributes, setFinishIOUsingCurrentThread, setInet, setLinger, setLogger, setMaxAcceptRetries, setPendingIOlimitPerThread, setPort, 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 |
ReusableTCPSelectorHandler
public ReusableTCPSelectorHandler()
copyTo
public void copyTo(Copyable copy)
- Specified by:
copyTo in interface Copyable- Overrides:
copyTo in class TCPSelectorHandler
getSelectableChannel
protected SelectableChannel getSelectableChannel(SocketAddress remoteAddress,
SocketAddress localAddress)
throws IOException
- Overrides:
getSelectableChannel in class TCPSelectorHandler
- Throws:
IOException
shutdown
public void shutdown()
- Shuntdown this instance by closing its Selector and associated channels.
- Specified by:
shutdown in interface SelectorHandler- Overrides:
shutdown in class TCPSelectorHandler
acceptWithoutRegistration
public SelectableChannel acceptWithoutRegistration(SelectionKey key)
throws IOException
- Accepts connection, without registering it for reading or writing
- Specified by:
acceptWithoutRegistration in interface SelectorHandler- Overrides:
acceptWithoutRegistration in class TCPSelectorHandler
- Returns:
- accepted
SelectableChannel
- Throws:
IOException
closeChannel
public void closeChannel(SelectableChannel channel)
- Closes
SelectableChannel
- Specified by:
closeChannel in interface SelectorHandler- Overrides:
closeChannel in class TCPSelectorHandler
Copyright © 2009 SUN Microsystems. All Rights Reserved.