## com.sun.grizzly
Class UDPSelectorHandler

    java.lang.Object
      com.sun.grizzly.TCPSelectorHandler
          com.sun.grizzly.UDPSelectorHandler

All Implemented Interfaces:
  Handler, SelectorHandler, AttributeHolder, Copyable, SupportStateHolder<State>

    public class UDPSelectorHandler

extends TCPSelectorHandler

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

Author:
  Jeanfrancois Arcand

Field Summary
`protected DatagramChannel` `datagramChannel` The DatagramChannel.
`protected DatagramSocket` `datagramSocket` The datagramSocket instance.

Fields inherited from class com.sun.grizzly.TCPSelectorHandler
`asyncQueueReader, asyncQueueWriter, attributes, connectorInstanceHandler, inet, instanceHandler, isClient, isShutDown, linger, logger, opToRegister, pipeline, port, reuseAddress, selectionKeyHandler, selector, selectTimeout, serverSocket, serverSocketChannel, serverTimeout, socketTimeout, ssBackLog, stateHolder, tcpNoDelay`

Constructor Summary
`UDPSelectorHandler()`
`UDPSelectorHandler(boolean isClient)`

Method Summary
`void` `closeChannel(SelectableChannel channel)` Closes `SelectableChannel`
`void` `copyTo(Copyable copy)` Copies current object content to copy object
`protected Callable<ConnectorHandler>` `getConnectorInstanceHandlerDelegate()` Return <Callable>factory<Callable> object, which knows how to create `ConnectorInstanceHandler` corresponding to the protocol
`int` `getLinger()`
`int` `getPortLowLevel()` Returns port number `SelectorHandler` is listening on Similar to `getPort()`, but getting port number directly from connection (`ServerSocket`, `DatagramSocket`).
`Class<? extends SelectionKeyHandler>` `getPreferredSelectionKeyHandler()` Get the preffered SelectionKeyHandler implementation for this SelectorHandler.
`int` `getSocketTimeout()`
`int` `getSsBackLog()`
`boolean` `isTcpNoDelay()` Return the tcpNoDelay value used by the underlying accepted Sockets.
`boolean` `onAcceptInterest(SelectionKey key, Context ctx)` Handle OP_ACCEPT.
`protected void` `onConnectOp(Context ctx, SelectionKeyOP.ConnectSelectionKeyOP selectionKeyOp)` Handle new OP_CONNECT ops.
`void` `preSelect(Context ctx)` Before invoking Selector.select(), make sure the ServerScoketChannel has been created.
`Controller.Protocol` `protocol()` A token describing the protocol supported by an implementation of this interface
`void` `setLinger(int linger)`
`void` `setSocketTimeout(int socketTimeout)`
`void` `setSsBackLog(int ssBackLog)`
`void` `setTcpNoDelay(boolean tcpNoDelay)` Enable (true) or disable (false) the underlying Socket's tcpNoDelay.
`void` `shutdown()` Shuntdown this instance by closing its Selector and associated channels.

Methods inherited from class com.sun.grizzly.TCPSelectorHandler

`acceptWithoutRegistration, acquireConnectorHandler, configureChannel, connect, getAsyncQueueReader, getAsyncQueueWriter, getAttribute, getAttributes, getInet, getLogger, getPort, getProtocolChainInstanceHandler, getSelectionKeyHandler, getSelector, getSelectTimeout, getServerTimeout, getStateHolder, initOpRegistriesIfRequired, invokeAsyncQueueReader, invokeAsyncQueueWriter, invokeCallbackHandler, isOpen, isReuseAddress, keys, onConnectInterest, onReadInterest, onReadOp, onWriteInterest, onWriteOp, pause, pipeline, pollContext, postSelect, processPendingOperations, register, register, releaseConnectorHandler, removeAttribute, resume, select, setAttribute, setAttributes, setInet, setLogger, setPipeline, setPort, setProtocolChainInstanceHandler, setReuseAddress, setSelectionKeyHandler, setSelector, setSelectTimeout, setServerTimeout`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### datagramSocket

    protected DatagramSocket datagramSocket

  The datagramSocket instance.

### datagramChannel

    protected DatagramChannel datagramChannel

  The DatagramChannel.

