Mercurial > hg > RemoteEditor > REPSessionManager
changeset 165:9bb6bbb08ad7
*** empty log message ***
author | kent |
---|---|
date | Thu, 28 Aug 2008 18:04:50 +0900 |
parents | 3841cc75b808 |
children | be2c1a1e9b8d |
files | rep/channel/REPServerSocket.java rep/channel/REPServerSocketChannel.java rep/channel/ServerChannelSimulator.java |
diffstat | 3 files changed, 80 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/rep/channel/REPServerSocket.java Thu Aug 28 17:58:42 2008 +0900 +++ b/rep/channel/REPServerSocket.java Thu Aug 28 18:04:50 2008 +0900 @@ -1,17 +1,65 @@ package rep.channel; import java.io.IOException; -import java.nio.channels.SocketChannel; +import java.net.InetAddress; +import java.net.ServerSocket; +import java.net.SocketAddress; +import java.nio.channels.ServerSocketChannel; + -public class REPServerSocket<T> extends REPSocketChannel<T>{ +/* こいつはシミュレーションの時しか生成され無いゾ */ +public class REPServerSocket extends ServerSocket{ + NetworkSimulator<?> ns; + ServerChannelSimulator<?> scs; + //scs.socket().setReuseAddress(true); + //scs.socket().bind(IP); - public REPServerSocket(SocketChannel channel) { - super(channel); + public REPServerSocket(ServerChannelSimulator<?> channel) throws IOException { + ns = NetworkSimulator.singleton(); + scs = channel; + } + + public void bind(int ip){ + scs.bind(ip); } - - public static <T> REPServerSocket<T> create() throws IOException { - return new REPServerSocket<T>(null); + @Override + public void close(){ + } + @Override + public ServerSocketChannel getChannel(){ + return scs; + } + @Override + public InetAddress getInetAddress(){ + return null; + } + @Override + public int getLocalPort(){ + return 0; + } + @Override + public SocketAddress getLocalSocketAddress(){ + return null; } - + @Override + public int getReceiveBufferSize(){ + return 0; + } + @Override + public boolean getReuseAddress(){ + return false; + } + @Override + public int getSoTimeout(){ + return 0; + } + /* + @Override + public (){ + } + @Override + public (){ + }*/ + }
--- a/rep/channel/REPServerSocketChannel.java Thu Aug 28 17:58:42 2008 +0900 +++ b/rep/channel/REPServerSocketChannel.java Thu Aug 28 18:04:50 2008 +0900 @@ -8,6 +8,10 @@ import java.nio.channels.SocketChannel; import java.nio.channels.spi.SelectorProvider; +/* + * シミュレーションでは inheritance のServerChannelSimulator を生成、 + * リアルコミュニケーションでは 自身を生成、内部にもつ ServerSocketChannelを扱う + */ public class REPServerSocketChannel<P> extends ServerSocketChannel{ public static boolean isSimulation;
--- a/rep/channel/ServerChannelSimulator.java Thu Aug 28 17:58:42 2008 +0900 +++ b/rep/channel/ServerChannelSimulator.java Thu Aug 28 18:04:50 2008 +0900 @@ -6,33 +6,44 @@ import java.nio.channels.SelectionKey; import java.nio.channels.SocketChannel; +/* シミュレーションの際にコンストラクトされる REPServerSocketChannel の実装 */ public class ServerChannelSimulator<P>extends REPServerSocketChannel<P>{ protected NetworkSimulator<P> ns; - public REPServerSocket<REPSocketChannel<P>> socket; + //public REPServerSocket<REPSocketChannel<P>> socket; + protected int virtualIP; /** Constructors. * @throws IOException */ public ServerChannelSimulator() throws IOException { - socket = REPServerSocket.<REPSocketChannel<P>>create(); + //socket = REPServerSocket.<REPSocketChannel<P>>create(); + } + + public void bind(int ip){ + virtualIP = ip; } - public REPSocketChannel<P> accept1() throws IOException { - return new REPSocketChannel<P>(ss.accept()); + public REPSocketChannel<P> accept1() /*throws IOException*/ { + return ns.accept(virtualIP); } @Override public ServerSocket socket() { - return socket; + try { + return new REPServerSocket(this); + } catch (IOException e) { + e.printStackTrace(); + return null; + } } @Override protected void implCloseSelectableChannel() throws IOException { - ss.close(); + return; } @Override protected void implConfigureBlocking(boolean block) throws IOException { - ss.configureBlocking(block); + return; } @Override @@ -44,7 +55,9 @@ public SelectionKey register(REPSelector sel, int ops, Object att) throws ClosedChannelException { REPSelector selector = sel; + ns.listen(virtualIP, (SelectorSimulator) selector); return selector.register(this, ops, att); } + }