Mercurial > hg > Applications > TreeVNC
annotate src/main/java/jp/ac/u_ryukyu/treevnc/TreeManagement.java @ 470:f7210f834403
add unique node id
author | mir3636 |
---|---|
date | Wed, 03 Aug 2016 19:09:11 +0900 |
parents | a817fa255673 |
children | 89f1f7e41838 |
rev | line source |
---|---|
206 | 1 package jp.ac.u_ryukyu.treevnc; |
11 | 2 |
153 | 3 |
4 import java.io.IOException; | |
208 | 5 import java.net.InetAddress; |
337
c455b05f163b
in decideWhereToConnect, host on a different network isn't add to nodeList.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
334
diff
changeset
|
6 import java.net.UnknownHostException; |
153 | 7 import java.util.LinkedList; |
11 | 8 |
153 | 9 public class TreeManagement { |
188 | 10 |
462 | 11 |
12 private final int treeId; | |
231 | 13 public LinkedList<TreeVNCNode> nodeList = new LinkedList<TreeVNCNode>(); |
463 | 14 public LinkedList<NetworkAddress> treeAddresses = new LinkedList<NetworkAddress>(); |
223 | 15 private final int treebranch = 2; |
16 private boolean showTreeNode = false; | |
462 | 17 // node id |
18 // ttttnnnnnnnnnnnn | |
19 // tttt 4bit tree number | |
20 // nnnnnnnnnnnn 12bit node number | |
21 public final int MAX_TREE = 15; | |
22 public final int MAX_TREE_NODE = (1<<12)-1; | |
188 | 23 |
462 | 24 public TreeManagement(String hostName, int vncport, boolean showTree, int id) { |
25 treeId = id; | |
223 | 26 TreeVNCNode me = new TreeVNCNode(hostName, vncport,"localhost"); |
27 showTreeNode = showTree; | |
28 me.setTreeNum(0); | |
29 nodeList.add(me); | |
30 } | |
31 | |
463 | 32 private class NetworkAddress { |
33 InetAddress inetaddress; | |
34 byte [] address; | |
35 byte [] netmask; | |
36 | |
37 public NetworkAddress(InetAddress ipaddress, byte[] netaddress, byte[] netmask) { | |
38 inetaddress = ipaddress; | |
39 address = netaddress; | |
40 this.netmask = netmask; | |
41 } | |
42 } | |
43 | |
462 | 44 public int getTreeId() { |
45 return treeId; | |
46 } | |
138 | 47 |
223 | 48 /** |
49 * a parent is lost, remove from the list and move last one into here | |
50 * @param nodeNum | |
51 * parent value | |
52 */ | |
418
0543c380308c
Move bottleneck Node to outside node list
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
342
diff
changeset
|
53 public void moveLastNodeToLostNodePosition(int nodeNum) { |
223 | 54 nodeList.remove(nodeNum); |
328
1a2ab6bd5ba3
add function lost child node, remove deadChild nodeList.
oc
parents:
251
diff
changeset
|
55 if (nodeNum != nodeList.size()) { |
1a2ab6bd5ba3
add function lost child node, remove deadChild nodeList.
oc
parents:
251
diff
changeset
|
56 TreeVNCNode node = nodeList.removeLast(); |
1a2ab6bd5ba3
add function lost child node, remove deadChild nodeList.
oc
parents:
251
diff
changeset
|
57 node.setTreeNum(nodeNum); |
1a2ab6bd5ba3
add function lost child node, remove deadChild nodeList.
oc
parents:
251
diff
changeset
|
58 nodeList.add(nodeNum, node); |
1a2ab6bd5ba3
add function lost child node, remove deadChild nodeList.
oc
parents:
251
diff
changeset
|
59 } |
223 | 60 } |
11 | 61 |
223 | 62 private void checkParameter(int parent, int counter, int leaderflag2) { |
63 System.out.print("number p =" + parent); | |
64 System.out.print(" number i =" + counter); | |
65 System.out.println(" leaderflag=" + leaderflag2 + "\n"); | |
66 } | |
11 | 67 |
223 | 68 private TreeVNCNode getParentNode(int nodeNum) { |
69 int parentnum = (nodeNum - 1) / treebranch; | |
135
ada4d850a820
lostParent and notFoundParenet
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
134
diff
changeset
|
70 return nodeList.get(parentnum); |
223 | 71 } |
72 | |
73 | |
74 public TreeVNCNode getChildNode(TreeVNCNode newparent, int i) { | |
75 int child = newparent.getTreeNum() * treebranch + i + 1; | |
76 if (child >= nodeList.size()) { | |
77 return(null); | |
78 } else { | |
79 return(nodeList.get(child)); | |
80 } | |
328
1a2ab6bd5ba3
add function lost child node, remove deadChild nodeList.
oc
parents:
251
diff
changeset
|
81 } |
223 | 82 |
83 /** | |
84 * A parent is lost, move last node which has no child to the position | |
85 * @param hostname | |
86 * @param port | |
87 * @param myHostName | |
88 */ | |
195 | 89 public void fixLostParent(String hostname, int port, String myHostName) { |
136 | 90 TreeVNCNode lostParentNode = lookup(nodeList,hostname,port); |
328
1a2ab6bd5ba3
add function lost child node, remove deadChild nodeList.
oc
parents:
251
diff
changeset
|
91 if (lostParentNode == null ) return; // something wrong |
136 | 92 int treeNumber = lostParentNode.getTreeNum(); |
172 | 93 TreeVNCNode deadParent = getParentNode(treeNumber); |
223 | 94 TreeVNCNode me = nodeList.getFirst(); |
95 me.setHostName(myHostName); | |
173 | 96 if (deadParent.getTreeNum() == 0) { |
223 | 97 // if dead root, connect me. |
337
c455b05f163b
in decideWhereToConnect, host on a different network isn't add to nodeList.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
334
diff
changeset
|
98 try { |
c455b05f163b
in decideWhereToConnect, host on a different network isn't add to nodeList.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
334
diff
changeset
|
99 connectTo(me, lostParentNode); |
c455b05f163b
in decideWhereToConnect, host on a different network isn't add to nodeList.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
334
diff
changeset
|
100 } catch (IOException e) { |
c455b05f163b
in decideWhereToConnect, host on a different network isn't add to nodeList.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
334
diff
changeset
|
101 e.printStackTrace(); |
c455b05f163b
in decideWhereToConnect, host on a different network isn't add to nodeList.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
334
diff
changeset
|
102 } |
223 | 103 return; |
173 | 104 } |
105 if (getChildNode(deadParent, 0) == null) return; | |
172 | 106 moveLastNodeToLostNodePosition(deadParent.getTreeNum()); |
107 lostNodeConnection(deadParent); | |
136 | 108 // if lostParentNode is the last one, we don't need reconnection |
109 // Thread.sleep(intv_time); | |
110 } | |
54 | 111 |
328
1a2ab6bd5ba3
add function lost child node, remove deadChild nodeList.
oc
parents:
251
diff
changeset
|
112 public void fixLostChild(String hostname, int port, String myHostName, int clientId) { |
1a2ab6bd5ba3
add function lost child node, remove deadChild nodeList.
oc
parents:
251
diff
changeset
|
113 TreeVNCNode lostChildNode = lookup(nodeList, hostname, port); |
1a2ab6bd5ba3
add function lost child node, remove deadChild nodeList.
oc
parents:
251
diff
changeset
|
114 if (lostChildNode == null) return; |
334 | 115 int lostChildNodeNum; |
116 // if isTreeManager | |
117 if (lostChildNode.getTreeNum() == 0) { | |
118 lostChildNodeNum = clientId + 1; | |
119 } else { | |
120 lostChildNodeNum = (lostChildNode.getTreeNum() * treebranch) + clientId + 1; | |
121 } | |
122 TreeVNCNode deadChild; | |
423
ffe01c959cdd
Fix LostChild for root node
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
418
diff
changeset
|
123 fixLostChild1(lostChildNodeNum); |
136 | 124 } |
54 | 125 |
427
ed15f0bd8dfa
Remove shareScrrenNumber for ScreenChangeRequest Message
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
423
diff
changeset
|
126 public void fixLostChild1(int nodeNum) { |
ed15f0bd8dfa
Remove shareScrrenNumber for ScreenChangeRequest Message
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
423
diff
changeset
|
127 TreeVNCNode deadNode; |
ed15f0bd8dfa
Remove shareScrrenNumber for ScreenChangeRequest Message
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
423
diff
changeset
|
128 try { |
ed15f0bd8dfa
Remove shareScrrenNumber for ScreenChangeRequest Message
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
423
diff
changeset
|
129 deadNode = nodeList.get(nodeNum); |
ed15f0bd8dfa
Remove shareScrrenNumber for ScreenChangeRequest Message
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
423
diff
changeset
|
130 } catch (IndexOutOfBoundsException e) { |
ed15f0bd8dfa
Remove shareScrrenNumber for ScreenChangeRequest Message
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
423
diff
changeset
|
131 // this node became new node instead of deathChild. |
ed15f0bd8dfa
Remove shareScrrenNumber for ScreenChangeRequest Message
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
423
diff
changeset
|
132 deadNode = null; |
ed15f0bd8dfa
Remove shareScrrenNumber for ScreenChangeRequest Message
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
423
diff
changeset
|
133 } |
ed15f0bd8dfa
Remove shareScrrenNumber for ScreenChangeRequest Message
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
423
diff
changeset
|
134 if (deadNode != null) { |
ed15f0bd8dfa
Remove shareScrrenNumber for ScreenChangeRequest Message
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
423
diff
changeset
|
135 moveLastNodeToLostNodePosition(deadNode.getTreeNum()); |
ed15f0bd8dfa
Remove shareScrrenNumber for ScreenChangeRequest Message
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
423
diff
changeset
|
136 lostNodeConnection(deadNode); |
ed15f0bd8dfa
Remove shareScrrenNumber for ScreenChangeRequest Message
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
423
diff
changeset
|
137 } |
ed15f0bd8dfa
Remove shareScrrenNumber for ScreenChangeRequest Message
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
423
diff
changeset
|
138 if (showTreeNode) { |
ed15f0bd8dfa
Remove shareScrrenNumber for ScreenChangeRequest Message
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
423
diff
changeset
|
139 showTreeNode(); |
ed15f0bd8dfa
Remove shareScrrenNumber for ScreenChangeRequest Message
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
423
diff
changeset
|
140 } |
ed15f0bd8dfa
Remove shareScrrenNumber for ScreenChangeRequest Message
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
423
diff
changeset
|
141 } |
ed15f0bd8dfa
Remove shareScrrenNumber for ScreenChangeRequest Message
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
423
diff
changeset
|
142 |
331
42fcc9419498
add error message, add lostParent case by fail to connectTo.
oc
parents:
329
diff
changeset
|
143 /** |
42fcc9419498
add error message, add lostParent case by fail to connectTo.
oc
parents:
329
diff
changeset
|
144 * send reconnect to all children |
42fcc9419498
add error message, add lostParent case by fail to connectTo.
oc
parents:
329
diff
changeset
|
145 * @param deadNode |
42fcc9419498
add error message, add lostParent case by fail to connectTo.
oc
parents:
329
diff
changeset
|
146 */ |
418
0543c380308c
Move bottleneck Node to outside node list
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
342
diff
changeset
|
147 public void lostNodeConnection(TreeVNCNode deadNode) { |
331
42fcc9419498
add error message, add lostParent case by fail to connectTo.
oc
parents:
329
diff
changeset
|
148 if (nodeList.size() < deadNode.getTreeNum()+1) { |
42fcc9419498
add error message, add lostParent case by fail to connectTo.
oc
parents:
329
diff
changeset
|
149 return; |
42fcc9419498
add error message, add lostParent case by fail to connectTo.
oc
parents:
329
diff
changeset
|
150 } |
333 | 151 TreeVNCNode newNode = nodeList.get(deadNode.getTreeNum()); |
152 TreeVNCNode parentNode = getParentNode(newNode.getTreeNum()); | |
153 // new node connect to parent node. | |
337
c455b05f163b
in decideWhereToConnect, host on a different network isn't add to nodeList.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
334
diff
changeset
|
154 try { |
c455b05f163b
in decideWhereToConnect, host on a different network isn't add to nodeList.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
334
diff
changeset
|
155 connectTo(parentNode, newNode); |
c455b05f163b
in decideWhereToConnect, host on a different network isn't add to nodeList.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
334
diff
changeset
|
156 } catch (IOException e) { |
c455b05f163b
in decideWhereToConnect, host on a different network isn't add to nodeList.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
334
diff
changeset
|
157 e.printStackTrace(); |
c455b05f163b
in decideWhereToConnect, host on a different network isn't add to nodeList.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
334
diff
changeset
|
158 } |
333 | 159 // if children node exist, children connect to new node. |
331
42fcc9419498
add error message, add lostParent case by fail to connectTo.
oc
parents:
329
diff
changeset
|
160 for(int i=0; i < treebranch; i++) { |
333 | 161 TreeVNCNode child = getChildNode(newNode, i); |
331
42fcc9419498
add error message, add lostParent case by fail to connectTo.
oc
parents:
329
diff
changeset
|
162 if (child != null) { |
337
c455b05f163b
in decideWhereToConnect, host on a different network isn't add to nodeList.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
334
diff
changeset
|
163 try { |
c455b05f163b
in decideWhereToConnect, host on a different network isn't add to nodeList.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
334
diff
changeset
|
164 connectTo(newNode, child); |
c455b05f163b
in decideWhereToConnect, host on a different network isn't add to nodeList.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
334
diff
changeset
|
165 } catch (IOException e) { |
c455b05f163b
in decideWhereToConnect, host on a different network isn't add to nodeList.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
334
diff
changeset
|
166 e.printStackTrace(); |
c455b05f163b
in decideWhereToConnect, host on a different network isn't add to nodeList.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
334
diff
changeset
|
167 } |
331
42fcc9419498
add error message, add lostParent case by fail to connectTo.
oc
parents:
329
diff
changeset
|
168 } |
42fcc9419498
add error message, add lostParent case by fail to connectTo.
oc
parents:
329
diff
changeset
|
169 } |
42fcc9419498
add error message, add lostParent case by fail to connectTo.
oc
parents:
329
diff
changeset
|
170 } |
173 | 171 |
337
c455b05f163b
in decideWhereToConnect, host on a different network isn't add to nodeList.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
334
diff
changeset
|
172 public void connectTo(TreeVNCNode newparent, TreeVNCNode n) throws IOException { |
223 | 173 TreeVncProtocol vc1 = new TreeVncProtocol(n.getHostname(),n.getPort()); |
470 | 174 short nodeId = (short) n.getId(); |
223 | 175 vc1.connectTo(newparent.getHostname(), newparent.getPort(), isLeader(n), nodeId); |
176 } | |
173 | 177 |
136 | 178 private int isLeader(TreeVNCNode n) { |
179 return ( n.getTreeNum() % treebranch == 1) ? 1 : 0; | |
180 } | |
181 | |
182 private TreeVNCNode lookup(LinkedList<TreeVNCNode> list, String hostname, int port) { | |
223 | 183 for (TreeVNCNode r : list) { |
184 if (r.getHostname().equals(hostname) && r.getPort() == port ) | |
185 return r; | |
186 } | |
187 return null; | |
136 | 188 } |
135
ada4d850a820
lostParent and notFoundParenet
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
134
diff
changeset
|
189 |
223 | 190 /** |
191 * Determine tree topology and send CONNECT_TO command | |
192 * @param hostname | |
193 * @param port | |
470 | 194 * @param id |
223 | 195 */ |
470 | 196 public void decideWhereToConnect(String hostname, int port, String localhostname, int id) { |
423
ffe01c959cdd
Fix LostChild for root node
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents:
418
diff
changeset
|
197 TreeVNCNode node = new TreeVNCNode(hostname, port, localhostname); |
136 | 198 node.setTreeNum(nodeList.size()); |
470 | 199 node.setId(id); |
337
c455b05f163b
in decideWhereToConnect, host on a different network isn't add to nodeList.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
334
diff
changeset
|
200 |
c455b05f163b
in decideWhereToConnect, host on a different network isn't add to nodeList.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
334
diff
changeset
|
201 InetAddress ipAddress = null; |
c455b05f163b
in decideWhereToConnect, host on a different network isn't add to nodeList.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
334
diff
changeset
|
202 try { |
c455b05f163b
in decideWhereToConnect, host on a different network isn't add to nodeList.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
334
diff
changeset
|
203 ipAddress = InetAddress.getByName(hostname); |
c455b05f163b
in decideWhereToConnect, host on a different network isn't add to nodeList.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
334
diff
changeset
|
204 } catch (UnknownHostException e) { |
c455b05f163b
in decideWhereToConnect, host on a different network isn't add to nodeList.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
334
diff
changeset
|
205 System.out.println("root : whereToConnect : cannot get ipAddress" + hostname); |
c455b05f163b
in decideWhereToConnect, host on a different network isn't add to nodeList.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
334
diff
changeset
|
206 return; |
c455b05f163b
in decideWhereToConnect, host on a different network isn't add to nodeList.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
334
diff
changeset
|
207 } |
c455b05f163b
in decideWhereToConnect, host on a different network isn't add to nodeList.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
334
diff
changeset
|
208 if (onTheSameNetwork(ipAddress)) |
c455b05f163b
in decideWhereToConnect, host on a different network isn't add to nodeList.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
334
diff
changeset
|
209 nodeList.add(node); |
223 | 210 if (nodeList.size() >= treebranch + 1) { |
211 TreeVNCNode parent = getParentNode(node.getTreeNum()); | |
212 checkParameter(parent.getTreeNum(), nodeList.size(), isLeader(node)); | |
337
c455b05f163b
in decideWhereToConnect, host on a different network isn't add to nodeList.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
334
diff
changeset
|
213 try { |
c455b05f163b
in decideWhereToConnect, host on a different network isn't add to nodeList.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
334
diff
changeset
|
214 connectTo(parent, node); |
c455b05f163b
in decideWhereToConnect, host on a different network isn't add to nodeList.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
334
diff
changeset
|
215 } catch (IOException e) { |
c455b05f163b
in decideWhereToConnect, host on a different network isn't add to nodeList.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
334
diff
changeset
|
216 nodeList.remove(node); |
c455b05f163b
in decideWhereToConnect, host on a different network isn't add to nodeList.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
334
diff
changeset
|
217 System.out.println("root : whereToConnect : Connection Faild" + hostname); |
c455b05f163b
in decideWhereToConnect, host on a different network isn't add to nodeList.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
334
diff
changeset
|
218 return; |
c455b05f163b
in decideWhereToConnect, host on a different network isn't add to nodeList.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
334
diff
changeset
|
219 } |
223 | 220 } else { |
337
c455b05f163b
in decideWhereToConnect, host on a different network isn't add to nodeList.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
334
diff
changeset
|
221 // connect to me |
223 | 222 TreeVNCNode me = nodeList.getFirst(); |
223 me.setHostName(localhostname); | |
337
c455b05f163b
in decideWhereToConnect, host on a different network isn't add to nodeList.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
334
diff
changeset
|
224 try { |
c455b05f163b
in decideWhereToConnect, host on a different network isn't add to nodeList.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
334
diff
changeset
|
225 connectTo(me, node); |
c455b05f163b
in decideWhereToConnect, host on a different network isn't add to nodeList.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
334
diff
changeset
|
226 } catch (IOException e) { |
c455b05f163b
in decideWhereToConnect, host on a different network isn't add to nodeList.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
334
diff
changeset
|
227 nodeList.remove(node); |
c455b05f163b
in decideWhereToConnect, host on a different network isn't add to nodeList.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
334
diff
changeset
|
228 System.out.println("root : whereToConnect : Connection Faild" + hostname); |
c455b05f163b
in decideWhereToConnect, host on a different network isn't add to nodeList.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
334
diff
changeset
|
229 return; |
c455b05f163b
in decideWhereToConnect, host on a different network isn't add to nodeList.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
334
diff
changeset
|
230 } |
223 | 231 } |
232 if (showTreeNode) { | |
233 showTreeNode(); | |
234 } | |
235 } | |
236 | |
237 /** | |
238 * show Tree Node. | |
239 */ | |
240 public void showTreeNode() { | |
241 int nl = 0, pow = 2; | |
163 | 242 for (int i=0; i<nodeList.size(); i++) { |
223 | 243 TreeVNCNode treeNode = nodeList.get(i); |
244 System.out.print(treeNode.getTreeNum() + ":" + treeNode.getPort() + ":" + treeNode.getHostname()); | |
245 if (i==nl) { | |
246 System.out.println(); | |
247 nl = nl + pow; | |
248 pow = pow * pow; | |
249 } else { | |
250 System.out.print(" "); | |
251 } | |
172 | 252 |
163 | 253 } |
188 | 254 System.out.println(); |
223 | 255 } |
11 | 256 |
223 | 257 public LinkedList<TreeVNCNode> getList() { |
258 return nodeList; | |
259 } | |
54 | 260 |
223 | 261 public void setList(LinkedList<TreeVNCNode> _ls) { |
262 nodeList = _ls; | |
263 } | |
54 | 264 |
223 | 265 public int getTreeBranch() { |
266 return treebranch; | |
267 } | |
136 | 268 |
463 | 269 public void setNetMask(byte[] netmask, byte[] netaddress, InetAddress ipaddress) { |
270 treeAddresses.add(new NetworkAddress(ipaddress,netaddress,netmask) ); | |
223 | 271 } |
272 | |
342 | 273 public boolean onTheSameNetwork(InetAddress adr) { |
223 | 274 byte [] byteadr = adr.getAddress(); |
463 | 275 for (NetworkAddress n : treeAddresses) { |
276 byte [] netmask = n.netmask; | |
277 byte [] netaddress = n.address; | |
278 if (byteadr.length != netmask.length) continue; | |
464 | 279 int i; |
280 for (i = 0; i < netmask.length; i++) { | |
281 if ((netmask[i] & byteadr[i]) != netaddress[i]) break; | |
463 | 282 } |
464 | 283 if (i < netmask.length) continue; |
463 | 284 return true; |
223 | 285 } |
463 | 286 return false; |
223 | 287 } |
54 | 288 } |