annotate src/main/java/alice/test/topology/fish/WidthReceiver.java @ 345:8f71c3e6f11d

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