diff 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 (2014-04-16)
parents
children ce3ad64bacd3
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/alice/test/topology/fish/WidthReceiver.java	Wed Apr 16 18:26:07 2014 +0900
@@ -0,0 +1,55 @@
+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);
+	}
+
+}