123
|
1 package rep.channel;
|
|
2
|
|
3 import java.io.IOException;
|
156
|
4 import java.net.ServerSocket;
|
175
|
5 import java.net.SocketAddress;
|
123
|
6 import java.nio.channels.ClosedChannelException;
|
194
|
7 import java.nio.channels.SelectableChannel;
|
123
|
8 import java.nio.channels.SelectionKey;
|
194
|
9 import java.nio.channels.Selector;
|
156
|
10 import java.nio.channels.SocketChannel;
|
194
|
11 import java.nio.channels.spi.SelectorProvider;
|
123
|
12
|
165
|
13 /* シミュレーションの際にコンストラクトされる REPServerSocketChannel の実装 */
|
194
|
14 public class ServerChannelSimulator<P>extends REPServerSocketChannel<P> {
|
123
|
15 protected NetworkSimulator<P> ns;
|
165
|
16 //public REPServerSocket<REPSocketChannel<P>> socket;
|
175
|
17 protected SocketAddress IP;
|
123
|
18
|
156
|
19 /** Constructors.
|
|
20 * @throws IOException */
|
|
21 public ServerChannelSimulator() throws IOException {
|
165
|
22 //socket = REPServerSocket.<REPSocketChannel<P>>create();
|
175
|
23 ns = NetworkSimulator.<P>singleton();
|
165
|
24 }
|
|
25
|
175
|
26 public void bind(SocketAddress ip){
|
|
27 IP = ip;
|
123
|
28 }
|
|
29
|
165
|
30 public REPSocketChannel<P> accept1() /*throws IOException*/ {
|
175
|
31 return ns.accept(IP);
|
123
|
32 }
|
|
33
|
156
|
34 public ServerSocket socket() {
|
165
|
35 try {
|
|
36 return new REPServerSocket(this);
|
|
37 } catch (IOException e) {
|
|
38 e.printStackTrace();
|
|
39 return null;
|
|
40 }
|
156
|
41 }
|
|
42
|
|
43
|
123
|
44
|
194
|
45 public SelectionKey register(REPSelector<P> sel, int ops, Object att) throws ClosedChannelException {
|
|
46 REPSelector<P> selector = sel;
|
175
|
47 ns.listen(IP, (SelectorSimulator) selector);
|
156
|
48 return selector.register(this, ops, att);
|
123
|
49 }
|
|
50
|
175
|
51 public boolean isAcceptable() {
|
|
52 return ns.canAccept(IP);
|
|
53 }
|
165
|
54
|
194
|
55 @Override
|
|
56 public Object blockingLock() {
|
|
57 // TODO Auto-generated method stub
|
|
58 return null;
|
|
59 }
|
|
60
|
|
61 public SelectableChannel configureBlocking(boolean block)
|
|
62 throws IOException {
|
|
63 // TODO Auto-generated method stub
|
|
64 return null;
|
|
65 }
|
|
66
|
|
67 @Override
|
|
68 public boolean isBlocking() {
|
|
69 // TODO Auto-generated method stub
|
|
70 return false;
|
|
71 }
|
|
72
|
|
73 @Override
|
|
74 public boolean isRegistered() {
|
|
75 // TODO Auto-generated method stub
|
|
76 return false;
|
|
77 }
|
|
78
|
|
79 @Override
|
|
80 public SelectionKey keyFor(Selector sel) {
|
|
81 // TODO Auto-generated method stub
|
|
82 return null;
|
|
83 }
|
|
84
|
|
85 @Override
|
|
86 public SelectorProvider provider() {
|
|
87 // TODO Auto-generated method stub
|
|
88 return null;
|
|
89 }
|
|
90
|
|
91 @Override
|
|
92 public SelectionKey register(Selector sel, int ops, Object att)
|
|
93 throws ClosedChannelException {
|
|
94 // TODO Auto-generated method stub
|
|
95 return null;
|
|
96 }
|
|
97
|
|
98 @Override
|
|
99 public int validOps() {
|
|
100 // TODO Auto-generated method stub
|
|
101 return 0;
|
|
102 }
|
|
103
|
|
104 @Override
|
|
105 protected void implCloseChannel() throws IOException {
|
|
106 // TODO Auto-generated method stub
|
|
107
|
|
108 }
|
|
109
|
123
|
110 }
|