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)
          Cancel a SelectionKey and close its associated Channel.
protected  void cancelKey(SelectionKey key)
           
protected  Object clearKeyAttachment(SelectionKey key)
           
 void close(SelectionKey key)
          Close the SelectionKey's channel input or output, but keep alive the SelectionKey.
protected  void closeChannel(SelectableChannel channel)
           
protected  void closeChannel(SelectionKey key)
           
 void copyTo(Copyable copy)
          Copies current object content to copy object
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
protected  boolean keyIsValid(SelectionKey key)
           
 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 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 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
Parameters:
keyIterator - Iterator of SelectionKeys to expire

cancel

public void cancel(SelectionKey key)
Cancel a SelectionKey and close its associated Channel.

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

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

copyTo

public void copyTo(Copyable copy)
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)

cancelKey

protected void cancelKey(SelectionKey key)

keyIsValid

protected boolean keyIsValid(SelectionKey key)

closeChannel

protected void closeChannel(SelectionKey key)

clearKeyAttachment

protected Object clearKeyAttachment(SelectionKey key)

closeChannel

protected void closeChannel(SelectableChannel channel)


Copyright © 2009 SUN Microsystems. All Rights Reserved.