Mercurial > hg > RemoteEditor > REPSessionManager
view rep/SessionManagerList.java @ 82:4bb583553a42
*** empty log message ***
author | pin |
---|---|
date | Tue, 11 Dec 2007 14:26:13 +0900 |
parents | 8a4f92f31c58 |
children | 8dce4348966c |
line wrap: on
line source
package rep; import java.nio.channels.SocketChannel; import java.util.LinkedList; import java.util.List; import rep.xml.SessionXMLEncoder; public class SessionManagerList { private List<SocketChannel> list = new LinkedList<SocketChannel>(); private int mySMID; private SocketChannel master; public void add(SocketChannel channel) { list.add(channel); } public void sendUpdate(int sessionID, String string) { for(SocketChannel 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(SocketChannel 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(SocketChannel channel : list){ if(channel == master) continue; REPPacketSend send = new REPPacketSend(channel); send.send(command); } } public void setMaster(SocketChannel channel){ this.master = channel; } public void sendSessionList(SessionList sessionlist, REPCommand command) { SessionXMLEncoder encoder = new SessionXMLEncoder(sessionlist); command.setString(encoder.sessionListToXML()); for(SocketChannel channel : list){ REPPacketSend send = new REPPacketSend(channel); send.send(command); } } public void send(SocketChannel channel, REPCommand repCmd) { } public void sendToMaster(REPCommand repCmd) { REPPacketSend send = new REPPacketSend(master); send.send(repCmd); } public void sendToSlave(REPCommand repCmd) { for(SocketChannel channel : list){ if(channel.equals(master)) continue; REPPacketSend send = new REPPacketSend(channel); send.send(repCmd); } } public void sendExcept(SocketChannel exceptChannel, REPCommand command) { for(SocketChannel channel : list){ if(channel.equals(exceptChannel)) continue; REPPacketSend send = new REPPacketSend(channel); send.send(command); } } }