123
|
1 package rep.channel;
|
|
2
|
|
3 import java.io.IOException;
|
|
4 import java.nio.channels.ClosedChannelException;
|
|
5 import java.nio.channels.SelectableChannel;
|
|
6 import java.nio.channels.SelectionKey;
|
|
7 import java.nio.channels.Selector;
|
|
8 import java.nio.channels.ServerSocketChannel;
|
|
9 import java.nio.channels.spi.SelectorProvider;
|
|
10
|
|
11
|
|
12
|
|
13 public class ServerChannelSimulator<P>extends SelectableChannelSimulator<P>{
|
|
14 protected NetworkSimulator<P> ns;
|
|
15 private int virtualIP;
|
|
16
|
|
17 /** Constructors. */
|
|
18 public ServerChannelSimulator(NetworkSimulator<P> _ns, SelectorSimulator<P> rselector){
|
|
19 super(null);
|
|
20 ns = _ns;
|
|
21 readSelector = rselector;
|
|
22 writeSelector = null;
|
|
23 qread = null;
|
|
24 qwrite = null;
|
|
25 }
|
|
26
|
|
27 /** Connecting methods */
|
|
28 // for servers.
|
|
29 public void bind(int ip){
|
|
30 virtualIP = ip;
|
|
31 ns.listen(ip, readSelector);
|
|
32 }
|
|
33
|
|
34 public ChannelSimulator<P> accept(){
|
|
35 ChannelSimulator<P> channel = ns.accept(virtualIP);
|
|
36 return channel;
|
|
37 }
|
|
38
|
|
39
|
|
40 /* state check methods for SelectionKeySimulator. */
|
|
41 public boolean isReadable() {
|
|
42 return false;
|
|
43 }
|
|
44 public boolean isWritable() {
|
|
45 return false;
|
|
46 }
|
|
47 public boolean isAcceptable() {
|
|
48 return ns.canAccept(virtualIP);
|
|
49 }
|
|
50
|
|
51 @Override
|
|
52 public Object blockingLock() {
|
|
53 // TODO Auto-generated method stub
|
|
54 return null;
|
|
55 }
|
|
56
|
|
57 @Override
|
|
58 public SelectableChannel configureBlocking(boolean block) throws IOException {
|
|
59 // TODO Auto-generated method stub
|
|
60 return null;
|
|
61 }
|
|
62
|
|
63 @Override
|
|
64 public boolean isBlocking() {
|
|
65 // TODO Auto-generated method stub
|
|
66 return false;
|
|
67 }
|
|
68
|
|
69 @Override
|
|
70 public boolean isRegistered() {
|
|
71 // TODO Auto-generated method stub
|
|
72 return false;
|
|
73 }
|
|
74
|
|
75 @Override
|
|
76 public SelectionKey keyFor(Selector sel) {
|
|
77 // TODO Auto-generated method stub
|
|
78 return null;
|
|
79 }
|
|
80
|
|
81 @Override
|
|
82 public SelectorProvider provider() {
|
|
83 // TODO Auto-generated method stub
|
|
84 return null;
|
|
85 }
|
|
86
|
|
87 @Override
|
|
88 public SelectionKey register(Selector sel, int ops, Object att) throws ClosedChannelException {
|
|
89 // TODO Auto-generated method stub
|
|
90 return null;
|
|
91 }
|
|
92
|
|
93 @Override
|
|
94 public int validOps() {
|
|
95 // TODO Auto-generated method stub
|
|
96 return 0;
|
|
97 }
|
|
98
|
|
99 @Override
|
|
100 protected void implCloseChannel() throws IOException {
|
|
101 // TODO Auto-generated method stub
|
|
102
|
|
103 }
|
|
104
|
|
105 public static ServerSocketChannel open() {
|
|
106 // TODO Auto-generated method stub
|
|
107 return null;
|
|
108 }
|
|
109
|
|
110 }
|