Mercurial > hg > Database > Alice
view 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 |
line wrap: on
line source
package alice.test.topology.fish; import java.util.Collections; import java.util.Comparator; 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; } }); 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); } }