Mercurial > hg > RemoteEditor > REPSessionManager
view rep/SessionManagerList.java @ 442:3819dec4641e
command waiting during merge
author | one |
---|---|
date | Sun, 12 Sep 2010 22:23:53 +0900 |
parents | 795ef563f2a0 |
children |
line wrap: on
line source
package rep; import java.util.LinkedList; import rep.channel.REPSocketChannel; import rep.handler.REPNode; import rep.handler.NullForwarder; public class SessionManagerList extends LinkedList<REPNode>{ /** * Session Manager List which we have a connection. */ private static final long serialVersionUID = 1L; private int mySMID=0; private int smid_root=0; private REPNode parent=new NullForwarder(null,null); private LinkedList<REPNode> waiting= new LinkedList<REPNode>(); public void setMaster(REPNode f) { this.parent = f; } public void sendToMaster(REPCommand repCmd) { parent.send(repCmd); } public void sendToSlaves(REPCommand repCmd) { for(REPNode channel : this){ channel.send(repCmd); } } public boolean isMaster() { return !parent.isForwarder(); } /** * Add our slave session manager. Only an empty session manager can * connect to the other session manager. join_sm() is forwarded to * the master session manager, and in the master addNewSessionManager() * is performed. * * @param sm * @param receivedCommand * @return session manager id (global) */ public int addNewSessionManager(REPNode sm,REPCommand receivedCommand) { add(sm); int sid = ++smid_root; sm.setSID(sid); sm.setName(receivedCommand.string); return sid; } public void setSessionManagerID(int sid) { mySMID = sid; } public int sessionManagerID() { return mySMID; } /** * An sm_join() is accepted, but we are not the master, forward request * and register as an waiting sessin manager. * @param fw * @param command */ public void addWaitingSessionManager(REPNode fw, REPCommand command) { // SID assign 待ちのSessionManager Channelを登録する waiting.add(fw); } /** * An sm_join_ack() is received. Assign session manager id to the waiter. * @param sid */ public void assignSessionManagerIDtoWaitingSM(int sid) { // 待っていたSession Manager ChannelにSession IDを登録し,Session Manager List // に登録する。この次のsm_join_ackでSIDが確定する。 REPNode waiter; if ((waiter=waiting.poll())!=null) { waiter.setSID(sid); add(waiter); return; } assert false; } public void setParent(REPNode fw) { parent = fw; } public REPNode parent() { return parent; } public REPNode managerByChannel(REPSocketChannel<REPCommand> channel) { for(REPNode e:this) { if (e.channel==channel) return e; } return null; } }