com.sun.grizzly
Class BaseSelectionKeyHandler

java.lang.Object
  extended by com.sun.grizzly.BaseSelectionKeyHandler
All Implemented Interfaces:
Handler, SelectionKeyHandler, ConnectionCloseHandlerNotifier, Copyable
Direct Known Subclasses:
DefaultSelectionKeyHandler

public class BaseSelectionKeyHandler
extends Object
implements SelectionKeyHandler, ConnectionCloseHandlerNotifier

This class is an implementation of a SelectionKeyHandler which does not use the SelectionKey attachment, does not expire keys or utilize a keep-alive mechanism. However, this is currently not the SelectionKeyHandler provisioned by default with Grizzly's Controller. Hence for an application to use this SelectionKeyHandler, Grizzly's Controller must be explicitly configured to use this SelectionKeyHandler implementation.

Author:
Charlie Hunt

Field Summary
protected  Logger logger
           
protected  SelectorHandler selectorHandler
          Associated SelectorHandler
 
Constructor Summary
BaseSelectionKeyHandler()
           
BaseSelectionKeyHandler(SelectorHandler selectorHandler)
           
 
Method Summary
 void cancel(SelectionKey key)
          if SelectionKey is valid, its canceled .
 void close(SelectionKey key)
          Close the SelectionKey's channel input or output, but keep alive the SelectionKey.
 void copyTo(Copyable copy)
          Copies current object content to copy object
protected  void doAfterKeyCancel(SelectionKey key)
          Performed when a key is canceled.
closes the channel and notifies ConnectionCloseHandler , if SelectionKey.attachment() instanceof SelectionKeyAttachment then its release method is called.
protected  void doRegisterKey(SelectionKey key, int selectionKeyOps)
          Registers SelectionKey to handle certain operations
 void expire(Iterator<SelectionKey> keyIterator)
          Expire a SelectionKey set.
 void expire(SelectionKey key, long currentTime)
          Deprecated.  
 Logger getLogger()
           
 SelectorHandler getSelectorHandler()
          Get associated SelectorHandler
 void notifyLocallyClose(SelectionKey key)
          Notify a ConnectionCloseHandler that a remote connection has been closed.
 void notifyRemotlyClose(SelectionKey key)
          Notify a ConnectionCloseHandler that a remote connection has been closed.
 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 SelectionKeys.
 void register(SelectableChannel channel, int selectionKeyOps)
          Register a SelectableChannel on Selector.
 void register(SelectableChannel channel, int selectionKeyOps, Object attachment)
          Register a SelectableChannel on Selector.
 void register(SelectionKey key, int selectionKeyOps)
          Register a SelectionKey on Selector.
 void register(SelectionKey key, long currentTime)
          Deprecated.  
 void removeConnectionCloseHandler(ConnectionCloseHandler cch)
          Removes the the ConnectionCloseHandler from a set.
 void setConnectionCloseHandler(ConnectionCloseHandler cch)
          Adds the the ConnectionCloseHandler to a set.
 void setLogger(Logger logger)
           
 void setSelectorHandler(SelectorHandler selectorHandler)
          Set associated SelectorHandler
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected Logger logger

selectorHandler

protected SelectorHandler selectorHandler
Associated SelectorHandler

Constructor Detail

BaseSelectionKeyHandler

public BaseSelectionKeyHandler()

BaseSelectionKeyHandler

public BaseSelectionKeyHandler(SelectorHandler selectorHandler)
Method Detail

getSelectorHandler

public SelectorHandler getSelectorHandler()
Description copied from interface: SelectionKeyHandler
Get associated SelectorHandler

Specified by:
getSelectorHandler in interface SelectionKeyHandler

setSelectorHandler

public void setSelectorHandler(SelectorHandler selectorHandler)
Description copied from interface: SelectionKeyHandler
Set associated SelectorHandler

Specified by:
setSelectorHandler in interface SelectionKeyHandler

process

public void process(SelectionKey key)
Description copied from interface: SelectionKeyHandler
SelectionKey process notification

Specified by:
process in interface SelectionKeyHandler
Parameters:
key - SelectionKey to process

postProcess

