Mercurial > hg > RemoteEditor > REPSessionManager
view rep/SessionManagerList.java @ 382:4b87f89b3afd
REP Session Manager (Java version)
new structure
author | one@firefly.cr.ie.u-ryukyu.ac.jp |
---|---|
date | Mon, 10 Nov 2008 22:07:45 +0900 |
parents | 1bde894edd83 |
children | 6f356d160e58 |
line wrap: on
line source
package rep; import java.util.LinkedList; import rep.handler.REPNode; import rep.handler.NullForwarder; public class SessionManagerList extends LinkedList<REPNode>{ /** * */ private static final long serialVersionUID = 1L; private int mySMID=0; private int smid_root=0; private REPNode parent=new NullForwarder(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(); } 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; } public void addWaitingSessionManager(REPNode fw, REPCommand command) { // SID assign 待ちのSessionManager Channelを登録する waiting.add(fw); } 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; } }