Mercurial > hg > RemoteEditor > REPSessionManager
changeset 21:2d4bab638a71
*** empty log message ***
author | pin |
---|---|
date | Thu, 08 Nov 2007 04:37:59 +0900 |
parents | 83088d943612 |
children | 850a9cc4963a |
files | rep/Editor.java rep/REPPacketReceive.java rep/SessionManager.java rep/SessionManagerList.java |
diffstat | 4 files changed, 49 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/rep/Editor.java Tue Nov 06 15:26:37 2007 +0900 +++ b/rep/Editor.java Thu Nov 08 04:37:59 2007 +0900 @@ -6,6 +6,8 @@ private int editorNo; private SocketChannel channel; private SocketChannel nextChannel; + private String host; + private String port; public Editor(int editorNo, SocketChannel channel){ this.editorNo = editorNo; @@ -15,4 +17,19 @@ public SocketChannel getChannel() { return channel; } + + public void setHost(String host){ + this.host = host; + } + public void setPort(String port){ + this.port = port; + } + + public String getHost(){ + return host; + } + public String getPort(){ + return port; + } + }
--- a/rep/REPPacketReceive.java Tue Nov 06 15:26:37 2007 +0900 +++ b/rep/REPPacketReceive.java Thu Nov 08 04:37:59 2007 +0900 @@ -68,8 +68,8 @@ //getSocket(string); REPCommand repcommand = new REPCommand(cmd, sid, eid, seqid, lineno, textsiz, string); System.out.println("received command: " + repcommand.toString()); - getSocket(repcommand); - System.out.println("received command: " + repcommand.toString()); + //getSocket(repcommand); + //System.out.println("received command: " + repcommand.toString()); return repcommand; }
--- a/rep/SessionManager.java Tue Nov 06 15:26:37 2007 +0900 +++ b/rep/SessionManager.java Thu Nov 08 04:37:59 2007 +0900 @@ -1,7 +1,6 @@ package rep; import java.io.IOException; -import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.SocketAddress; import java.nio.channels.SelectableChannel; @@ -33,7 +32,7 @@ private Selector selector; private SessionManagerList smList; private String myHost; - private String myPort; + private boolean isMaster = true; //private SocketChannel sessionchannel; //private boolean co; public SessionManager(int port) { @@ -101,7 +100,7 @@ }else if(key.isConnectable()){ System.out.println("Connectable"); - } //Socketのcloseを実装する + } } } } @@ -120,13 +119,18 @@ if(repCmd == null) return; switch(repCmd.cmd){ case REP.SMCMD_JOIN: - join_ack(channel, repCmd); + if(isMaster){ + sendJoinAck(channel, repCmd); + }else{ + sendJoin(repCmd); + } break; case REP.SMCMD_JOIN_ACK: + sendJoinAck(repCmd); break; case REP.SMCMD_PUT: int sessionID = sessionlist.addSession(channel, repCmd.string); //SIDを取得 - smList.update(sessionID, repCmd.string); //updateコマンド:Session生成を通知 + smList.sendUpdate(sessionID, repCmd.string); //updateコマンド:Session生成を通知 sessionmanagerGUI.setComboSession(sessionID, repCmd.string); //ComboBoxにSessionを追加 repCmd.setSID(sessionID); //SIDをセット repCmd.setCMD(repCmd.cmd + 1); //ACKを返す @@ -147,11 +151,12 @@ case REP.SMCMD_SESSION: break; case REP.SMCMD_SM_JOIN: + this.isMaster = true; myHost = repCmd.host; - myPort = repCmd.port; - sm_join_ack(channel, repCmd); + sendSessionManagerJoinAck(channel, repCmd); break; case REP.SMCMD_SM_JOIN_ACK: + this.isMaster = false; myHost = repCmd.host; smList.add(channel); //SessionManagerのリストへ追加 break; @@ -173,7 +178,11 @@ } } - private void sm_join_ack(SocketChannel channel, REPCommand repCmd) { + private void sendJoin(REPCommand repCmd) { + smList.sendJoin(repCmd); + } + + private void sendSessionManagerJoinAck(SocketChannel channel, REPCommand repCmd) { String socketstring = getSocketString(channel); System.out.println(socketstring); smList.add(channel); //SessionManagerのリストへ追加 @@ -182,8 +191,12 @@ REPPacketSend repSend4 = new REPPacketSend(channel); repSend4.send(repCmd); //ACK } + + private void sendJoinAck(REPCommand repCmd) { + + } - private void join_ack(SocketChannel channel, REPCommand repCmd) { + private void sendJoinAck(SocketChannel channel, REPCommand repCmd) { int eid = sessionlist.getNumberOfEditor(); //eidを取得 sessionmanagerGUI.setComboEditor(eid, channel); //ComboBoxにEditorを追加 repCmd.setEID(eid); //eidを決定して、
--- a/rep/SessionManagerList.java Tue Nov 06 15:26:37 2007 +0900 +++ b/rep/SessionManagerList.java Thu Nov 08 04:37:59 2007 +0900 @@ -10,16 +10,21 @@ private int mySMID; public void add(SocketChannel channel) { - // TODO Auto-generated method stub list.add(channel); } - public void update(int sessionID, String string) { - // TODO Auto-generated method stub + public void sendUpdate(int sessionID, String string) { for(SocketChannel channel : list){ REPPacketSend send = new REPPacketSend(channel); send.send(new REPCommand(REP.SMCMD_UPDATE, 0, mySMID, 0, 0, string.length(), string)); } } + public void sendJoin(REPCommand command) { + for(SocketChannel channel : list){ + REPPacketSend send = new REPPacketSend(channel); + send.send(command); + } + } + }