Mercurial > hg > Members > riono > TreeVNC_ja_comment
changeset 173:70068c2642de
fix lostParent.
author | oc |
---|---|
date | Sat, 21 Jun 2014 17:28:59 +0900 |
parents | 73c42f9d04a8 |
children | 2e1530139169 |
files | src/main/java/jp/ac/u_ryukyu/treevnc/server/TreeManagement.java src/main/java/jp/ac/u_ryukyu/treevnc/server/VncProxyService.java |
diffstat | 2 files changed, 43 insertions(+), 30 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/server/TreeManagement.java Fri Jun 20 20:19:36 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/server/TreeManagement.java Sat Jun 21 17:28:59 2014 +0900 @@ -58,6 +58,17 @@ return nodeList.get(parentnum); } + + public TreeVNCNode getChildNode(TreeVNCNode newparent, int i) { + int child = newparent.getTreeNum() * treebranch + i + 1; + if (child >= nodeList.size()) { + return(null); + } else { + return(nodeList.get(child)); + } + + } + /** * A parent is lost, move last node which has no child to the position * @param hostname @@ -68,6 +79,12 @@ if (lostParentNode == null ) return; // some thing wrong int treeNumber = lostParentNode.getTreeNum(); TreeVNCNode deadParent = getParentNode(treeNumber); + if (deadParent.getTreeNum() == 0) { + // if dead root, connect me. + connectTo(nodeList.getFirst(), lostParentNode); + return; + } + if (getChildNode(deadParent, 0) == null) return; moveLastNodeToLostNodePosition(deadParent.getTreeNum()); lostNodeConnection(deadParent); // if lostParentNode is the last one, we don't need reconnection @@ -82,28 +99,28 @@ 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 - } + connectTo(grandfather, newparent); - for(int i=1; i < treebranch; i++ ) { - if (newparent.getTreeNum() + i <=nodeList.size() ) { - TreeVNCNode n = nodeList.get(newparent.getTreeNum()+i) ; - TreeVncProtocol vc1 = new TreeVncProtocol(n.getHostname(),n.getPort()); - try { - short nodeId = (short) n.getTreeNum(); - vc1.connectTo(newparent.getHostname(), newparent.getPort(), isLeader(n), nodeId); - } catch (IOException e) { - // log - } + for(int i=0; i < treebranch; i++) { + TreeVNCNode child = getChildNode(newparent, i); + if (child != null) { + connectTo(newparent, child); } } } + + + public void connectTo(TreeVNCNode newparent, TreeVNCNode n) { + TreeVncProtocol vc1 = new TreeVncProtocol(n.getHostname(),n.getPort()); + try { + short nodeId = (short) n.getTreeNum(); + vc1.connectTo(newparent.getHostname(), newparent.getPort(), isLeader(n), nodeId); + } catch (IOException e) { + // log + } + } + private int isLeader(TreeVNCNode n) { return ( n.getTreeNum() % treebranch == 1) ? 1 : 0; } @@ -126,19 +143,14 @@ node.setTreeNum(nodeList.size()); nodeList.add(node); showTreeNode(); - TreeVncProtocol treeProtocol = new TreeVncProtocol(hostname,port); - try { - if (nodeList.size() >= treebranch + 1) { - TreeVNCNode parent = getParentNode(node.getTreeNum()); - checkParameter(parent.getTreeNum(), nodeList.size(), isLeader(node)); - treeProtocol.connectTo(parent.getHostname(),parent.getPort(),isLeader(node), (short) node.getTreeNum()); - } else { - // connect to me - treeProtocol.connectTo(localhostname,rfb.getAcceptPort(),isLeader(node), (short) node.getTreeNum()); - } - } catch (IOException e) { - // log - } + if (nodeList.size() >= treebranch + 1) { + TreeVNCNode parent = getParentNode(node.getTreeNum()); + checkParameter(parent.getTreeNum(), nodeList.size(), isLeader(node)); + connectTo(parent, node); + } else { + // connect to me + connectTo(nodeList.getFirst(), node); + } } /**
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/server/VncProxyService.java Fri Jun 20 20:19:36 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/server/VncProxyService.java Sat Jun 21 17:28:59 2014 +0900 @@ -200,6 +200,7 @@ public void fixLostParent(String hostname, int port) { clients.fixLostParent(hostname,port); + clients.showTreeNode(); } public TreeVncCommandChannelListener getAcceptThread() {