comparison src/pathfinder/mergetest/channels2/SelectionKeySimulator.java @ 172:a913949a0dd9

channelsimulations version2
author kent
date Sat, 30 Aug 2008 01:55:16 +0900
parents
children
comparison
equal deleted inserted replaced
171:c61a52e12161 172:a913949a0dd9
1 package pathfinder.mergetest.channels2;
2
3 public class SelectionKeySimulator {
4
5 public static final int OP_READ = 0x01;
6 public static final int OP_ACCEPT = 0x02;
7 public static final int OP_WRITE = 0x04;
8
9 private int interestOpt;
10 private SelectableChannelSimulator channel;
11 private Object attachment;
12
13 public SelectionKeySimulator(SelectableChannelSimulator cs, int opt) {
14 channel = cs;
15 interestOpt = opt;
16 }
17
18 public boolean isAble() {
19 if ( (interestOpt&OP_READ)!=0 && isReadable() )
20 return true;
21 else if( (interestOpt&OP_ACCEPT)!=0 && isAcceptable() )
22 return true;
23 else if( (interestOpt&OP_WRITE)!=0 && isWritable() )
24 return true;
25 else
26 return false;
27 }
28
29 public boolean isAcceptable() {
30 return channel.isAcceptable();
31 }
32
33 public boolean isReadable() {
34 return channel.isReadable();
35 }
36 public boolean isWritable() {
37 return channel.isWritable();
38 }
39
40 public SelectableChannelSimulator channel() {
41 return channel;
42 }
43
44 public Object attachment() {
45 return attachment;
46 }
47
48 public void attach(Object handler) {
49 attachment = handler;
50 }
51
52
53 }