Mercurial > hg > RemoteEditor > REPSessionManager
changeset 205:dfc2afab1325 simulator-nio-both-worked
*** empty log message ***
author | kono |
---|---|
date | Sat, 30 Aug 2008 11:42:52 +0900 |
parents | 0607cc699ba3 |
children | a2aaf8af7bcc |
files | rep/channel/SelectionKeySimulator.java test/channeltest/testSeMa.java test/channeltest/testSeMaSlave.java |
diffstat | 3 files changed, 14 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/rep/channel/SelectionKeySimulator.java Sat Aug 30 11:25:27 2008 +0900 +++ b/rep/channel/SelectionKeySimulator.java Sat Aug 30 11:42:52 2008 +0900 @@ -4,7 +4,6 @@ import java.nio.channels.SelectableChannel; import java.nio.channels.SelectionKey; import java.nio.channels.Selector; -import java.nio.channels.ServerSocketChannel; public class SelectionKeySimulator<P> extends REPSelectionKey<P>{ @@ -53,6 +52,7 @@ return channel; } + @SuppressWarnings("unchecked") public REPSocketChannel<P> accept(REPPack<P> pack) throws IOException { assert(channel instanceof ServerChannelSimulator); ServerChannelSimulator<P> scs = (ServerChannelSimulator<P>) channel;
--- a/test/channeltest/testSeMa.java Sat Aug 30 11:25:27 2008 +0900 +++ b/test/channeltest/testSeMa.java Sat Aug 30 11:42:52 2008 +0900 @@ -33,17 +33,16 @@ @SuppressWarnings("unchecked") public void run() { - REPSelector selector=null; + REPSelector<String> selector=null; REPServerSocketChannel<String> scs; - REPPack pack = new StringPacker(); + REPPack<String> pack = new StringPacker(); try { selector = REPSelector.<String>create(); scs = REPServerSocketChannel.<String>open(pack); scs.socket().setReuseAddress(true); scs.socket().bind(IP); scs.configureBlocking(false); - //selector.register(scs, SelectionKey.OP_ACCEPT, null); scs.register(selector, SelectionKey.OP_ACCEPT, null); } catch (IOException e1) { ns.writeLog("cannot create REPServerSocketChannel!, exit."); @@ -63,7 +62,6 @@ for(REPSelectionKey<String> key : set) { if(key.isAcceptable()){ - ns.writeLog("gets acceptable channel", 1); REPSocketChannel<String> channel = key.accept(pack); if(channel==null) continue; channel.configureBlocking(false); @@ -72,7 +70,6 @@ }else if(key.isReadable()){ ns.writeLog("gets readable channel", 1); - //SelectableChannelSimulator<String> channel = key.channel(); REPSocketChannel<String> channel = (REPSocketChannel<String>) key.channel(pack); String packet; packet = channel.read();
--- a/test/channeltest/testSeMaSlave.java Sat Aug 30 11:25:27 2008 +0900 +++ b/test/channeltest/testSeMaSlave.java Sat Aug 30 11:42:52 2008 +0900 @@ -8,6 +8,8 @@ import java.nio.channels.Selector; import rep.channel.REPLogger; +import rep.channel.REPPack; +import rep.channel.REPSelectionKey; import rep.channel.REPSelector; import rep.channel.REPServerSocketChannel; import rep.channel.REPSocketChannel; @@ -31,11 +33,13 @@ } + @SuppressWarnings("unchecked") public void run() { - REPSelector selector; + REPSelector<String> selector; REPSocketChannel<String> masterCH ; try { - REPServerSocketChannel<String> scs = REPServerSocketChannel.<String>open(new StringPacker()); + REPPack<String> pack = new StringPacker(); + REPServerSocketChannel<String> scs = REPServerSocketChannel.<String>open(pack); selector = REPSelector.create(); masterCH = connectToMaster(selector); scs.socket().bind(ownIP); @@ -50,18 +54,18 @@ selector.select(); - for(SelectionKey key : selector.selectedKeys()){ + for(REPSelectionKey<String> key : selector.selectedKeys1()){ if(key.isAcceptable()){ - ns.writeLog("gets acceptable channel", 1); - REPServerSocketChannel<String> sc = (REPServerSocketChannel<String>) key.channel(); - REPSocketChannel<String> channel = sc.accept1(); + REPSocketChannel<String> channel = key.accept(pack); + if(channel==null) continue; + channel.configureBlocking(false); selector.register(channel, SelectionKey.OP_READ,null); ns.writeLog("accepts a client.", 1); }else if(key.isReadable()){ ns.writeLog("gets readable channel", 1); - REPSocketChannel<String> channel = (REPSocketChannel<String>) key.channel(); + REPSocketChannel<String> channel = (REPSocketChannel<String>) key.channel(pack); String packet = channel.read(); if (channel==masterCH){ ns.writeLog("receives String from master ==> `"+packet+"\'", 1);