Constructor Detail

### UDPSelectorHandler

    public UDPSelectorHandler()

### UDPSelectorHandler

    public UDPSelectorHandler(boolean isClient)

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

### preSelect

    public void preSelect(Context ctx)
                   throws IOException

  Before invoking Selector.select(), make sure the ServerScoketChannel has been created. If true, then register all SelectionKey to the Selector.

  Specified by:
    `preSelect` in interface `SelectorHandler`
  Overrides:
    `preSelect` in class `TCPSelectorHandler`
  Parameters:
    `ctx` - `Context`
  Throws:
    `IOException`

### onConnectOp

    protected void onConnectOp(Context ctx,
                               SelectionKeyOP.ConnectSelectionKeyOP selectionKeyOp)
                        throws IOException

  Handle new OP_CONNECT ops.

  Overrides:
    `onConnectOp` 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`

### onAcceptInterest

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

  Handle OP_ACCEPT. Not used for UPD.

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

### getPreferredSelectionKeyHandler

    public Class<? extends SelectionKeyHandler> getPreferredSelectionKeyHandler()

  Get the preffered SelectionKeyHandler implementation for this SelectorHandler.

  Specified by:
    `getPreferredSelectionKeyHandler` in interface `SelectorHandler`
  Overrides:
    `getPreferredSelectionKeyHandler` in class `TCPSelectorHandler`

### protocol

    public Controller.Protocol protocol()

  A token describing the protocol supported by an implementation of this interface

  Specified by:
    `protocol` in interface `SelectorHandler`
  Overrides:
    `protocol` in class `TCPSelectorHandler`
  Returns:
    SelectorHandler supported protocol

### getPortLowLevel

    public int getPortLowLevel()

  Description copied from class: `TCPSelectorHandler`
  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.

  Overrides:
    `getPortLowLevel` in class `TCPSelectorHandler`
  Returns:
    port number or -1 if `SelectorHandler` was not initialized for accepting connections.

### getSsBackLog

    public int getSsBackLog()

  Overrides:
    `getSsBackLog` in class `TCPSelectorHandler`

### setSsBackLog

    public void setSsBackLog(int ssBackLog)

  Overrides:
    `setSsBackLog` in class `TCPSelectorHandler`

### isTcpNoDelay

    public boolean isTcpNoDelay()

  Description copied from class: `TCPSelectorHandler`
  Return the tcpNoDelay value used by the underlying accepted Sockets. Also see setTcpNoDelay(boolean tcpNoDelay)

  Overrides:
    `isTcpNoDelay` in class `TCPSelectorHandler`

### setTcpNoDelay

    public void setTcpNoDelay(boolean tcpNoDelay)

  Description copied from class: `TCPSelectorHandler`
  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.

  Overrides:
    `setTcpNoDelay` in class `TCPSelectorHandler`

### getLinger

    public int getLinger()

  Overrides:
    `getLinger` in class `TCPSelectorHandler`

### setLinger

    public void setLinger(int linger)

  Overrides:
    `setLinger` in class `TCPSelectorHandler`

### getSocketTimeout

    public int getSocketTimeout()

  Overrides:
    `getSocketTimeout` in class `TCPSelectorHandler`

### setSocketTimeout

    public void setSocketTimeout(int socketTimeout)

  Overrides:
    `setSocketTimeout` in class `TCPSelectorHandler`

### closeChannel

    public void closeChannel(SelectableChannel channel)

  Description copied from class: `TCPSelectorHandler`
  Closes `SelectableChannel`

  Specified by:
    `closeChannel` in interface `SelectorHandler`
  Overrides:
    `closeChannel` in class `TCPSelectorHandler`

### getConnectorInstanceHandlerDelegate

    protected Callable<ConnectorHandler> getConnectorInstanceHandlerDelegate()

  Description copied from class: `TCPSelectorHandler`
  Return <Callable>factory<Callable> object, which knows how to create `ConnectorInstanceHandler` corresponding to the protocol

  Overrides:
    `getConnectorInstanceHandlerDelegate` in class `TCPSelectorHandler`
  Returns:
    <Callable>factory

Copyright © 2008 SUN Microsystems. All Rights Reserved.