Mercurial > hg > RemoteEditor > REPSessionManager
comparison rep/channel/ServerChannelSimulator.java @ 175:5653cf8e3c8b
*** empty log message ***
author | kent |
---|---|
date | Thu, 28 Aug 2008 21:22:07 +0900 |
parents | 9bb6bbb08ad7 |
children | be219ba8b39c |
comparison
equal
deleted
inserted
replaced
174:72252e970a8b | 175:5653cf8e3c8b |
---|---|
1 package rep.channel; | 1 package rep.channel; |
2 | 2 |
3 import java.io.IOException; | 3 import java.io.IOException; |
4 import java.net.ServerSocket; | 4 import java.net.ServerSocket; |
5 import java.net.SocketAddress; | |
5 import java.nio.channels.ClosedChannelException; | 6 import java.nio.channels.ClosedChannelException; |
6 import java.nio.channels.SelectionKey; | 7 import java.nio.channels.SelectionKey; |
7 import java.nio.channels.SocketChannel; | 8 import java.nio.channels.SocketChannel; |
8 | 9 |
9 /* シミュレーションの際にコンストラクトされる REPServerSocketChannel の実装 */ | 10 /* シミュレーションの際にコンストラクトされる REPServerSocketChannel の実装 */ |
10 public class ServerChannelSimulator<P>extends REPServerSocketChannel<P>{ | 11 public class ServerChannelSimulator<P>extends REPServerSocketChannel<P>{ |
11 protected NetworkSimulator<P> ns; | 12 protected NetworkSimulator<P> ns; |
12 //public REPServerSocket<REPSocketChannel<P>> socket; | 13 //public REPServerSocket<REPSocketChannel<P>> socket; |
13 protected int virtualIP; | 14 protected SocketAddress IP; |
14 | 15 |
15 /** Constructors. | 16 /** Constructors. |
16 * @throws IOException */ | 17 * @throws IOException */ |
17 public ServerChannelSimulator() throws IOException { | 18 public ServerChannelSimulator() throws IOException { |
18 //socket = REPServerSocket.<REPSocketChannel<P>>create(); | 19 //socket = REPServerSocket.<REPSocketChannel<P>>create(); |
20 ns = NetworkSimulator.<P>singleton(); | |
19 } | 21 } |
20 | 22 |
21 public void bind(int ip){ | 23 public void bind(SocketAddress ip){ |
22 virtualIP = ip; | 24 IP = ip; |
23 } | 25 } |
24 | 26 |
25 public REPSocketChannel<P> accept1() /*throws IOException*/ { | 27 public REPSocketChannel<P> accept1() /*throws IOException*/ { |
26 return ns.accept(virtualIP); | 28 return ns.accept(IP); |
27 } | 29 } |
28 | 30 |
29 @Override | 31 @Override |
30 public ServerSocket socket() { | 32 public ServerSocket socket() { |
31 try { | 33 try { |
53 } | 55 } |
54 | 56 |
55 | 57 |
56 public SelectionKey register(REPSelector sel, int ops, Object att) throws ClosedChannelException { | 58 public SelectionKey register(REPSelector sel, int ops, Object att) throws ClosedChannelException { |
57 REPSelector selector = sel; | 59 REPSelector selector = sel; |
58 ns.listen(virtualIP, (SelectorSimulator) selector); | 60 ns.listen(IP, (SelectorSimulator) selector); |
59 return selector.register(this, ops, att); | 61 return selector.register(this, ops, att); |
60 } | 62 } |
61 | 63 |
64 public boolean isAcceptable() { | |
65 return ns.canAccept(IP); | |
66 } | |
62 | 67 |
63 } | 68 } |