java.nio.channels
Class SelectionKey

java.lang.Object
  extended by java.nio.channels.SelectionKey
Direct Known Subclasses:
AbstractSelectionKey

public abstract class SelectionKey
extends Object

Since:
1.4

Field Summary
static int OP_ACCEPT
           
static int OP_CONNECT
           
static int OP_READ
           
static int OP_WRITE
           
 
Constructor Summary
protected SelectionKey()
          Initializes the selection key.
 
Method Summary
 Object attach(Object obj)
          Attaches obj to the key and returns the old attached object.
 Object attachment()
          Returns the object attached to the key.
abstract  void cancel()
          Requests that the registration of this key's channel with its selector be cancelled.
abstract  SelectableChannel channel()
          return the channel attached to the key.
abstract  int interestOps()
          Returns the key's interest set.
abstract  SelectionKey interestOps(int ops)
          Sets this key's interest set to the given value.
 boolean isAcceptable()
          Tests if the channel attached to this key is ready to accept a new socket connection.
 boolean isConnectable()
          Tests whether this key's channel has either finished, or failed to finish, its socket-connection operation.
 boolean isReadable()
          Tests if the channel attached to the key is readable.
abstract  boolean isValid()
          Tells whether or not this key is valid.
 boolean isWritable()
          Tests if the channel attached to the key is writable.
abstract  int readyOps()
          Retrieves this key's ready-operation set.
abstract  Selector selector()
          Returns the selector for which this key was created.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OP_ACCEPT

public static final int OP_ACCEPT
See Also:
Constant Field Values

OP_CONNECT

public static final int OP_CONNECT
See Also:
Constant Field Values

OP_READ

public static final int OP_READ
See Also:
Constant Field Values

OP_WRITE

public static final int OP_WRITE
See Also:
Constant Field Values
Constructor Detail

SelectionKey

protected SelectionKey()
Initializes the selection key.

Method Detail

attach

public final Object attach(Object obj)
Attaches obj to the key and returns the old attached object.


attachment

public final Object attachment()
Returns the object attached to the key.


isAcceptable

public final boolean isAcceptable()
Tests if the channel attached to this key is ready to accept a new socket connection.

Throws:
CancelledKeyException - If this key has been cancelled

isConnectable

public final boolean isConnectable()
Tests whether this key's channel has either finished, or failed to finish, its socket-connection operation.

Throws:
CancelledKeyException - If this key has been cancelled

isReadable

public final boolean isReadable()
Tests if the channel attached to the key is readable.

Throws:
CancelledKeyException - If this key has been cancelled

isWritable

public final boolean isWritable()
Tests if the channel attached to the key is writable.

Throws:
CancelledKeyException - If this key has been cancelled

cancel

public abstract void cancel()
Requests that the registration of this key's channel with its selector be cancelled.


channel

public abstract SelectableChannel channel()
return the channel attached to the key.


interestOps

public abstract int interestOps()
Returns the key's interest set.

Throws:
CancelledKeyException - If this key has been cancelled

interestOps

public abstract SelectionKey interestOps(int ops)
Sets this key's interest set to the given value.

Throws:
CancelledKeyException - If this key has been cancelled
IllegalArgumentException - If a bit in the set does not correspond to an operation that is supported by this key's channel, that is, if set & ~(channel().validOps()) != 0

isValid

public abstract boolean isValid()
Tells whether or not this key is valid.


readyOps

public abstract int readyOps()
Retrieves this key's ready-operation set.

Throws:
CancelledKeyException - If this key has been cancelled

selector

public abstract Selector selector()
Returns the selector for which this key was created.