annotate src/main/java/alice/test/topology/fish/WidthReceiver.java @ 393:38021fceabef draft multicast

test commit
author tatsuki
date Tue, 17 Jun 2014 17:39:47 +0900
parents ce3ad64bacd3
children
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;
370
ce3ad64bacd3 add implement methods
sugi
parents: 345
diff changeset
5 import java.util.function.Function;
ce3ad64bacd3 add implement methods
sugi
parents: 345
diff changeset
6 import java.util.function.ToDoubleFunction;
ce3ad64bacd3 add implement methods
sugi
parents: 345
diff changeset
7 import java.util.function.ToIntFunction;
ce3ad64bacd3 add implement methods
sugi
parents: 345
diff changeset
8 import java.util.function.ToLongFunction;
345
8f71c3e6f11d Change directory structure Maven standard
sugi
parents:
diff changeset
9
8f71c3e6f11d Change directory structure Maven standard
sugi
parents:
diff changeset
10 import alice.codesegment.CodeSegment;
8f71c3e6f11d Change directory structure Maven standard
sugi
parents:
diff changeset
11 import alice.datasegment.CommandType;
8f71c3e6f11d Change directory structure Maven standard
sugi
parents:
diff changeset
12 import alice.datasegment.Receiver;
8f71c3e6f11d Change directory structure Maven standard
sugi
parents:
diff changeset
13
8f71c3e6f11d Change directory structure Maven standard
sugi
parents:
diff changeset
14 public class WidthReceiver extends CodeSegment {
8f71c3e6f11d Change directory structure Maven standard
sugi
parents:
diff changeset
15
8f71c3e6f11d Change directory structure Maven standard
sugi
parents:
diff changeset
16 public Receiver widths = ids.create(CommandType.TAKE);
8f71c3e6f11d Change directory structure Maven standard
sugi
parents:
diff changeset
17 public Receiver routing = ids.create(CommandType.PEEK);
8f71c3e6f11d Change directory structure Maven standard
sugi
parents:
diff changeset
18
8f71c3e6f11d Change directory structure Maven standard
sugi
parents:
diff changeset
19 @Override
8f71c3e6f11d Change directory structure Maven standard
sugi
parents:
diff changeset
20 public void run() {
8f71c3e6f11d Change directory structure Maven standard
sugi
parents:
diff changeset
21 int width = this.widths.asInteger();
8f71c3e6f11d Change directory structure Maven standard
sugi
parents:
diff changeset
22 String from = this.widths.from;
8f71c3e6f11d Change directory structure Maven standard
sugi
parents:
diff changeset
23 RoutingTable routing = this.routing.asClass(RoutingTable.class);
8f71c3e6f11d Change directory structure Maven standard
sugi
parents:
diff changeset
24 Routing newRouting = new Routing(from, width);
8f71c3e6f11d Change directory structure Maven standard
sugi
parents:
diff changeset
25 boolean update = false;
8f71c3e6f11d Change directory structure Maven standard
sugi
parents:
diff changeset
26 for (Routing r : routing.table) {
8f71c3e6f11d Change directory structure Maven standard
sugi
parents:
diff changeset
27 if (r.id == newRouting.id) {
8f71c3e6f11d Change directory structure Maven standard
sugi
parents:
diff changeset
28 routing.sumWidth -= r.width;
8f71c3e6f11d Change directory structure Maven standard
sugi
parents:
diff changeset
29 routing.sumWidth += newRouting.width;
8f71c3e6f11d Change directory structure Maven standard
sugi
parents:
diff changeset
30 r.width = width;
8f71c3e6f11d Change directory structure Maven standard
sugi
parents:
diff changeset
31 update = true;
8f71c3e6f11d Change directory structure Maven standard
sugi
parents:
diff changeset
32 break;
8f71c3e6f11d Change directory structure Maven standard
sugi
parents:
diff changeset
33 }
8f71c3e6f11d Change directory structure Maven standard
sugi
parents:
diff changeset
34 }
8f71c3e6f11d Change directory structure Maven standard
sugi
parents:
diff changeset
35 if (!update) {
8f71c3e6f11d Change directory structure Maven standard
sugi
parents:
diff changeset
36 routing.table.add(newRouting);
8f71c3e6f11d Change directory structure Maven standard
sugi
parents:
diff changeset
37 Collections.sort(routing.table, new Comparator<Routing>() {
8f71c3e6f11d Change directory structure Maven standard
sugi
parents:
diff changeset
38 @Override
8f71c3e6f11d Change directory structure Maven standard
sugi
parents:
diff changeset
39 public int compare(Routing o1, Routing o2) {
8f71c3e6f11d Change directory structure Maven standard
sugi
parents:
diff changeset
40 return o1.id - o2.id;
8f71c3e6f11d Change directory structure Maven standard
sugi
parents:
diff changeset
41 }
370
ce3ad64bacd3 add implement methods
sugi
parents: 345
diff changeset
42
ce3ad64bacd3 add implement methods
sugi
parents: 345
diff changeset
43 @Override
ce3ad64bacd3 add implement methods
sugi
parents: 345
diff changeset
44 public Comparator<Routing> reversed() {
ce3ad64bacd3 add implement methods
sugi
parents: 345
diff changeset
45 return null;
ce3ad64bacd3 add implement methods
sugi
parents: 345
diff changeset
46 }
ce3ad64bacd3 add implement methods
sugi
parents: 345
diff changeset
47
ce3ad64bacd3 add implement methods
sugi
parents: 345
diff changeset
48 @Override
ce3ad64bacd3 add implement methods
sugi
parents: 345
diff changeset
49 public Comparator<Routing> thenComparing(
ce3ad64bacd3 add implement methods
sugi
parents: 345
diff changeset
50 Comparator<? super Routing> other) {
ce3ad64bacd3 add implement methods
sugi
parents: 345
diff changeset
51 return null;
ce3ad64bacd3 add implement methods
sugi
parents: 345
diff changeset
52 }
ce3ad64bacd3 add implement methods
sugi
parents: 345
diff changeset
53
ce3ad64bacd3 add implement methods
sugi
parents: 345
diff changeset
54 @Override
ce3ad64bacd3 add implement methods
sugi
parents: 345
diff changeset
55 public <U> Comparator<Routing> thenComparing(
ce3ad64bacd3 add implement methods
sugi
parents: 345
diff changeset
56 Function<? super Routing, ? extends U> keyExtractor,
ce3ad64bacd3 add implement methods
sugi
parents: 345
diff changeset
57 Comparator<? super U> keyComparator) {
ce3ad64bacd3 add implement methods
sugi
parents: 345
diff changeset
58 return null;
ce3ad64bacd3 add implement methods
sugi
parents: 345
diff changeset
59 }
ce3ad64bacd3 add implement methods
sugi
parents: 345
diff changeset
60
ce3ad64bacd3 add implement methods
sugi
parents: 345
diff changeset
61 @Override
ce3ad64bacd3 add implement methods
sugi
parents: 345
diff changeset
62 public <U extends Comparable<? super U>> Comparator<Routing> thenComparing(
ce3ad64bacd3 add implement methods
sugi
parents: 345
diff changeset
63 Function<? super Routing, ? extends U> keyExtractor) {
ce3ad64bacd3 add implement methods
sugi
parents: 345
diff changeset
64 return null;
ce3ad64bacd3 add implement methods
sugi
parents: 345
diff changeset
65 }
ce3ad64bacd3 add implement methods
sugi
parents: 345
diff changeset
66
ce3ad64bacd3 add implement methods
sugi
parents: 345
diff changeset
67 @Override
ce3ad64bacd3 add implement methods
sugi
parents: 345
diff changeset
68 public Comparator<Routing> thenComparingInt(
ce3ad64bacd3 add implement methods
sugi
parents: 345
diff changeset
69 ToIntFunction<? super Routing> keyExtractor) {
ce3ad64bacd3 add implement methods
sugi
parents: 345
diff changeset
70 return null;
ce3ad64bacd3 add implement methods
sugi
parents: 345
diff changeset
71 }
ce3ad64bacd3 add implement methods
sugi
parents: 345
diff changeset
72
ce3ad64bacd3 add implement methods
sugi
parents: 345
diff changeset
73 @Override
ce3ad64bacd3 add implement methods
sugi
parents: 345
diff changeset
74 public Comparator<Routing> thenComparingLong(
ce3ad64bacd3 add implement methods
sugi
parents: 345
diff changeset
75 ToLongFunction<? super Routing> keyExtractor) {
ce3ad64bacd3 add implement methods
sugi
parents: 345
diff changeset
76 return null;
ce3ad64bacd3 add implement methods
sugi
parents: 345
diff changeset
77 }
ce3ad64bacd3 add implement methods
sugi
parents: 345
diff changeset
78
ce3ad64bacd3 add implement methods
sugi
parents: 345
diff changeset
79 @Override
ce3ad64bacd3 add implement methods
sugi
parents: 345
diff changeset
80 public Comparator<Routing> thenComparingDouble(
ce3ad64bacd3 add implement methods
sugi
parents: 345
diff changeset
81 ToDoubleFunction<? super Routing> keyExtractor) {
ce3ad64bacd3 add implement methods
sugi
parents: 345
diff changeset
82 return null;
ce3ad64bacd3 add implement methods
sugi
parents: 345
diff changeset
83 }
345
8f71c3e6f11d Change directory structure Maven standard
sugi
parents:
diff changeset
84 });
8f71c3e6f11d Change directory structure Maven standard
sugi
parents:
diff changeset
85 routing.sumWidth += width;
8f71c3e6f11d Change directory structure Maven standard
sugi
parents:
diff changeset
86 }
8f71c3e6f11d Change directory structure Maven standard
sugi
parents:
diff changeset
87
8f71c3e6f11d Change directory structure Maven standard
sugi
parents:
diff changeset
88 System.out.println("SUM WIDTH: " + routing.sumWidth);
8f71c3e6f11d Change directory structure Maven standard
sugi
parents:
diff changeset
89
8f71c3e6f11d Change directory structure Maven standard
sugi
parents:
diff changeset
90 System.out.println("NODE NUM: " + routing.table.size());
8f71c3e6f11d Change directory structure Maven standard
sugi
parents:
diff changeset
91
8f71c3e6f11d Change directory structure Maven standard
sugi
parents:
diff changeset
92 ods.update("width", routing.sumWidth);
8f71c3e6f11d Change directory structure Maven standard
sugi
parents:
diff changeset
93 ods.update("routing", routing);
8f71c3e6f11d Change directory structure Maven standard
sugi
parents:
diff changeset
94
8f71c3e6f11d Change directory structure Maven standard
sugi
parents:
diff changeset
95 WidthReceiver cs = new WidthReceiver();
8f71c3e6f11d Change directory structure Maven standard
sugi
parents:
diff changeset
96 cs.widths.setKey("widths", this.widths.index);
8f71c3e6f11d Change directory structure Maven standard
sugi
parents:
diff changeset
97 cs.routing.setKey("routing");
8f71c3e6f11d Change directory structure Maven standard
sugi
parents:
diff changeset
98 //cs.routing.setKey("routing", this.routing.index);
8f71c3e6f11d Change directory structure Maven standard
sugi
parents:
diff changeset
99 }
8f71c3e6f11d Change directory structure Maven standard
sugi
parents:
diff changeset
100
8f71c3e6f11d Change directory structure Maven standard
sugi
parents:
diff changeset
101 }