Mercurial > hg > Members > tatsuki > Alice
view src/main/java/alice/test/topology/fish/WidthReceiver.java @ 402:dbfeb353a78d draft multicast tip
refs #3 test commit
author | tatsuki |
---|---|
date | Tue, 24 Jun 2014 19:06:41 +0900 |
parents | ce3ad64bacd3 |
children |
line wrap: on
line source
package alice.test.topology.fish; import java.util.Collections; import java.util.Comparator; import java.util.function.Function; import java.util.function.ToDoubleFunction; import java.util.function.ToIntFunction; import java.util.function.ToLongFunction; import alice.codesegment.CodeSegment; import alice.datasegment.CommandType; import alice.datasegment.Receiver; public class WidthReceiver extends CodeSegment { public Receiver widths = ids.create(CommandType.TAKE); public Receiver routing = ids.create(CommandType.PEEK); @Override public void run() { int width = this.widths.asInteger(); String from = this.widths.from; RoutingTable routing = this.routing.asClass(RoutingTable.class); Routing newRouting = new Routing(from, width); boolean update = false; for (Routing r : routing.table) { if (r.id == newRouting.id) { routing.sumWidth -= r.width; routing.sumWidth += newRouting.width; r.width = width; update = true; break; } } if (!update) { routing.table.add(newRouting); Collections.sort(routing.table, new Comparator<Routing>() { @Override public int compare(Routing o1, Routing o2) { return o1.id - o2.id; } @Override public Comparator<Routing> reversed() { return null; } @Override public Comparator<Routing> thenComparing( Comparator<? super Routing> other) { return null; } @Override public <U> Comparator<Routing> thenComparing( Function<? super Routing, ? extends U> keyExtractor, Comparator<? super U> keyComparator) { return null; } @Override public <U extends Comparable<? super U>> Comparator<Routing> thenComparing( Function<? super Routing, ? extends U> keyExtractor) { return null; } @Override public Comparator<Routing> thenComparingInt( ToIntFunction<? super Routing> keyExtractor) { return null; } @Override public Comparator<Routing> thenComparingLong( ToLongFunction<? super Routing> keyExtractor) { return null; } @Override public Comparator<Routing> thenComparingDouble( ToDoubleFunction<? super Routing> keyExtractor) { return null; } }); routing.sumWidth += width; } System.out.println("SUM WIDTH: " + routing.sumWidth); System.out.println("NODE NUM: " + routing.table.size()); ods.update("width", routing.sumWidth); ods.update("routing", routing); WidthReceiver cs = new WidthReceiver(); cs.widths.setKey("widths", this.widths.index); cs.routing.setKey("routing"); //cs.routing.setKey("routing", this.routing.index); } }