Mercurial > hg > RemoteEditor > REPSessionManager
diff rep/SessionManager.java @ 359:fa041bae35f1
all code written for distributed session except gather.
author | kono |
---|---|
date | Sun, 19 Oct 2008 19:24:38 +0900 |
parents | 034acadc0cdc |
children | b25f832f875d |
line wrap: on
line diff
--- a/rep/SessionManager.java Sun Oct 19 16:54:37 2008 +0900 +++ b/rep/SessionManager.java Sun Oct 19 19:24:38 2008 +0900 @@ -343,7 +343,7 @@ session.addForwarder(editor); REPCommand sendCommand = new REPCommand(); if (editor.isDirect()&&editor.getEID()==eid) { - sendUpdate(); + sendUpdate(session.getSID()); sendCommand.setCMD(REP.SMCMD_JOIN_ACK); } else { // SELECT_ACK is sent to the session ring to @@ -369,11 +369,26 @@ } } - private void sendUpdate() { - // TODO Auto-generated method stub - + private void sendUpdate(int sid) { + REPCommand command = makeREPCommandWithSessionList(REP.SMCMD_UPDATE); + command.setSID(sid); + command.setEID(REP.SM_EID.id); + smList.sendToMaster(command); } + public Editor newEditor(REPSocketChannel<REPCommand> channel) { + int eid = makeID(editorList.newEid()); + Editor editor = new Editor(this, eid, channel); + editorList.add(editor); + return editor; + } + + + public Session newSession(Forwarder master) { + int sid= makeID(sessionList.newSessionID()); + Session session = new Session(sid, master); + return session; + } public void addWaitingCommand(PacketSet set) { waitingCommandInMerge.add(set); @@ -432,7 +447,7 @@ private void removeSession(Session s0) { s0.remove(this); sessionList.remove(s0); - sendUpdate(); + sendUpdate(s0.getSID()); } public void setParentPort(int port) { @@ -456,10 +471,6 @@ case SMCMD_JOIN: { // first connection or forwarded command - if (forwarder.isDirect()) { - // direct linked editor なので、ここでIDを作成する - command.setEID(makeID(editorList.newEid())); - } if(isMaster()) { REPCommand ackCommand = new REPCommand(); ackCommand.setCMD(REP.SMCMD_JOIN_ACK); @@ -484,13 +495,6 @@ case SMCMD_PUT: { // first connection or forwarded command - if (forwarder.isDirect()) { - // direct link, make new ID - int eid = makeID(editorList.newEid()); - int sid = makeID(sessionList.newSessionID()); - command.setEID(eid); - command.setSID(sid); - } if(isMaster()) { command.setCMD(REP.SMCMD_PUT_ACK); command.string = command.string; @@ -559,11 +563,14 @@ break; case SMCMD_UPDATE: - command.setString(mergeUpdate(command)); - // 上に知らせる - smList.sendToMaster(command); - break; - + if (!isMaster()) { + command.setString(mergeUpdate(command)); + // 上に知らせる + smList.sendToMaster(command); + break; + } + // fall thru + command.setCMD(REP.SMCMD_UPDATE_ACK); case SMCMD_UPDATE_ACK: command.setString(mergeUpdate(command)); // 下に知らせる