345
|
1 package alice.test.topology.fish;
|
|
2
|
|
3 import java.util.Collections;
|
|
4 import java.util.Comparator;
|
|
5
|
|
6 import alice.codesegment.CodeSegment;
|
|
7 import alice.datasegment.CommandType;
|
|
8 import alice.datasegment.Receiver;
|
|
9
|
|
10 public class WidthReceiver extends CodeSegment {
|
|
11
|
|
12 public Receiver widths = ids.create(CommandType.TAKE);
|
|
13 public Receiver routing = ids.create(CommandType.PEEK);
|
|
14
|
|
15 @Override
|
|
16 public void run() {
|
|
17 int width = this.widths.asInteger();
|
|
18 String from = this.widths.from;
|
|
19 RoutingTable routing = this.routing.asClass(RoutingTable.class);
|
|
20 Routing newRouting = new Routing(from, width);
|
|
21 boolean update = false;
|
|
22 for (Routing r : routing.table) {
|
|
23 if (r.id == newRouting.id) {
|
|
24 routing.sumWidth -= r.width;
|
|
25 routing.sumWidth += newRouting.width;
|
|
26 r.width = width;
|
|
27 update = true;
|
|
28 break;
|
|
29 }
|
|
30 }
|
|
31 if (!update) {
|
|
32 routing.table.add(newRouting);
|
|
33 Collections.sort(routing.table, new Comparator<Routing>() {
|
|
34 @Override
|
|
35 public int compare(Routing o1, Routing o2) {
|
|
36 return o1.id - o2.id;
|
|
37 }
|
|
38 });
|
|
39 routing.sumWidth += width;
|
|
40 }
|
|
41
|
|
42 System.out.println("SUM WIDTH: " + routing.sumWidth);
|
|
43
|
|
44 System.out.println("NODE NUM: " + routing.table.size());
|
|
45
|
|
46 ods.update("width", routing.sumWidth);
|
|
47 ods.update("routing", routing);
|
|
48
|
|
49 WidthReceiver cs = new WidthReceiver();
|
|
50 cs.widths.setKey("widths", this.widths.index);
|
|
51 cs.routing.setKey("routing");
|
|
52 //cs.routing.setKey("routing", this.routing.index);
|
|
53 }
|
|
54
|
|
55 }
|