Mercurial > hg > RemoteEditor > REPSessionManager
changeset 155:bbd2801d8ce0
*** empty log message ***
author | pin |
---|---|
date | Thu, 28 Aug 2008 15:39:20 +0900 |
parents | fafbaaa0abd0 |
children | 31334767e65d |
files | rep/Editor.java rep/SessionManager.java rep/handler/PacketSet.java rep/handler/REPHandlerImpl.java rep/handler/REPHandlerInMerge.java |
diffstat | 5 files changed, 26 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/rep/Editor.java Thu Aug 28 15:33:02 2008 +0900 +++ b/rep/Editor.java Thu Aug 28 15:39:20 2008 +0900 @@ -16,6 +16,12 @@ private String file; private TranslaterImp1 translater; private List<REPCommand> sentList; + + public Editor(){ + setHostAndPort(myChannel); + translater = new TranslaterImp1(eid); + sentList = new LinkedList<REPCommand>(); + } public Editor(int editorNo, REPSocketChannel<REPCommand> channel){ this.eid = editorNo; @@ -89,7 +95,6 @@ } public REPSocketChannel<REPCommand> getChannel() { - return myChannel; } @@ -116,7 +121,6 @@ } public String toString(){ return (host + ":" + port + ":" + file); - //return ("eid:" + eid + ":" + myChannel.socket().getLocalSocketAddress().toString()); } public String getName() {
--- a/rep/SessionManager.java Thu Aug 28 15:33:02 2008 +0900 +++ b/rep/SessionManager.java Thu Aug 28 15:39:20 2008 +0900 @@ -56,6 +56,7 @@ private List<Editor> editorList; private String maxHost; private boolean isSimulation; + private List<PacketSet> packetSetList; //private Set<SelectionKey> sessionList; private static int temp_port; private static int send_port; @@ -70,14 +71,11 @@ selector = REPSelector.open(); } - public void mainLoop(int port) throws InterruptedException, IOException { + public void init(int port) throws InterruptedException, IOException { REPServerSocketChannel<REPCommand> ssc = REPServerSocketChannel.<REPCommand>open(); - ssc.configureBlocking(false); //reuse address 必須 - ssc.socket().setReuseAddress(true); - ssc.socket().bind(new InetSocketAddress(port)); ssc.register(selector, SelectionKey.OP_ACCEPT); @@ -87,7 +85,13 @@ smList = new SessionManagerList(); ownEditorList = new EditorList(); editorList = new LinkedList<Editor>(); + packetSetList = new LinkedList<PacketSet>(); + // main loop + mainLoop(); + } + + private void mainLoop() throws IOException { while(true){ selector.select(); select(); @@ -398,7 +402,8 @@ SessionManager sm = new SessionManager(port); sm.openSelector(); sm.openWindow(); - sm.mainLoop(port); + sm.init(port); + sm.mainLoop(); } private void openWindow() { @@ -498,7 +503,7 @@ public void addWaitingCommand(PacketSet set) { // TODO Auto-generated method stub - + packetSetList.add(set); } public void undo() {
--- a/rep/handler/PacketSet.java Thu Aug 28 15:33:02 2008 +0900 +++ b/rep/handler/PacketSet.java Thu Aug 28 15:39:20 2008 +0900 @@ -2,13 +2,14 @@ import rep.REPCommand; import rep.channel.ChannelSimulator; +import rep.channel.REPSocketChannel; public class PacketSet { - private ChannelSimulator<REPCommand> channel; + private REPSocketChannel<REPCommand> channel; private REPCommand packet; - public PacketSet(ChannelSimulator<REPCommand> channel, REPCommand packet) { + public PacketSet(REPSocketChannel<REPCommand> channel, REPCommand packet) { this.channel = channel; this.packet = packet; }
--- a/rep/handler/REPHandlerImpl.java Thu Aug 28 15:33:02 2008 +0900 +++ b/rep/handler/REPHandlerImpl.java Thu Aug 28 15:39:20 2008 +0900 @@ -1,5 +1,6 @@ package rep.handler; +import java.io.IOException; import java.nio.channels.SelectionKey; import rep.REPCommand; @@ -17,7 +18,7 @@ this.manager = manager; } - public void handle(SelectionKeySimulator key) { + public void handle(SelectionKeySimulator key) throws IOException { REPSocketChannel<REPCommand> channel = (REPSocketChannel<REPCommand>) key.channel(); REPCommand packet = channel.read(); REPCommand command = packet;
--- a/rep/handler/REPHandlerInMerge.java Thu Aug 28 15:33:02 2008 +0900 +++ b/rep/handler/REPHandlerInMerge.java Thu Aug 28 15:39:20 2008 +0900 @@ -1,9 +1,11 @@ package rep.handler; +import java.io.IOException; import java.nio.channels.SelectionKey; import rep.REPCommand; import rep.SessionManager; import rep.channel.ChannelSimulator; +import rep.channel.REPSocketChannel; import rep.channel.SelectionKeySimulator; public class REPHandlerInMerge implements REPHandler { @@ -15,8 +17,8 @@ this.manager = manager; } - public void handle(SelectionKeySimulator key) { - ChannelSimulator<REPCommand> channel = (ChannelSimulator<REPCommand>) key.channel(); + public void handle(SelectionKeySimulator key) throws IOException { + REPSocketChannel<REPCommand> channel = (REPSocketChannel<REPCommand>) key.channel(); REPCommand packet = channel.read(); manager.addWaitingCommand(new PacketSet(channel, packet)); REPCommand command = packet;