changeset 115:9845b74063ec working

share max number
author sugi
date Sat, 21 Jul 2012 10:02:41 +0900
parents 7dbaaa0de144
children 248064474909
files src/alice/test/topology/fishmodel/alpha/AutoIncrement.java src/alice/test/topology/fishmodel/alpha/SendLocation.java src/alice/test/topology/fishmodel/alpha/SetLocation.java src/alice/test/topology/fishmodel/beta/CheckMyName.java src/alice/test/topology/fishmodel/beta/GetMaxNum.java src/alice/test/topology/fishmodel/beta/UpdateNum.java
diffstat 6 files changed, 99 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/src/alice/test/topology/fishmodel/alpha/AutoIncrement.java	Wed Jul 18 20:40:50 2012 +0900
+++ b/src/alice/test/topology/fishmodel/alpha/AutoIncrement.java	Sat Jul 21 10:02:41 2012 +0900
@@ -17,11 +17,28 @@
 	}
 
 	@Override
-	public void run() {
+	public synchronized void run() {
 		FishPoint FP = this.position.asClass(FishPoint.class);
-		FP.setXY(FP.getX()+0.01f, FP.getY());
+		
+		if (FP.getX()+0.01>9.0f){
+			FP.setXY(-1.0f, FP.getY());
+		} else if (FP.getX()+0.01< -1.0f){
+			FP.setXY(9.0f, FP.getY());
+		}
+		else {
+			FP.setXY(FP.getX()+0.01f, FP.getY());
+		}
+		
+		
 		ods.update("local", key, FP);
 		
+		try {
+			wait(150);
+		} catch (InterruptedException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+		
 		new AutoIncrement(this.key,this.position.index);
 		
 	}
--- a/src/alice/test/topology/fishmodel/alpha/SendLocation.java	Wed Jul 18 20:40:50 2012 +0900
+++ b/src/alice/test/topology/fishmodel/alpha/SendLocation.java	Sat Jul 21 10:02:41 2012 +0900
@@ -19,7 +19,16 @@
 	@Override
 	public void run() {
 		FishPoint FP = this.position.asClass(FishPoint.class);
-		FP.setXY(FP.getX()+this.x, FP.getY()+this.y);
+		
+		if (FP.getX()+this.x>9.0f){
+			FP.setXY(-1.0f, FP.getY()+this.y);
+		} else if (FP.getX()+this.x< -1){
+			FP.setXY(9.0f, FP.getY()+this.y);
+		}
+		else {
+			FP.setXY(FP.getX()+this.x, FP.getY()+this.y);
+		}
+		
 		ods.update("local", "fish", FP);
 		
 	}
--- a/src/alice/test/topology/fishmodel/alpha/SetLocation.java	Wed Jul 18 20:40:50 2012 +0900
+++ b/src/alice/test/topology/fishmodel/alpha/SetLocation.java	Sat Jul 21 10:02:41 2012 +0900
@@ -24,15 +24,13 @@
 	public void run(){
 		
 		FishPoint FP = this.position.asClass(FishPoint.class);
-		obj.setLocation(FP.getX() - 2*range, FP.getY());
+		//obj.setLocation(FP.getX() - 2*range, FP.getY());
 		
-		/*
-		float startX = 2*range - 1;
-		float endX = 2*range + 1;
+		float startX = 2*range - 1.5f;
+		float endX = 2*range + 1.5f;
 		if (startX <= FP.getX() && FP.getX() < endX)
 			obj.setLocation(FP.getX() - 2*range, FP.getY());
-		System.out.println(this.position.key);
-		*/
+		
 		new SetLocation(this.obj,this.key,this.position.index,this.range);
 					
 	}
--- a/src/alice/test/topology/fishmodel/beta/CheckMyName.java	Wed Jul 18 20:40:50 2012 +0900
+++ b/src/alice/test/topology/fishmodel/beta/CheckMyName.java	Sat Jul 21 10:02:41 2012 +0900
@@ -30,9 +30,10 @@
 		
 		MakeFrame frame =  new MakeFrame(name);
 		RoutingTable routing = new RoutingTable();
-		
-		
-		
+		/*
+		ods.put("local", "max", num);
+		new CheckLocalIndex(key,1);
+		*/
 		if (type.equals("cli")){
 			System.out.println("cli"+num);
 			routing.table.add(new Routing("parent"));
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/alice/test/topology/fishmodel/beta/GetMaxNum.java	Sat Jul 21 10:02:41 2012 +0900
@@ -0,0 +1,32 @@
+package alice.test.topology.fishmodel.beta;
+
+import alice.codesegment.CodeSegment;
+import alice.datasegment.CommandType;
+import alice.datasegment.Receiver;
+
+
+public class GetMaxNum extends CodeSegment{
+	
+	private Receiver member = ids.create(CommandType.PEEK);
+	int nowMax;
+	public GetMaxNum(int range,int index){
+		this.nowMax = range;
+		this.member.setKey("local","num",index);
+	}
+	
+	@Override
+	public void run(){
+		if (this.member.index > this.nowMax){
+			new UpdateNum("num",this.member);
+			new GetMaxNum(this.member.asInteger(),this.member.index);
+			
+		} else {
+			
+			new GetMaxNum(this.nowMax,this.member.index);
+		}
+		
+					
+	}
+	
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/alice/test/topology/fishmodel/beta/UpdateNum.java	Sat Jul 21 10:02:41 2012 +0900
@@ -0,0 +1,30 @@
+package alice.test.topology.fishmodel.beta;
+
+import alice.codesegment.CodeSegment;
+import alice.datasegment.CommandType;
+import alice.datasegment.Receiver;
+
+public class UpdateNum extends CodeSegment {
+	
+	private Receiver list = ids.create(CommandType.PEEK);
+	private Receiver data;
+	String key;
+	
+	public UpdateNum(String key,Receiver data){
+		this.key = key;
+		this.data = data;
+		this.list.setKey("local", "list");
+	}
+
+	@Override
+	public void run() {
+		RoutingTable RT = this.list.asClass(RoutingTable.class);
+		for (Routing r : RT.table) {
+			if (!r.name.equals(this.data.from)){
+				ods.update(r.name, this.key, this.data.val);
+			}
+			
+		}
+	}
+
+}