com.sun.grizzly.util
Class SelectionKeyAttachment

java.lang.Object
  extended by com.sun.grizzly.util.SelectionKeyAttachment
Direct Known Subclasses:
SelectedKeyAttachmentLogic, SelectionKeyActionAttachment

public abstract class SelectionKeyAttachment
extends Object

Basic class for all SelectionKey attachments. Custom attachments should be inherited from it.

Author:
Alexey Stashok

Nested Class Summary
static interface SelectionKeyAttachment.KeySelectionListener
           
static interface SelectionKeyAttachment.TimeOutListener
           
 
Field Summary
static long DEREGISTERED
           
protected  long idleTimeoutDelay
           
protected  SelectionKeyAttachment.KeySelectionListener keySelectionListener
           
protected  long timeout
           
protected  SelectionKeyAttachment.TimeOutListener timeoutListener
           
static long UNLIMITED_TIMEOUT
           
 
Constructor Summary
SelectionKeyAttachment()
           
 
Method Summary
static Object getAttachment(SelectionKey key)
           
 long getIdleTimeoutDelay()
          Returns the idle timeout delay.
 SelectionKeyAttachment.KeySelectionListener getKeySelectionListener()
           
 long getTimeout()
          Get the channel expiration stamp in millis (last time an opeation on the channel was invoked).
 SelectionKeyAttachment.TimeOutListener getTimeoutListener()
           
 boolean handleSelectedKey(SelectionKey selectionKey)
          Used for completely custom selector.select logic.
 void release(SelectionKey selectionKey)
           
 void setIdleTimeoutDelay(long idleTimeoutDelay)
          Set the idle timeout delay.
 void setKeySelectionListener(SelectionKeyAttachment.KeySelectionListener keySelectionListener)
           
 void setTimeout(long timeout)
          Set the channel expiration stamp in millis (last time an opeation on the channel was invoked).
 void setTimeoutListener(SelectionKeyAttachment.TimeOutListener timeoutListener)
           
 boolean timedOut(SelectionKey Key)
          called when idle timeout detected.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UNLIMITED_TIMEOUT

public static final long UNLIMITED_TIMEOUT
See Also:
Constant Field Values

DEREGISTERED

public static final long DEREGISTERED
See Also:
Constant Field Values

timeout

protected volatile long timeout

idleTimeoutDelay

protected volatile long idleTimeoutDelay

timeoutListener

protected volatile SelectionKeyAttachment.TimeOutListener timeoutListener

keySelectionListener

protected volatile SelectionKeyAttachment.KeySelectionListener keySelectionListener
Constructor Detail

SelectionKeyAttachment

public SelectionKeyAttachment()
Method Detail

getAttachment

public static Object getAttachment(SelectionKey key)

getIdleTimeoutDelay

public long getIdleTimeoutDelay()
Returns the idle timeout delay. Default it returns UNLIMITED_TIMEOUT, meaning no idle timeout delay.

Returns:

setIdleTimeoutDelay

public void setIdleTimeoutDelay(long idleTimeoutDelay)
Set the idle timeout delay. Default it returns UNLIMITED_TIMEOUT, meaning no idle timeout delay.

Parameters:
idleTimeoutDelay -

getTimeout

public long getTimeout()
Get the channel expiration stamp in millis (last time an opeation on the channel was invoked).

Returns:
the channel expiration stamp in millis.

setTimeout

public void setTimeout(long timeout)
Set the channel expiration stamp in millis (last time an opeation on the channel was invoked).

Parameters:
timeout - the channel expiration stamp in millis.

getTimeoutListener

public SelectionKeyAttachment.TimeOutListener getTimeoutListener()

setTimeoutListener

public void setTimeoutListener(SelectionKeyAttachment.TimeOutListener timeoutListener)

getKeySelectionListener

public SelectionKeyAttachment.KeySelectionListener getKeySelectionListener()

setKeySelectionListener

public void setKeySelectionListener(SelectionKeyAttachment.KeySelectionListener keySelectionListener)

timedOut

public boolean timedOut(SelectionKey Key)
called when idle timeout detected. return true if key should be canceled.

Parameters:
Key -
Returns:

handleSelectedKey

public boolean handleSelectedKey(SelectionKey selectionKey)
Used for completely custom selector.select logic.

Parameters:
selectionKey -
Returns:
true, if we want to continue the default interest processing, or false otherwise.

release

public void release(SelectionKey selectionKey)


Copyright © 2012 Oracle Corporation. All Rights Reserved.