Save This Page
Home » apache-harmony-6.0-src-r917296-snapshot » java » nio » channels » [javadoc | source]
java.nio.channels
abstract public class: SelectionKey [javadoc | source]
java.lang.Object
   java.nio.channels.SelectionKey

Direct Known Subclasses:
    AbstractSelectionKey

A {@code SelectionKey} represents the relationship between a channel and a selector for which the channel is registered.

Operation set

An operation set is represented by an integer value. The bits of an operation set represent categories of operations for a key's channel: Accepting socket connections ({@code OP_ACCEPT}), connecting with a socket ({@code OP_CONNECT}), reading ({@code OP_READ}) and writing ({@code OP_WRITE}).

Interest set

The interest set is an operation set that defines the operations that a channel is interested in performing.

Ready set

The ready set is an operation set that shows the operations that a {@code channel} is ready to execute.
Field Summary
public static final  int OP_ACCEPT    Interest set mask bit for socket-accept operations. 
public static final  int OP_CONNECT    Interest set mask bit for socket-connect operations. 
public static final  int OP_READ    Interesting operation mask bit for read operations. 
public static final  int OP_WRITE    Interest set mask bit for write operations. 
Constructor:
 protected SelectionKey() 
Method from java.nio.channels.SelectionKey Summary:
attach,   attachment,   cancel,   channel,   interestOps,   interestOps,   isAcceptable,   isConnectable,   isReadable,   isValid,   isWritable,   readyOps,   selector
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from java.nio.channels.SelectionKey Detail:
 public final Object attach(Object anObject) 
    Attaches an object to this key. It is acceptable to attach {@code null}, this discards the old attachment.
 public final Object attachment() 
    Gets the attached object.
 abstract public  void cancel()
    Cancels this key.

    A key that has been canceled is no longer valid. Calling this method on an already canceled key does nothing.

    Calling this method is safe at any time. The call might block until another ongoing call to a method of this selector has finished. The reason is that it is synchronizing on the key set of the selector. After this call finishes, the key will have been added to the selectors canceled-keys set and will not be included in any future selects of this selector.

 abstract public SelectableChannel channel()
    Gets the channel of this key.
 abstract public int interestOps()
    Gets this key's interest set . The returned set has only those bits set that are valid for this key's channel.
 abstract public SelectionKey interestOps(int operations)
 public final boolean isAcceptable() 
    Indicates whether this key's channel is interested in the accept operation and is ready to accept new connections. A call to this method is equal to executing {@code (readyOps() & OP_ACCEPT) == OP_ACCEPT}.
 public final boolean isConnectable() 
    Indicates whether this key's channel is interested in the connect operation and is ready to connect. A call to this method is equal to executing {@code (readyOps() & OP_CONNECT) == OP_CONNECT}.
 public final boolean isReadable() 
    Indicates whether this key's channel is interested in the read operation and is ready to read. A call to this method is equal to executing {@code (readyOps() & OP_READ) == OP_READ}.
 abstract public boolean isValid()
    Indicates whether this key is valid. A key is valid as long as it has not been canceled.
 public final boolean isWritable() 
    Indicates whether this key's channel is interested in the write operation and is ready to write. A call to this method is equal to executing {@code (readyOps() & OP_WRITE) == OP_WRITE}.
 abstract public int readyOps()
    Gets the set of operations that are ready. The returned set has only those bits set that are valid for this key's channel.
 abstract public Selector selector()
    Gets the selector for which this key's channel is registered.