Mercurial > hg > RemoteEditor > REPSessionManager
diff rep/SessionManager.java @ 133:8dce4348966c
*** empty log message ***
author | kono |
---|---|
date | Wed, 27 Aug 2008 18:27:12 +0900 |
parents | 97a321d91b79 |
children | d6b94713cf45 |
line wrap: on
line diff
--- a/rep/SessionManager.java Wed Aug 27 18:22:36 2008 +0900 +++ b/rep/SessionManager.java Wed Aug 27 18:27:12 2008 +0900 @@ -17,6 +17,7 @@ import java.util.StringTokenizer; import rep.channel.REPServerSocketChannel; +import rep.channel.REPSocketChannel; import rep.simulator.REPSelector; import rep.xml.SessionXMLDecoder; import rep.xml.SessionXMLEncoder; @@ -38,7 +39,6 @@ private SessionList sessionlist; - //SocketChannel sessionchannel; private SessionManagerGUI gui; private Selector selector; private SessionManagerList smList; @@ -46,9 +46,6 @@ private boolean isMaster = true; private EditorList ownEditorList; private String maxHost; - //private boolean addressIsGlobal; - //private SocketChannel sessionchannel; - //private boolean co; private static int temp_port; private static int send_port; @@ -65,8 +62,7 @@ public void sessionManagerNet(int port) throws InterruptedException, IOException { - //ServerSocketChannel ssc = ServerSocketChannel.open(); - REPServerSocketChannel ssc = REPServerSocketChannel.open(); + REPServerSocketChannel<REPCommand> ssc = REPServerSocketChannel.open(); ssc.configureBlocking(false); //reuse address 必須 @@ -93,7 +89,7 @@ }else if(key.isReadable()){ - SocketChannel channel = (SocketChannel)key.channel(); + REPSocketChannel<REPCommand> channel = (REPSocketChannel<REPCommand>)key.channel(); REPPacketReceive receive = new REPPacketReceive(channel); receive.setkey(key); REPCommand receivedCommand = receive.unpackUConv(); @@ -169,21 +165,10 @@ command.setCMD(REP.SMCMD_UPDATE); smList.sendExcept(channel, command); - -// if(isMaster){ -// command.setCMD(REP.SMCMD_UPDATE_ACK); -// smList.sendToSlave(command); -// }else{ -// command.setCMD(REP.SMCMD_UPDATE); -// smList.sendToMaster(command); -// } break; -// case REP.SMCMD_PUT_ACK: -// break; - + case REP.SMCMD_SELECT: -// sessionlist.addEditor(channel, repCmd.sid, repCmd); //sessionlistへ追加 editor = new Editor(channel); session = sessionlist.getSession(receivedCommand.sid); @@ -191,9 +176,6 @@ if(session.isOwner()){ int eid2 = session.addEditor(editor); editor.setEID(eid2); - //REPPacketSend send = new REPPacketSend(channel); - //receivedCommand.setCMD(REP.SMCMD_SELECT_ACK); - //receivedCommand.setEID(eid2); sendCommand.setCMD(REP.SMCMD_SELECT_ACK); sendCommand.setEID(eid2); send.send(sendCommand); @@ -399,41 +381,7 @@ return kindOfCmd; } - private String setUTF16(String string) { - //CharBuffer cb = CharBuffer.wrap(string); - Charset charset = Charset.forName("UTF-16"); - ByteBuffer buffer = ByteBuffer.allocateDirect(string.length() * 2); - //CharsetEncoder encoder = charset.newEncoder(); - try { - buffer = charset.encode(string); - } catch (IllegalStateException e) { - e.printStackTrace(); - } - buffer.rewind(); - String text = null; - for(int i=0;i<string.length();i++) { - text +=buffer.getChar(); - } - String string2 = text; - return string2; - } - private boolean setMaxHost(SocketChannel channel, String host) { - if(maxHost == null) { - maxHost = myHost; - sessionlist.setMaxHost(maxHost); - } - if(host.compareTo(maxHost) > 0){ - //host > MaxHost なら maxHost = host - //masterを設定する。 - maxHost = host; - sessionlist.setMaxHost(maxHost); - setMaster(false, channel); - return true; - }else{ - return false; - } - } private void setMyHostName(String localHostName) { myHost = localHostName + temp_port; @@ -523,42 +471,15 @@ return host; } -// private String getSocketString(SocketChannel sessionchannel) { -// SocketAddress socket = sessionchannel.socket().getRemoteSocketAddress(); -// //String inetAddressString = sessionchannel.socket().getInetAddress().toString(); -// StringTokenizer stn = new StringTokenizer(socket.toString(), "/"); -// String socketString = null; -// while(stn.hasMoreTokens()){ -// socketString = stn.nextToken(); -// //System.out.println(socketString); -// } -// return socketString; -// } - public void connectionOccured(ConnectionEvent event) { connectSession(event.getHost()); } public void ActionOccured(REPActionEvent event) { - /*** 元の ***/ -// SocketChannel editorChannel = event.getEditorChannel(); -// int sid = event.getSID(); -// Editor editor = new Editor(editorChannel); -// editor.setHost(this.myHost); -// Session session = sessionlist.getSession(sid); -// session.addEditor(editor); -// -// Editor owner = session.getMaster(); -// -// REPCommand command = new REPCommand(); -// command.setCMD(REP.SMCMD_SELECT); -// command.setSID(sid); -// command.setString(editor.getHost() + ":" + editor.getPort()); -// owner.send(command); /*** 書き直し ***/ - SocketChannel channel = event.getEditorChannel(); + REPSocketChannel channel = event.getEditorChannel(); int sid = event.getSID(); Session session = sessionlist.getSession(sid); if(session.isOwner()){ @@ -570,7 +491,7 @@ REPPacketSend sender = new REPPacketSend(channel); sender.send(sendCommand); }else { - SocketChannel editorChannel = event.getEditorChannel(); + REPSocketChannel editorChannel = event.getEditorChannel(); sid = event.getSID(); Editor editor = new Editor(editorChannel); editor.setHost(myHost); @@ -587,16 +508,9 @@ } - //REPPacketSend send = new REPPacketSend(editorChannel); - //send.send(new REPCommand(REP.SMCMD_SELECT_ACK, sid, eid, 0,0,0,"")); - - - - //sessionlist.sendSelect(sid); } public void undo() { - // TODO Auto-generated method stub ownEditorList.undoAllEditors(); System.out.println("Undo!"); }