com.sun.grizzly
Class BaseSelectionKeyHandler

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

public class BaseSelectionKeyHandler
extends Object
implements SelectionKeyHandler

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)
          
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.  
 ConnectionCloseHandler getConnectionCloseHandler()
          Return the ConnectionClosedHandler.
 Logger getLogger()
           
 SelectorHandler getSelectorHandler()
          Get associated SelectorHandler
 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(SelectionKey key, int selectionKeyOps)
          Register a SelectionKey on Selector.
 void register(SelectionKey key, long currentTime)
          Deprecated.  
 void setConnectionCloseHandler(ConnectionCloseHandler cch)
          Set the the ConnectionClosedHandler
 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()
Get associated SelectorHandler

Specified by:
getSelectorHandler in interface SelectionKeyHandler

setSelectorHandler

public void setSelectorHandler(SelectorHandler selectorHandler)
Set associated SelectorHandler

Specified by:
setSelectorHandler in interface SelectionKeyHandler

process

public void process(SelectionKey key)
SelectionKey process notification

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

postProcess

public void postProcess(SelectionKey key)
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)
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
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(Iterator<SelectionKey> keyIterator,
                     int selectionKeyOps)
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)
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 key) 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.

Parameters:
key - a Selectionkey

close

public void close(SelectionKey key)
Close the SelectionKey's channel input or output, but keep alive the SelectionKey.

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

getConnectionCloseHandler

public ConnectionCloseHandler getConnectionCloseHandler()
Return the ConnectionClosedHandler.

Returns:
the ConnectionClosedHandler

setConnectionCloseHandler

public void setConnectionCloseHandler(ConnectionCloseHandler cch)
Set the the ConnectionClosedHandler

Parameters:
cch - ConnectionClosedHandler

copyTo

public void copyTo(Copyable copy)

Specified by:
copyTo in interface Copyable

getLogger

public Logger getLogger()

setLogger

public void setLogger(Logger logger)


Copyright © 2009 SUN Microsystems. All Rights Reserved.