Mercurial > hg > Members > tatsuki > Alice
view src/alice/test/topology/fish/WidthReceiver.java @ 35:ac3b48c5f4da
share width each other with tree
author | kazz <kazz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 20 Jan 2012 04:00:12 +0900 |
parents | |
children | 0b25b48116b6 |
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(routing.sumWidth); ods.update("local", "width", routing.sumWidth); ods.update("local", "routing", routing); WidthReceiver cs = new WidthReceiver(); cs.widths.setKey("local", "widths", this.widths.index); cs.routing.setKey("local", "routing", this.routing.index); } }