source: trunk/gcc/libjava/java/nio/channels/SelectionKey.java

Last change on this file was 1389, checked in by bird, 21 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 4.6 KB
Line 
1/* SelectionKey.java --
2 Copyright (C) 2002 Free Software Foundation, Inc.
3
4This file is part of GNU Classpath.
5
6GNU Classpath is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11GNU Classpath is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Classpath; see the file COPYING. If not, write to the
18Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
1902111-1307 USA.
20
21Linking this library statically or dynamically with other modules is
22making a combined work based on this library. Thus, the terms and
23conditions of the GNU General Public License cover the whole
24combination.
25
26As a special exception, the copyright holders of this library give you
27permission to link this library with independent modules to produce an
28executable, regardless of the license terms of these independent
29modules, and to copy and distribute the resulting executable under
30terms of your choice, provided that you also meet, for each linked
31independent module, the terms and conditions of the license of that
32module. An independent module is a module which is not derived from
33or based on this library. If you modify this library, you may extend
34this exception to your version of the library, but you are not
35obligated to do so. If you do not wish to do so, delete this
36exception statement from your version. */
37
38package java.nio.channels;
39
40/**
41 * @author Michael Koch
42 * @since 1.4
43 */
44public abstract class SelectionKey
45{
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;
50
51 Object attached;
52
53 /**
54 * Initializes the selection key.
55 */
56 protected SelectionKey ()
57 {
58 }
59
60 /**
61 * Attaches obj to the key and returns the old attached object.
62 */
63 public final Object attach (Object obj)
64 {
65 Object old = attached;
66 attached = obj;
67 return old;
68 }
69
70 /**
71 * Returns the object attached to the key.
72 */
73 public final Object attachment ()
74 {
75 return attached;
76 }
77
78 /**
79 * Tests if the channel attached to this key is ready to accept
80 * a new socket connection.
81 *
82 * @exception CancelledKeyException If this key has been cancelled
83 */
84 public final boolean isAcceptable ()
85 {
86 return (readyOps () & OP_ACCEPT) != 0;
87 }
88
89 /**
90 * Tests whether this key's channel has either finished,
91 * or failed to finish, its socket-connection operation.
92 *
93 * @exception CancelledKeyException If this key has been cancelled
94 */
95 public final boolean isConnectable ()
96 {
97 return (readyOps () & OP_CONNECT) != 0;
98 }
99
100 /**
101 * Tests if the channel attached to the key is readable.
102 *
103 * @exception CancelledKeyException If this key has been cancelled
104 */
105 public final boolean isReadable ()
106 {
107 return (readyOps () & OP_READ) != 0;
108 }
109
110 /**
111 * Tests if the channel attached to the key is writable.
112 *
113 * @exception CancelledKeyException If this key has been cancelled
114 */
115 public final boolean isWritable ()
116 {
117 return (readyOps () & OP_WRITE) != 0;
118 }
119
120 /**
121 * Requests that the registration of this key's channel with
122 * its selector be cancelled.
123 */
124 public abstract void cancel ();
125
126 /**
127 * return the channel attached to the key.
128 */
129 public abstract SelectableChannel channel ();
130
131 /**
132 * Returns the key's interest set.
133 *
134 * @exception CancelledKeyException If this key has been cancelled
135 */
136 public abstract int interestOps ();
137
138 /**
139 * Sets this key's interest set to the given value.
140 *
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
145 */
146 public abstract SelectionKey interestOps (int ops);
147
148 /**
149 * Tells whether or not this key is valid.
150 */
151 public abstract boolean isValid ();
152
153 /**
154 * Retrieves this key's ready-operation set.
155 *
156 * @exception CancelledKeyException If this key has been cancelled
157 */
158 public abstract int readyOps ();
159
160 /**
161 * Returns the selector for which this key was created.
162 */
163 public abstract Selector selector ();
164}
Note: See TracBrowser for help on using the repository browser.