Mercurial > hg > RemoteEditor > REPSessionManager
view rep/SessionManagerList.java @ 137:1ea856259add
*** empty log message ***
author | pin |
---|---|
date | Wed, 27 Aug 2008 18:43:09 +0900 |
parents | 8dce4348966c |
children | 4ff7a00b13cc |
line wrap: on
line source
package rep; import java.util.LinkedList; import java.util.List; import rep.channel.REPSocketChannel; import rep.xml.SessionXMLEncoder; public class SessionManagerList { private List<REPSocketChannel<REPCommand>> list = new LinkedList<REPSocketChannel<REPCommand>>(); private int mySMID; private REPSocketChannel<REPCommand> master; public void add(REPSocketChannel<REPCommand> channel) { list.add(channel); } public void sendUpdate(int sessionID, String string) { for(REPSocketChannel<REPCommand> 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(REPSocketChannel<REPCommand> channel : list){ REPPacketSend send = new REPPacketSend(channel); send.send(command); } } public void sendUpdateUp(REPCommand command){ REPPacketSend send = new REPPacketSend(master); command.setCMD(REP.SMCMD_UPDATE_UP); send.send(command); } public void sendUpdateDown(REPCommand command){ command.setCMD(REP.SMCMD_UPDATE_DOWN); for(REPSocketChannel<REPCommand> channel : list){ if(channel == master) continue; REPPacketSend send = new REPPacketSend(channel); send.send(command); } } public void setMaster(REPSocketChannel<REPCommand> channel){ this.master = channel; } public void sendSessionList(SessionList sessionlist, REPCommand command) { SessionXMLEncoder encoder = new SessionXMLEncoder(sessionlist); command.setString(encoder.sessionListToXML()); for(REPSocketChannel<REPCommand> channel : list){ REPPacketSend send = new REPPacketSend(channel); send.send(command); } } public void send(REPSocketChannel<REPCommand> channel, REPCommand repCmd) { } public void sendToMaster(REPCommand repCmd) { REPPacketSend send = new REPPacketSend(master); send.send(repCmd); } public void sendToSlave(REPCommand repCmd) { for(REPSocketChannel<REPCommand> channel : list){ if(channel.equals(master)) continue; REPPacketSend send = new REPPacketSend(channel); send.send(repCmd); } } public void sendExcept(REPSocketChannel<REPCommand> exceptChannel, REPCommand command) { for(REPSocketChannel<REPCommand> channel : list){ if(channel.equals(exceptChannel)) continue; REPPacketSend send = new REPPacketSend(channel); send.send(command); } } }