## com.sun.grizzly
Class DefaultSelectionKeyHandler

    java.lang.Object
      com.sun.grizzly.BaseSelectionKeyHandler
          com.sun.grizzly.DefaultSelectionKeyHandler

All Implemented Interfaces:
  Handler, SelectionKeyHandler, Copyable

Direct Known Subclasses:
  CacheableSelectionKeyHandler

    public class DefaultSelectionKeyHandler

extends BaseSelectionKeyHandler

Default implementation of a SelectionKey Handler. By default, this class will attach a Long to a SelectionKey in order to calculate the time a SelectionKey can stay active. By default, a SelectionKey will be active for 30 seconds. If during that 30 seconds the client isn't pushing bytes (or closing the connection). the SelectionKey will be expired and its channel closed.

Author:
  Jeanfrancois Arcand

Field Summary
`protected long` `nextKeysExpiration` Next time the exprireKeys() will delete keys.
`protected long` `timeout`

Fields inherited from class com.sun.grizzly.BaseSelectionKeyHandler
`logger, selectorHandler`

Constructor Summary
`DefaultSelectionKeyHandler()`
`DefaultSelectionKeyHandler(SelectorHandler selectorHandler)`

Method Summary
`protected Object` `clearKeyAttachment(SelectionKey key)`
`void` `copyTo(Copyable copy)` Copies current object content to copy object
`protected void` `doRegisterKey(SelectionKey key, int selectionKeyOps, long currentTime)` Registers `SelectionKey` to handle certain operations
`void` `expire(Iterator<SelectionKey> iterator)` Expire a `SelectionKey` set.
`void` `expire(SelectionKey key, long currentTime)` Deprecated.
`long` `getTimeout()`
`void` `postProcess(SelectionKey key)` `SelectionKey` post process notification
`void` `process(SelectionKey key)` `SelectionKey` process notification
`void` `register(Iterator<SelectionKey> keyIterator, int selectionKeyOps)` Register a set of `SelectionKey`s.
`void` `register(SelectableChannel channel, int ops)` Register a `SelectableChannel` on `Selector`.
`void` `register(SelectionKey key, int selectionKeyOps)` Register a `SelectionKey` on `Selector`.
`void` `register(SelectionKey key, long currentTime)` Attach a times out to the SelectionKey used to cancel idle connection.
`void` `setTimeout(long timeout)`

Methods inherited from class com.sun.grizzly.BaseSelectionKeyHandler
`cancel, cancelKey, close, closeChannel, closeChannel, doRegisterKey, getLogger, getSelectorHandler, keyIsValid, setLogger, setSelectorHandler`

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

Field Detail

### nextKeysExpiration

    protected long nextKeysExpiration

  Next time the exprireKeys() will delete keys.

### timeout

    protected long timeout

Constructor Detail

### DefaultSelectionKeyHandler

    public DefaultSelectionKeyHandler()

### DefaultSelectionKeyHandler

    public DefaultSelectionKeyHandler(SelectorHandler selectorHandler)

Method Detail

### copyTo

    public void copyTo(Copyable copy)

  Copies current object content to copy object

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

### process

    public void process(SelectionKey key)

  `SelectionKey` process notification

  Specified by:
    `process` in interface `SelectionKeyHandler`
  Overrides:
    `process` in class `BaseSelectionKeyHandler`
  Parameters:
    `key` - `SelectionKey` to process

### postProcess

    public void postProcess(SelectionKey key)

  `SelectionKey` post process notification

  Specified by:
    `postProcess` in interface `SelectionKeyHandler`
  Overrides:
    `postProcess` in class `BaseSelectionKeyHandler`
  Parameters:
    `key` - `SelectionKey` to process

### register

    public void register(Iterator<SelectionKey> keyIterator,
                         int selectionKeyOps)

  Register a set of `SelectionKey`s. Note: After processing each `SelectionKey` it should be removed from `Iterator`

  Specified by:
    `register` in interface `SelectionKeyHandler`
  Overrides:
    `register` in class `BaseSelectionKeyHandler`
    `selectionKeyOps` - The interest set to apply when registering. to register

### register

    public void register(SelectionKey key,
                         int selectionKeyOps)

  Register a `SelectionKey` on `Selector`.

  Specified by:
    `register` in interface `SelectionKeyHandler`
  Overrides:
    `register` in class `BaseSelectionKeyHandler`
  Parameters:
    `key` - `SelectionKey`
    `selectionKeyOps` - The interest set to apply when registering. to register

### doRegisterKey

    protected void doRegisterKey(SelectionKey key,
                                 int selectionKeyOps,
                                 long currentTime)

  Registers `SelectionKey` to handle certain operations

### register

    public void register(SelectableChannel channel,
                         int ops)
                  throws ClosedChannelException

  Register a `SelectableChannel` on `Selector`.

  Specified by:
    `register` in interface `SelectionKeyHandler`
  Overrides:
    `register` in class `BaseSelectionKeyHandler`
  Parameters:
    `channel` - `SelectableChannel`
    `ops` - The interest set to apply when registering. to register
  Throws:
    `ClosedChannelException`

### register

    public void register(SelectionKey key,
                         long currentTime)

  Attach a times out to the SelectionKey used to cancel idle connection. Null when the feature is not required.

  Specified by:
    `register` in interface `SelectionKeyHandler`
  Overrides:
    `register` in class `BaseSelectionKeyHandler`
  Parameters:
    `key` - `SelectionKey` to register
    `currentTime` - the System.currentTimeMillis

### expire

    public void expire(SelectionKey key,
                       long currentTime)

  Deprecated.

  Description copied from interface: `SelectionKeyHandler`
  Expire a `SelectionKey`. If a `SelectionKey` is inactive for certain time (timeout), the `SelectionKey` will be cancelled and its associated Channel closed.

  Specified by:
    `expire` in interface `SelectionKeyHandler`
  Overrides:
    `expire` in class `BaseSelectionKeyHandler`
  Parameters:
    `key` - `SelectionKey` to expire
    `currentTime` - the System.currentTimeMillis

### expire

    public void expire(Iterator<SelectionKey> iterator)

  Expire a `SelectionKey` set. Method checks each `SelectionKey` from the`Set`. And if a `SelectionKey` is inactive for certain time (timeout), the `SelectionKey` will be cancelled and its associated Channel closed.

  Specified by:
    `expire` in interface `SelectionKeyHandler`
  Overrides:
    `expire` in class `BaseSelectionKeyHandler`
  Parameters:
    `iterator` - `Iterator` of `SelectionKey`s to expire

### getTimeout

    public long getTimeout()

### setTimeout

    public void setTimeout(long timeout)

### clearKeyAttachment

    protected Object clearKeyAttachment(SelectionKey key)

  Overrides:
    `clearKeyAttachment` in class `BaseSelectionKeyHandler`

Copyright © 2008 SUN Microsystems. All Rights Reserved.