FSF GCC merge 02/23/03
[official-gcc.git] / libjava / java / nio / channels / SelectionKey.java
blob39b66f1902ad2b485160664e50a0c5c1249a0ddb
1 /* SelectionKey.java --
2 Copyright (C) 2002 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
38 package java.nio.channels;
40 /**
41 * @author Michael Koch
42 * @since 1.4
44 public abstract class SelectionKey
46 public static final int OP_ACCEPT = 16;
47 public static final int OP_CONNECT = 8;
48 public static final int OP_READ = 1;
49 public static final int OP_WRITE = 4;
51 Object attached;
53 /**
54 * Initializes the selection key.
56 protected SelectionKey ()
60 /**
61 * Attaches obj to the key and returns the old attached object.
63 public final Object attach (Object obj)
65 Object old = attached;
66 attached = obj;
67 return old;
70 /**
71 * Returns the object attached to the key.
73 public final Object attachment ()
75 return attached;
78 /**
79 * Tests if the channel attached to this key is ready to accept
80 * a new socket connection.
82 * @exception CancelledKeyException If this key has been cancelled
84 public final boolean isAcceptable ()
86 return (readyOps () & OP_ACCEPT) != 0;
89 /**
90 * Tests whether this key's channel has either finished,
91 * or failed to finish, its socket-connection operation.
93 * @exception CancelledKeyException If this key has been cancelled
95 public final boolean isConnectable ()
97 return (readyOps () & OP_CONNECT) != 0;
101 * Tests if the channel attached to the key is readable.
103 * @exception CancelledKeyException If this key has been cancelled
105 public final boolean isReadable ()
107 return (readyOps () & OP_READ) != 0;
111 * Tests if the channel attached to the key is writable.
113 * @exception CancelledKeyException If this key has been cancelled
115 public final boolean isWritable ()
117 return (readyOps () & OP_WRITE) != 0;
121 * Requests that the registration of this key's channel with
122 * its selector be cancelled.
124 public abstract void cancel ();
127 * return the channel attached to the key.
129 public abstract SelectableChannel channel ();
132 * Returns the key's interest set.
134 * @exception CancelledKeyException If this key has been cancelled
136 public abstract int interestOps ();
139 * Sets this key's interest set to the given value.
141 * @exception CancelledKeyException If this key has been cancelled
142 * @exception IllegalArgumentException If a bit in the set does not
143 * correspond to an operation that is supported by this key's channel,
144 * that is, if set & ~(channel().validOps()) != 0
146 public abstract SelectionKey interestOps (int ops);
149 * Tells whether or not this key is valid.
151 public abstract boolean isValid ();
154 * Retrieves this key's ready-operation set.
156 * @exception CancelledKeyException If this key has been cancelled
158 public abstract int readyOps ();
161 * Returns the selector for which this key was created.
163 public abstract Selector selector ();