# HG changeset patch # User kono # Date 1223944411 -32400 # Node ID edf0e0a5ffc830c68a53681e705cb2c2c8bd7126 # Parent a092a8fe9d97adaa26cef94c21e52604a091b9d5 *** empty log message *** diff -r a092a8fe9d97 -r edf0e0a5ffc8 rep/SessionManager.java --- a/rep/SessionManager.java Tue Oct 14 09:00:04 2008 +0900 +++ b/rep/SessionManager.java Tue Oct 14 09:33:31 2008 +0900 @@ -11,6 +11,8 @@ import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; +import org.xml.sax.SAXException; + import rep.channel.REPLogger; import rep.channel.REPServerSocketChannel; @@ -61,6 +63,7 @@ private int parent_port; static final int DEFAULT_PORT = 8766; private static final int packetLimit = 200; + private SessionXMLDecoder decoder = new SessionXMLDecoder(); public static void main(String[] args) throws InterruptedException, IOException { @@ -157,7 +160,7 @@ * @return true if there is a processed waiting command * @throws IOException */ - private void checkWaitingCommandInMerge() throws IOException { + private void checkWaitingCommandInMerge() { List w = waitingCommandInMerge; waitingCommandInMerge = new LinkedList(); for(PacketSet p: w) { @@ -165,11 +168,26 @@ if(e!=null &&e.isMerging()) { // still merging do nothing waitingCommandInMerge.add(p); } else { - manage(p.channel, p.command); + try { + manage(p.channel, p.command); + } catch (IOException e1) { + close(p.channel); + } catch (SAXException e1) { + close(p.channel); + } } } } + private void close(REPSocketChannel channel) { + REPSelectionKeykey = channel.keyFor1(selector); + REPHandler handler = (REPHandler)key.attachment(); + key.cancel(); + handler.cancel(channel); + // we have to remove session/enditor + } + + public boolean hasWaitingCommand(REPSocketChannelc) { for(PacketSet p:waitingCommandInMerge) { if (p.channel==c) { @@ -193,12 +211,9 @@ REPHandler handler = (REPHandler)(key.attachment()); try { handler.handle(key); - } catch (ClosedChannelException x) { + } catch (Exception x) { key.cancel(); handler.cancel(key.channel1()); - } catch (IOException x) { - key.cancel(); - handler.cancel( key.channel1()); } } } @@ -213,7 +228,7 @@ channel.register(selector, ops, handler); } - public void manage(REPSocketChannel channel, REPCommand receivedCommand) throws IOException { + public void manage(REPSocketChannel channel, REPCommand receivedCommand) throws IOException, SAXException { if (sessionManagerCommand(channel, receivedCommand)) return; Session s = getSession(receivedCommand.sid); Editor e = s.getEditor(channel); @@ -223,7 +238,7 @@ private boolean sessionManagerCommand(REPSocketChannel channel, REPCommand receivedCommand) throws ClosedChannelException, - IOException { + IOException, SAXException { switch(receivedCommand.cmd){ // Session Manager Command @@ -341,7 +356,6 @@ smList.add(channel); //XMLからSessionListオブジェクトを生成する。 - SessionXMLDecoder decoder = new SessionXMLDecoder(); SessionList receivedSessionList = decoder.decode(receivedCommand.string); //myHost を設定。 @@ -376,8 +390,7 @@ case SMCMD_SM_JOIN_ACK: //XMLからSessionListオブジェクトを生成。 - SessionXMLDecoder decoder2 = new SessionXMLDecoder(); - SessionList receivedSessionList2 = decoder2.decode(receivedCommand.string); + SessionList receivedSessionList2 = decoder.decode(receivedCommand.string); //maxHostを決定。 if(setMaxHost(channel, receivedSessionList2.getMaxHost())){ @@ -391,8 +404,7 @@ case SMCMD_UPDATE: { - SessionXMLDecoder decoder3 = new SessionXMLDecoder(); - SessionList receivedSessionList3 = decoder3.decode(receivedCommand.string); + SessionList receivedSessionList3 = decoder.decode(receivedCommand.string); //UPDATEコマンドにより送られてきたSessionの情報を追加する LinkedList list = receivedSessionList3.getList(); diff -r a092a8fe9d97 -r edf0e0a5ffc8 test/XMLTest.java --- a/test/XMLTest.java Tue Oct 14 09:00:04 2008 +0900 +++ b/test/XMLTest.java Tue Oct 14 09:33:31 2008 +0900 @@ -1,5 +1,9 @@ package test; +import java.io.IOException; + +import org.xml.sax.SAXException; + import rep.Editor; import rep.Session; import rep.SessionList; @@ -38,7 +42,12 @@ SessionXMLDecoder decoder = new SessionXMLDecoder(); String t1 = encoder.sessionListToXML(); System.out.println(t1); - SessionList sessionlist2 = decoder.decode(t1); + SessionList sessionlist2; + try { + sessionlist2 = decoder.decode(t1); + } catch (Exception e) { + return; + } /*** SessionList から XML へ ***/ //SessionXMLEncoder encoder2 = new SessionXMLEncoder(sessionlist2.getList());