Mercurial > hg > RemoteEditor > REPSessionManager
view rep/SessionManagerList.java @ 355:98607350f7d1
*** empty log message ***
author | kono |
---|---|
date | Fri, 17 Oct 2008 22:11:34 +0900 |
parents | ef4afcae0c92 |
children | b18c24dcc5d2 |
line wrap: on
line source
package rep; import java.util.LinkedList; import rep.channel.REPSocketChannel; public class SessionManagerList { private LinkedList<Forwarder> list = new LinkedList<Forwarder>(); private int mySMID; private Forwarder parent=null; private LinkedList<Forwarder> waiting= new LinkedList<Forwarder>(); public void add(Forwarder channel) { list.add(channel); } public void setMaster(Forwarder f) { this.parent = f; } public void sendToMaster(REPCommand repCmd) { parent.send(repCmd); } public void sendToSlaves(REPCommand repCmd) { for(Forwarder channel : list){ channel.send(repCmd); } } public boolean isMaster() { return parent==null; } public int addNewSessionManager(Forwarder fw,REPCommand receivedCommand) { list.add(fw); int sid = list.size(); fw.setSID(sid); fw.setName(receivedCommand.string); return sid; } public boolean isSessionManagerChannel(REPSocketChannel<REPCommand> channel) { for(Forwarder f : list){ if (f.channel==channel) return true; } return false; } public void setSessionManagerID(int sid) { mySMID = sid; } public int sessionManagerID() { return mySMID; } public void addWaitingSessionManager(Forwarder 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が確定する。 Forwarder waiter; if ((waiter=waiting.poll())!=null) { waiter.setSID(sid); list.add(waiter); return; } assert false; } }