Follower网元
Follower是一种特殊的节点类型,Follower对象可以有一个节点,并可以像主节点的一部分一样跟随主节点移动,同时Follower对象可以单独移动。尽管如此两个Follower对象可以设置为会为主节点,这种情况下两个Follower就像一个对象一块移动。
实际情况可能会更复杂,可以创建主节点队列、环、树,下面的代码将说明这几种情况:
Follower node1 = new Follower();
node1.setLocation(100, 50);
box.addElement(node1);
Follower node2 = new Follower();
node2.setLocation(300, 50);
box.addElement(node2);
node2.setHost(node1);
node1.setHost(node2);
其显示如下:
这两个网元的关系是户为主节点(关系如下所示):
主节点对
Follower center = new Follower();
center.setLocation(200, 200);
box.addElement(center);
int count = 10;
for (int i = 0; i < count; i++) {
Follower node = new Follower();
int x = center.getLocation().x + (int) (150 * Math.cos(Math.PI * 2 / count * i));
int y = center.getLocation().y + (int) (80 * Math.sin(Math.PI * 2 / count * i));
node.setLocation(x, y);
box.addElement(node);
node.setHost(center);
}
主节点树
int count = 10;
for (int i = 0; i < count; i++) {
Follower node = new Follower("n" + i);
int x = 200 + (int) (150 * Math.cos(Math.PI * 2 / count * i));
int y = 400 + (int) (80 * Math.sin(Math.PI * 2 / count * i));
node.setLocation(x, y);
box.addElement(node);
if (i > 0) {
node.setHost((Follower) box.getElementByID("n" + (i - 1)));
}
if (i == count - 1) {
(Follower) box.getElementByID("n0").setHost(node);
}
}
int count = 5;
for (int i = 0; i < count; i++) {
Follower node = new Follower("m" + i);
int x = 100 + i * 80;
int y = 500;
node.setLocation(x, y);
box.addElement(node);
if (i > 0) {
node.setHost((Follower) box.getElementByID("m" + (i - 1)));
}
}
在Twaver中BTS和BTSAntenna之间也运用了Host机制,并且互为主节点。在这种情况下,当BTS上添加多个BTSAntenna,拖动或缩放时由于相互咬合可能会造成性能影响,这时可以利用BTS.setRingHost(false)取消BTSAntenna相对于bts的主节点关系,从而提高执行效率。