Mercurial > hg > RemoteEditor > REPSessionManager
comparison rep/channel/SelectionKeySimulator.java @ 123:5b1a0574b406 add-simulator
*** empty log message ***
author | pin |
---|---|
date | Wed, 27 Aug 2008 17:21:25 +0900 |
parents | |
children | 9faacdd6c9cb |
comparison
equal
deleted
inserted
replaced
122:790c8dd42a7b | 123:5b1a0574b406 |
---|---|
1 package rep.channel; | |
2 | |
3 import java.nio.channels.SelectionKey; | |
4 import java.nio.channels.Selector; | |
5 | |
6 public class SelectionKeySimulator<P> extends SelectionKey{ | |
7 | |
8 private int interestOpt; | |
9 private SelectableChannelSimulator<P> channel; | |
10 private int ready; | |
11 public Selector selector; | |
12 | |
13 public SelectionKeySimulator(SelectableChannelSimulator<P> cs, int opt, Selector _selector) { | |
14 channel = cs; | |
15 interestOpt = opt; | |
16 selector = _selector; | |
17 } | |
18 | |
19 public boolean isAble() { | |
20 if ( (interestOpt&OP_READ)!=0 && isReadable() ) | |
21 return true; | |
22 else if( (interestOpt&OP_ACCEPT)!=0 && isAcceptable() ) | |
23 return true; | |
24 else if( (interestOpt&OP_WRITE)!=0 && isWritable() ) | |
25 return true; | |
26 else | |
27 return false; | |
28 } | |
29 | |
30 public void setFlag() { | |
31 ready = 0; | |
32 if(channel.isAcceptable()) ready |= OP_ACCEPT; | |
33 if(channel.isReadable()) ready |= OP_READ; | |
34 if(channel.isWritable()) ready |= OP_WRITE; | |
35 } | |
36 | |
37 public SelectableChannelSimulator<P> channel() { | |
38 return channel; | |
39 } | |
40 | |
41 | |
42 @Override | |
43 public void cancel() { | |
44 // TODO Auto-generated method stub | |
45 | |
46 } | |
47 | |
48 @Override | |
49 public int interestOps() { | |
50 // TODO Auto-generated method stub | |
51 return interestOpt; | |
52 } | |
53 | |
54 @Override | |
55 public SelectionKey interestOps(int ops) { | |
56 interestOpt = ops; | |
57 return this; | |
58 } | |
59 | |
60 @Override | |
61 public boolean isValid() { | |
62 return true; | |
63 } | |
64 | |
65 @Override | |
66 public int readyOps() { | |
67 return ready; | |
68 } | |
69 | |
70 @Override | |
71 public Selector selector() { | |
72 // TODO Auto-generated method stub | |
73 return selector; | |
74 } | |
75 | |
76 } |