public void postProcess(SelectionKey key)
Description copied from interface: SelectionKeyHandler
SelectionKey post process notification

Specified by:
postProcess in interface SelectionKeyHandler
Parameters:
key - SelectionKey to process

register

public void register(SelectionKey key,
                     long currentTime)
Deprecated. 

Description copied from interface: SelectionKeyHandler
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
Parameters:
key - SelectionKey to register
currentTime - the System.currentTimeMillis

register

public void register(SelectionKey key,
                     int selectionKeyOps)
Description copied from interface: SelectionKeyHandler
Register a SelectionKey on Selector.

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

doRegisterKey

protected void doRegisterKey(SelectionKey key,
                             int selectionKeyOps)
Registers SelectionKey to handle certain operations


register

public void register(SelectableChannel channel,
                     int selectionKeyOps)
              throws ClosedChannelException
Description copied from interface: SelectionKeyHandler
Register a SelectableChannel on Selector.

Specified by:
register in interface SelectionKeyHandler
Parameters:
channel - SelectableChannel
selectionKeyOps - The interest set to apply when registering. to register
Throws:
ClosedChannelException

register

public void register(SelectableChannel channel,
                     int selectionKeyOps,
                     Object attachment)
              throws ClosedChannelException
Description copied from interface: SelectionKeyHandler
Register a SelectableChannel on Selector.

Specified by:
register in interface SelectionKeyHandler
Parameters:
channel - SelectableChannel
selectionKeyOps - The interest set to apply when registering. to register
attachment - attachment
Throws:
ClosedChannelException

register

public void register(Iterator<SelectionKey> keyIterator,
                     int selectionKeyOps)
Description copied from interface: SelectionKeyHandler
Register a set of SelectionKeys. Note: After processing each SelectionKey it should be removed from Iterator

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

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
Parameters:
key - SelectionKey to expire
currentTime - the System.currentTimeMillis

expire

public void expire(Iterator<SelectionKey> keyIterator)
Description copied from interface: SelectionKeyHandler
Expire a SelectionKey set. Method checks each SelectionKey from theSet. 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
Parameters:
keyIterator - Iterator of SelectionKeys to expire

cancel

public void cancel(SelectionKey key)
if SelectionKey is valid, its canceled . doAfterKeyCancel(SelectionKey) is called even if key is invalid.

Specified by:
cancel in interface SelectionKeyHandler
Parameters:
key - SelectionKey to cancel

doAfterKeyCancel

protected void doAfterKeyCancel(SelectionKey key)
Performed when a key is canceled.
closes the channel and notifies ConnectionCloseHandler , if SelectionKey.attachment() instanceof SelectionKeyAttachment then its release method is called.


notifyRemotlyClose

public void notifyRemotlyClose(SelectionKey key)
Notify a ConnectionCloseHandler that a remote connection has been closed.

Specified by:
notifyRemotlyClose in interface ConnectionCloseHandlerNotifier
Parameters:
key - a SelectionKey

notifyLocallyClose

public void notifyLocallyClose(SelectionKey key)
Notify a ConnectionCloseHandler that a remote connection has been closed.

Specified by:
notifyLocallyClose in interface ConnectionCloseHandlerNotifier
Parameters:
key - a SelectionKey

close

public void close(SelectionKey key)
Description copied from interface: SelectionKeyHandler
Close the SelectionKey's channel input or output, but keep alive the SelectionKey.

Specified by:
close in interface SelectionKeyHandler
Parameters:
key - SelectionKey to close

setConnectionCloseHandler

public void setConnectionCloseHandler(ConnectionCloseHandler cch)
Adds the the ConnectionCloseHandler to a set.

Parameters:
cch - ConnectionCloseHandler

removeConnectionCloseHandler

public void removeConnectionCloseHandler(ConnectionCloseHandler cch)
Removes the the ConnectionCloseHandler from a set.

Parameters:
cch - ConnectionCloseHandler

copyTo

public void copyTo(Copyable copy)
Description copied from interface: Copyable
Copies current object content to copy object

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

getLogger

public Logger getLogger()

setLogger

public void setLogger(Logger logger)


Copyright © 2013 Oracle Corporation. All Rights Reserved.