1 7 8 package java.nio.channels; 9 10 import java.io.IOException ; 11 12 13 91 92 public abstract class SelectionKey { 93 94 97 protected SelectionKey() { } 98 99 100 102 108 public abstract SelectableChannel channel(); 109 110 116 public abstract Selector selector(); 117 118 126 public abstract boolean isValid(); 127 128 142 public abstract void cancel(); 143 144 145 147 161 public abstract int interestOps(); 162 163 181 public abstract SelectionKey interestOps(int ops); 182 183 194 public abstract int readyOps(); 195 196 197 199 210 public static final int OP_READ = 1 << 0; 211 212 223 public static final int OP_WRITE = 1 << 2; 224 225 236 public static final int OP_CONNECT = 1 << 3; 237 238 249 public static final int OP_ACCEPT = 1 << 4; 250 251 270 public final boolean isReadable() { 271 return (readyOps() & OP_READ) != 0; 272 } 273 274 293 public final boolean isWritable() { 294 return (readyOps() & OP_WRITE) != 0; 295 } 296 297 317 public final boolean isConnectable() { 318 return (readyOps() & OP_CONNECT) != 0; 319 } 320 321 341 public final boolean isAcceptable() { 342 return (readyOps() & OP_ACCEPT) != 0; 343 } 344 345 346 348 private volatile Object attachment = null; 349 350 364 public final Object attach(Object ob) { 365 Object a = attachment; 366 attachment = ob; 367 return a; 368 } 369 370 376 public final Object attachment() { 377 return attachment; 378 } 379 380 } 381 | Popular Tags |