annotate rep/channel/ServerChannelSimulator.java @ 194:be219ba8b39c

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