Mercurial > hg > Members > riono > TreeVNC_ja_comment
changeset 328:1a2ab6bd5ba3
add function lost child node, remove deadChild nodeList.
author | oc |
---|---|
date | Mon, 02 Feb 2015 13:50:35 +0900 |
parents | 293c35aa902b |
children | 230038d5127d |
files | src/main/java/com/glavsoft/rfb/protocol/ProtocolContext.java src/main/java/jp/ac/u_ryukyu/treevnc/TreeManagement.java src/main/java/jp/ac/u_ryukyu/treevnc/TreeRFBProto.java src/main/java/jp/ac/u_ryukyu/treevnc/TreeVncCommand.java src/main/java/jp/ac/u_ryukyu/treevnc/TreeVncProtocol.java src/viewer_swing/java/com/glavsoft/viewer/CuiViewer.java src/viewer_swing/java/com/glavsoft/viewer/Viewer.java src/viewer_swing/java/com/glavsoft/viewer/ViewerInterface.java |
diffstat | 8 files changed, 100 insertions(+), 49 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/com/glavsoft/rfb/protocol/ProtocolContext.java Sun Feb 01 17:34:09 2015 +0900 +++ b/src/main/java/com/glavsoft/rfb/protocol/ProtocolContext.java Mon Feb 02 13:50:35 2015 +0900 @@ -97,7 +97,9 @@ LOST_PARENT (225), NOT_FOUND_PARENT (226), NEW_NODE (227), - QUIT_LOOP (228); + QUIT_LOOP (228), + LOST_LEFT_CHILD (229), + LOST_RIGHT_CHILD (230); public final int cmd; TreeCommand(int cmd) { @@ -106,16 +108,18 @@ public static TreeCommand create(int i) { switch (i) { - case 220: return FIND_ROOT ; - case 221: return FIND_ROOT_REPLY; - case 222: return WHERE_TO_CONNECT; - case 223: return CONNECT_TO ; - case 224: return CONNECT_TO_AS_LEADER ; - case 225: return LOST_PARENT ; - case 226: return NOT_FOUND_PARENT ; - case 227: return NEW_NODE ; - case 228: default: - return QUIT_LOOP; + case 220: return FIND_ROOT ; + case 221: return FIND_ROOT_REPLY; + case 222: return WHERE_TO_CONNECT; + case 223: return CONNECT_TO ; + case 224: return CONNECT_TO_AS_LEADER ; + case 225: return LOST_PARENT ; + case 226: return NOT_FOUND_PARENT ; + case 227: return NEW_NODE ; + case 228: return QUIT_LOOP; + case 229: return LOST_LEFT_CHILD; + case 230: default: + return LOST_RIGHT_CHILD; } } }
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/TreeManagement.java Sun Feb 01 17:34:09 2015 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/TreeManagement.java Mon Feb 02 13:50:35 2015 +0900 @@ -42,9 +42,11 @@ */ private void moveLastNodeToLostNodePosition(int nodeNum) { nodeList.remove(nodeNum); - TreeVNCNode node = nodeList.removeLast(); - node.setTreeNum(nodeNum); - nodeList.add(nodeNum, node) ; + if (nodeNum != nodeList.size()) { + TreeVNCNode node = nodeList.removeLast(); + node.setTreeNum(nodeNum); + nodeList.add(nodeNum, node); + } } private void checkParameter(int parent, int counter, int leaderflag2) { @@ -66,8 +68,7 @@ } else { return(nodeList.get(child)); } - - } + } /** * A parent is lost, move last node which has no child to the position @@ -77,7 +78,7 @@ */ public void fixLostParent(String hostname, int port, String myHostName) { TreeVNCNode lostParentNode = lookup(nodeList,hostname,port); - if (lostParentNode == null ) return; // some thing wrong + if (lostParentNode == null ) return; // something wrong int treeNumber = lostParentNode.getTreeNum(); TreeVNCNode deadParent = getParentNode(treeNumber); TreeVNCNode me = nodeList.getFirst(); @@ -99,6 +100,14 @@ // Thread.sleep(intv_time); } + public void fixLostChild(String hostname, int port, String myHostName, int clientId) { + TreeVNCNode lostChildNode = lookup(nodeList, hostname, port); + if (lostChildNode == null) return; + TreeVNCNode deadChild = getChildNode(lostChildNode, clientId); + moveLastNodeToLostNodePosition(deadChild.getTreeNum()); + lostNodeConnection(deadChild); + } + /** * send reconnect to all children * @param oldParent
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/TreeRFBProto.java Sun Feb 01 17:34:09 2015 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/TreeRFBProto.java Mon Feb 02 13:50:35 2015 +0900 @@ -144,10 +144,27 @@ // long, memory will overflow... } if (flag == 1) - System.out.println("Resuming " + myId - + " count=" + count); + System.out.println("Resuming " + myId + " count=" + count); if (state != 1) { System.out.println("Client died " + myId); + System.out.println("task stop"); + + TreeVncProtocol echo = null; + + if (isTreeManager) { + + + } else { + echo = new TreeVncProtocol(getConnectionParam().getHostName(), getConnectionParam().getPort()); + } + + if (echo!=null) { + if (myId == 0) { + echo.lostLeftChild(getMyAddress(), getAcceptPort()); + } else if (myId == 1) { + echo.lostRightChild(getMyAddress(), getAcceptPort()); + } + } break; } }
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/TreeVncCommand.java Sun Feb 01 17:34:09 2015 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/TreeVncCommand.java Mon Feb 02 13:50:35 2015 +0900 @@ -43,34 +43,41 @@ public void handleTreeVncCommand() { switch (command) { - case FIND_ROOT_REPLY : - handleFindRootReply(port,hostname,myHostName); - break; - case CONNECT_TO_AS_LEADER : - handleConnectTo( port,hostname,myHostName,true,this.value); - break; - case CONNECT_TO : - handleConnectTo( port,hostname,myHostName,false,this.value); - break; - case FIND_ROOT : - // this is a multicast message, it is handled in FindRootListener - break; - case WHERE_TO_CONNECT : - handleWhereToConnect(port,hostname, myHostName); - break; - case LOST_PARENT : - handleLostParent(port,hostname, myHostName); - break; - case NEW_NODE : - rfb.newClient(connection, os, is); - break; - case QUIT_LOOP: - break; - default: - System.out.println("unknown treeVNC command" + command); + case FIND_ROOT_REPLY : + handleFindRootReply(port,hostname,myHostName); + break; + case CONNECT_TO_AS_LEADER : + handleConnectTo(port,hostname,myHostName,true,this.value); + break; + case CONNECT_TO : + handleConnectTo(port,hostname,myHostName,false,this.value); + break; + case FIND_ROOT : + // this is a multicast message, it is handled in FindRootListener + break; + case WHERE_TO_CONNECT : + handleWhereToConnect(port,hostname, myHostName); + break; + case LOST_PARENT : + handleLostParent(port,hostname, myHostName); + break; + case NEW_NODE : + rfb.newClient(connection, os, is); + break; + case QUIT_LOOP : + break; + case LOST_LEFT_CHILD : + handleLostChild(port, hostname, myHostName, 0); + break; + case LOST_RIGHT_CHILD : + handleLostChild(port, hostname, myHostName, 1); + break; + default: + System.out.println("unknown treeVNC command" + command); } } + /** * new clients ask root to where to connect * tell him his parent @@ -128,6 +135,11 @@ rfb.getTreeManager(intf).fixLostParent(hostname,port,myHostName); } + private void handleLostChild(int port, String hostname, String myHostName, int clientId) { + rfb.getTreeManager(intf).fixLostChild(hostname, port, myHostName, clientId); + } + + public TreeCommand getCommand () { return command; }
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/TreeVncProtocol.java Sun Feb 01 17:34:09 2015 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/TreeVncProtocol.java Mon Feb 02 13:50:35 2015 +0900 @@ -50,6 +50,14 @@ sendWithHostAndPort(TreeCommand.LOST_PARENT, hostname, port, (short) 0); } + public void lostLeftChild(String hostname, int port) { + sendWithHostAndPort(TreeCommand.LOST_LEFT_CHILD, hostname, port, (short) 0); + } + + public void lostRightChild(String hostname, int port) { + sendWithHostAndPort(TreeCommand.LOST_RIGHT_CHILD, hostname, port, (short) 0); + } + public void sendWithHostAndPort(TreeCommand command, String hostname, int port, short value) { try { openport(); @@ -94,4 +102,5 @@ } } + } \ No newline at end of file
--- a/src/viewer_swing/java/com/glavsoft/viewer/CuiViewer.java Sun Feb 01 17:34:09 2015 +0900 +++ b/src/viewer_swing/java/com/glavsoft/viewer/CuiViewer.java Mon Feb 02 13:50:35 2015 +0900 @@ -205,7 +205,7 @@ public void setOpenPort(int parseInt) { } - public void setTeminationType(boolean b) { + public void setTerminationType(boolean b) { myRfb.setTerminationType(b); } @@ -243,7 +243,7 @@ @Override public void connectToParenet(int port, String hostname) throws IOException { - setTeminationType(false); + setTerminationType(false); closeApp(); connectionParams.setConnectionParam(hostname, port); run();
--- a/src/viewer_swing/java/com/glavsoft/viewer/Viewer.java Sun Feb 01 17:34:09 2015 +0900 +++ b/src/viewer_swing/java/com/glavsoft/viewer/Viewer.java Mon Feb 02 13:50:35 2015 +0900 @@ -286,7 +286,7 @@ public void setOpenPort(int parseInt) { } - public void setTeminationType(boolean b) { + public void setTerminationType(boolean b) { myRfb.setTerminationType(b); } @@ -320,7 +320,7 @@ */ @Override public void connectToParenet(int port, String hostname) throws IOException { - setTeminationType(false); + setTerminationType(false); closeApp(); connectionParams.setConnectionParam(hostname, port); run();
--- a/src/viewer_swing/java/com/glavsoft/viewer/ViewerInterface.java Sun Feb 01 17:34:09 2015 +0900 +++ b/src/viewer_swing/java/com/glavsoft/viewer/ViewerInterface.java Mon Feb 02 13:50:35 2015 +0900 @@ -21,7 +21,7 @@ public void setOpenPort(int parseInt); - public void setTeminationType(boolean b); + public void setTerminationType(boolean b); public void setCuiVersion(boolean flag);