Mercurial > hg > Members > riono > TreeVNC_ja_comment
changeset 172:73c42f9d04a8
fix send connectTo command when lostNodeConnection.
author | oc |
---|---|
date | Fri, 20 Jun 2014 20:19:36 +0900 |
parents | fab76dd9c3cd |
children | 70068c2642de |
files | src/main/java/jp/ac/u_ryukyu/treevnc/client/TreeVncProtocol.java src/main/java/jp/ac/u_ryukyu/treevnc/server/TreeManagement.java |
diffstat | 2 files changed, 29 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/client/TreeVncProtocol.java Fri Jun 20 18:29:50 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/client/TreeVncProtocol.java Fri Jun 20 20:19:36 2014 +0900 @@ -130,7 +130,7 @@ throws IOException { this.leaderFlag = leader; this.myAddress = myHostName; - client.setTeminationType(true); + client.setTeminationType(false); client.closeApp(); client.setConnectionParam(hostname, port); client.run();
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/server/TreeManagement.java Fri Jun 20 18:29:50 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/server/TreeManagement.java Fri Jun 20 20:19:36 2014 +0900 @@ -67,10 +67,9 @@ TreeVNCNode lostParentNode = lookup(nodeList,hostname,port); if (lostParentNode == null ) return; // some thing wrong int treeNumber = lostParentNode.getTreeNum(); - TreeVNCNode newparent = getParentNode(treeNumber); - moveLastNodeToLostNodePosition(treeNumber); - if(nodeList.size() > treeNumber +1) - lostNodeConnection(newparent); + TreeVNCNode deadParent = getParentNode(treeNumber); + moveLastNodeToLostNodePosition(deadParent.getTreeNum()); + lostNodeConnection(deadParent); // if lostParentNode is the last one, we don't need reconnection // Thread.sleep(intv_time); } @@ -79,14 +78,25 @@ * send reconnect to all children * @param newparent */ - private void lostNodeConnection(TreeVNCNode newparent) { + private void lostNodeConnection(TreeVNCNode oldParent) { + TreeVNCNode newparent = nodeList.get(oldParent.getTreeNum()); + TreeVNCNode grandfather = getParentNode(newparent.getTreeNum()); + + TreeVncProtocol vc = new TreeVncProtocol(newparent.getHostname(),newparent.getPort()); + try { + short nodeId = (short) newparent.getTreeNum(); + vc.connectTo(grandfather.getHostname(), grandfather.getPort(), isLeader(newparent), nodeId); + } catch (IOException e) { + // log + } + for(int i=1; i < treebranch; i++ ) { if (newparent.getTreeNum() + i <=nodeList.size() ) { TreeVNCNode n = nodeList.get(newparent.getTreeNum()+i) ; - TreeVncProtocol vc = new TreeVncProtocol(n.getHostname(),n.getPort()); + TreeVncProtocol vc1 = new TreeVncProtocol(n.getHostname(),n.getPort()); try { short nodeId = (short) n.getTreeNum(); - vc.connectTo(newparent.getHostname(), newparent.getPort(), isLeader(newparent), nodeId); + vc1.connectTo(newparent.getHostname(), newparent.getPort(), isLeader(n), nodeId); } catch (IOException e) { // log } @@ -135,9 +145,18 @@ * show Tree Node. */ public void showTreeNode() { + int nl = 0, pow = 2; for (int i=0; i<nodeList.size(); i++) { - TreeVNCNode treeNode = nodeList.get(i); - System.out.println(treeNode.getTreeNum() + ":" + treeNode.getPort() + ":" + treeNode.getHostname()); + TreeVNCNode treeNode = nodeList.get(i); + System.out.print(treeNode.getTreeNum() + ":" + treeNode.getPort() + ":" + treeNode.getHostname()); + if (i==nl) { + System.out.println(); + nl = nl + pow; + pow = pow * pow; + } else { + System.out.print(" "); + } + } }