com.sun.grizzly
Class ReusableUDPSelectorHandler

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

public class ReusableUDPSelectorHandler
extends UDPSelectorHandler

This class extends a UDP implementation of a SelectorHandler and reuses the opened DatagramChannel if a user tries to connect any remote addresses. This class is useful for only CLIENT_SERVER Role. Because of reusing the DatagramChannel, if a user has initialized the Selectorhandler with inet, when a user tries to connect a remote with a local address for binding it, duplicated binding will be prevented. Here is scenario. - opened a DatagramChannel from SelectorHandler with CLIENT_SERVER role - tries to connect the remoteAddress with Controller like this. "connectorHandler = controller.acquireConnectorHandler( Protocol.UDP );" "connectorHandler.connect( remoteAddress, localAddress );" Then, the opened DatagramChannel is reused for I/O operations. Note: Actually, connectorHandler.close() doesn't allow the DatagramChannel to be closed because the DatagramChannel 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

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.UDPSelectorHandler
datagramChannel, datagramSocket
 
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
ReusableUDPSelectorHandler()
           
 
Method Summary
 void closeChannel(SelectableChannel channel)
          Closes SelectableChannel
protected  SelectableChannel getSelectableChannel(SocketAddress remoteAddress, SocketAddress localAddress)
           
 
Methods inherited from class com.sun.grizzly.UDPSelectorHandler
copyTo, getConnectorInstanceHandlerDelegate, getLinger, getPortLowLevel, getPreferredSelectionKeyHandler, getSocketNativeReceiveBufferSize, getSocketNativeSendBufferSize, getSocketTimeout, getSsBackLog, isTcpNoDelay, onAcceptInterest, onConnectOp, preSelect, protocol, setLinger, setSocketNativeReceiveBufferSize, setSocketNativeSendBufferSize, setSocketTimeout, setSsBackLog, setTcpNoDelay, shutdown
 
Methods inherited from class com.sun.grizzly.TCPSelectorHandler
acceptWithoutRegistration, acquireConnectorHandler, addPendingIO, addPendingKeyCancel, boolean2Role, configureChannel, connect, getAsyncQueueReader, getAsyncQueueWriter, getAttribute, getAttributes, getInet, getLogger, getPort, getPortRange, getProtocolChainInstanceHandler, getRole, getSelectionKeyHandler, getSelector, getSelectTimeout, getServerTimeout, getSpinRate, getStateHolder, getThreadPool, invokeAsyncQueueReader, invokeAsyncQueueWriter, invokeCallbackHandler, isExecutePendingIOUsingSelectorThread, isKeepAlive, isOpen, isReuseAddress, keyFor, keys, onConnectInterest, onReadInterest, onWriteInterest, pause, pollContext, postSelect, processPendingOperations, register, register, register, releaseConnectorHandler, removeAttribute, resetSpinCounter, resume, select, setAttribute, setAttributes, setExecutePendingIOUsingSelectorThread, setInet, setKeepAlive, setLogger, setMaxAcceptRetries, setPort, setPortRange, setProtocolChainInstanceHandler, setReceiveBufferSize, setReuseAddress, setRole, setSelectionKeyHandler, setSelector, setSelectTimeout, setSendBufferSize, setServerTimeout, setThreadPool, workaroundSelectorSpin
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReusableUDPSelectorHandler

public ReusableUDPSelectorHandler()
Method Detail

getSelectableChannel

protected SelectableChannel getSelectableChannel(SocketAddress remoteAddress,
                                                 SocketAddress localAddress)
                                          throws IOException
Overrides:
getSelectableChannel in class UDPSelectorHandler
Throws:
IOException

closeChannel

public void closeChannel(SelectableChannel channel)
Closes SelectableChannel

Specified by:
closeChannel in interface SelectorHandler
Overrides:
closeChannel in class UDPSelectorHandler


Copyright © 2012 Oracle Corporation. All Rights Reserved.