changeset 96:a5fce70380e8 working

add share test
author sugi
date Tue, 19 Jun 2012 17:52:01 +0900
parents 7982324d4329
children df786bf8f036
files src/alice/test/topology/share/CheckLocalIndex.java src/alice/test/topology/share/CheckMyName.java src/alice/test/topology/share/CheckNeedLocalUpdate.java src/alice/test/topology/share/CheckNeedParentUpdate.java src/alice/test/topology/share/CheckParentIndex.java src/alice/test/topology/share/Client.java src/alice/test/topology/share/FishMovementConfig.java src/alice/test/topology/share/FishMovementTopology.java src/alice/test/topology/share/Increment.java src/alice/test/topology/share/Node.java src/alice/test/topology/share/RelayPoint.java src/alice/test/topology/share/StartFishMovement.java
diffstat 12 files changed, 294 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/alice/test/topology/share/CheckLocalIndex.java	Tue Jun 19 17:52:01 2012 +0900
@@ -0,0 +1,29 @@
+package alice.test.topology.share;
+
+import alice.codesegment.CodeSegment;
+import alice.datasegment.CommandType;
+import alice.datasegment.Receiver;
+
+public class CheckLocalIndex extends CodeSegment {
+
+	private Receiver localX = ids.create(CommandType.PEEK);
+	private Receiver parentX = ids.create(CommandType.PEEK);
+	String key;
+	
+	public CheckLocalIndex(String key){
+		this.key = key;
+		this.localX.setKey("local", this.key, this.localX.index);
+		this.parentX.setKey("parent",this.key);
+	}
+	
+	@Override
+	public void run() {
+		System.out.println("index: "+this.localX.index + " value: "+this.localX.asInteger());
+		if (this.localX.index > this.parentX.index)
+			ods.update("parent", this.key, this.localX.asInteger());
+		new CheckLocalIndex(this.key);
+		
+		
+	}
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/alice/test/topology/share/CheckMyName.java	Tue Jun 19 17:52:01 2012 +0900
@@ -0,0 +1,58 @@
+package alice.test.topology.share;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import alice.codesegment.CodeSegment;
+import alice.datasegment.CommandType;
+import alice.datasegment.Receiver;
+
+public class CheckMyName extends CodeSegment {
+	Receiver host = ids.create(CommandType.PEEK);
+	Pattern pattern = Pattern.compile("^(node|cli)([0-9]+)$");
+	
+	public CheckMyName(){
+		host.setKey("local","host");
+	}
+	
+	
+	@Override
+	public synchronized void run(){
+		
+		String name = host.asString();
+		Matcher matcher = pattern.matcher(name);
+		
+		matcher.find();
+		String type = matcher.group(1);
+		int cliNum = new Integer(matcher.group(2));
+		
+		if (type.equals("cli")){
+			System.out.println("cli"+cliNum);
+			ods.update("local", "fish", 0);
+			new RelayPoint("fish");
+			
+			
+									
+		}else if(type.equals("node")){
+			
+			System.out.println("node"+cliNum);
+			if (cliNum == 0){
+			for (int i=0;i<20 ;i++){
+				System.out.println("i = " +i);
+				ods.update("local", "fish", i);
+				try {
+					wait(500);
+				} catch (InterruptedException e) {
+					// TODO Auto-generated catch block
+					e.printStackTrace();
+				}	
+			}
+			}else{
+				ods.update("local", "fish", 0);
+				new RelayPoint("fish");
+				
+			}
+						
+		}
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/alice/test/topology/share/CheckNeedLocalUpdate.java	Tue Jun 19 17:52:01 2012 +0900
@@ -0,0 +1,30 @@
+package alice.test.topology.share;
+
+import alice.codesegment.CodeSegment;
+import alice.datasegment.CommandType;
+import alice.datasegment.Receiver;
+
+public class CheckNeedLocalUpdate extends CodeSegment {
+
+	private Receiver localX = ids.create(CommandType.PEEK);
+	int parentValue;
+	int parentIndex;
+	String key;
+	
+	public CheckNeedLocalUpdate(String key,int index,int value){
+		this.key = key;
+		this.parentValue = value;
+		this.parentIndex = index;
+		this.localX.setKey("local", this.key);
+	}
+	
+	@Override
+	public void run() {
+		if (this.parentIndex > this.localX.index){
+			ods.update("local", this.key, this.parentValue);
+		}
+		new CheckParentIndex(this.key);
+		
+	}
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/alice/test/topology/share/CheckNeedParentUpdate.java	Tue Jun 19 17:52:01 2012 +0900
@@ -0,0 +1,26 @@
+package alice.test.topology.share;
+
+import alice.codesegment.CodeSegment;
+import alice.datasegment.CommandType;
+import alice.datasegment.Receiver;
+
+public class CheckNeedParentUpdate extends CodeSegment {
+
+	private Receiver parentX = ids.create(CommandType.PEEK);
+	int localX;
+	String key;
+	
+	public CheckNeedParentUpdate(String key ,int localX){
+		this.key = key;
+		this.parentX.setKey("parent", this.key, this.parentX.index);
+	}
+	
+	@Override
+	public void run() {
+		if (this.localX != this.parentX.asInteger())
+			ods.update("parent", this.key, localX);
+		new CheckLocalIndex(this.key);
+		
+	}
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/alice/test/topology/share/CheckParentIndex.java	Tue Jun 19 17:52:01 2012 +0900
@@ -0,0 +1,29 @@
+package alice.test.topology.share;
+
+import alice.codesegment.CodeSegment;
+import alice.datasegment.CommandType;
+import alice.datasegment.Receiver;
+
+public class CheckParentIndex extends CodeSegment {
+
+	public Receiver parentX = ids.create(CommandType.PEEK);
+	public Receiver localX = ids.create(CommandType.PEEK);
+	String key;
+		
+	public CheckParentIndex(String key){
+		this.key = key;
+		this.parentX.setKey("parent", this.key, this.parentX.index);
+		this.localX.setKey("local",this.key);
+	}
+	
+	@Override
+	public void run() {
+		System.out.println("parents.index: "+this.parentX.index +"parents.value: "+this.parentX.asInteger());
+		System.out.println("local.index: "+this.localX.index + " local.value: "+this.localX.asInteger());
+		if (this.parentX.index > this.localX.index)
+			ods.update("local", this.key, this.parentX.asInteger());
+		//new CheckNeedLocalUpdate(this.key,this.parentX.index,this.parentX.asInteger());
+		new CheckParentIndex(this.key);
+	}
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/alice/test/topology/share/Client.java	Tue Jun 19 17:52:01 2012 +0900
@@ -0,0 +1,20 @@
+package alice.test.topology.share;
+
+import alice.codesegment.CodeSegment;
+import alice.datasegment.CommandType;
+import alice.datasegment.Receiver;
+
+public class Client extends CodeSegment {
+	Receiver host = ids.create(CommandType.PEEK);
+	
+	public Client(){
+		host.setKey("local","others");
+	}
+	
+	@Override
+	public void run(){
+		System.out.println(host.asString());
+		ods.update("local", "fish", 0);
+		new RelayPoint("fish");
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/alice/test/topology/share/FishMovementConfig.java	Tue Jun 19 17:52:01 2012 +0900
@@ -0,0 +1,12 @@
+package alice.test.topology.share;
+
+import alice.topology.node.TopologyNodeConfig;;
+
+public class FishMovementConfig extends TopologyNodeConfig {
+	
+	public FishMovementConfig(String[] args){
+		super(args);
+	} 
+	
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/alice/test/topology/share/FishMovementTopology.java	Tue Jun 19 17:52:01 2012 +0900
@@ -0,0 +1,11 @@
+package alice.test.topology.share;
+import alice.topology.node.TopologyNode;
+
+public class FishMovementTopology {
+	public static void main(String[] args){
+		FishMovementConfig conf = new FishMovementConfig(args);
+		new TopologyNode(conf, new StartFishMovement());
+		
+	}
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/alice/test/topology/share/Increment.java	Tue Jun 19 17:52:01 2012 +0900
@@ -0,0 +1,21 @@
+package alice.test.topology.share;
+
+import alice.codesegment.CodeSegment;
+import alice.datasegment.CommandType;
+import alice.datasegment.Receiver;
+
+public class Increment extends CodeSegment {
+	Receiver nowX = ids.create(CommandType.PEEK);
+	
+	public Increment(){
+		nowX.setKey("local","fish",this.nowX.index);
+	}
+	
+	@Override
+	public void run(){
+		System.out.println("value "+this.nowX.asInteger());
+		new Increment();
+		ods.update("local", "fish", this.nowX.asInteger()+1);
+		
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/alice/test/topology/share/Node.java	Tue Jun 19 17:52:01 2012 +0900
@@ -0,0 +1,19 @@
+package alice.test.topology.share;
+
+import alice.codesegment.CodeSegment;
+import alice.datasegment.CommandType;
+import alice.datasegment.Receiver;
+
+public class Node extends CodeSegment {
+	Receiver host = ids.create(CommandType.PEEK);
+	
+	public Node(){
+		host.setKey("local","node0");
+	}
+	
+	@Override
+	public void run(){
+		new Increment();
+		ods.update("local", "fish", 0);
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/alice/test/topology/share/RelayPoint.java	Tue Jun 19 17:52:01 2012 +0900
@@ -0,0 +1,25 @@
+package alice.test.topology.share;
+
+import alice.codesegment.CodeSegment;
+import alice.datasegment.CommandType;
+import alice.datasegment.Receiver;
+
+public class RelayPoint extends CodeSegment {
+
+	Receiver name = ids.create(CommandType.PEEK);
+	String key;
+	
+	public RelayPoint(String key){
+		this.key = key;
+		this.name.setKey("parent", this.key, this.name.index);
+		System.out.println("setkey");
+	}
+	
+	@Override
+	public void run() {
+		System.out.println("run RelayPoint");	
+		new CheckLocalIndex(this.key);
+		new CheckParentIndex(this.key);
+	}
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/alice/test/topology/share/StartFishMovement.java	Tue Jun 19 17:52:01 2012 +0900
@@ -0,0 +1,14 @@
+package alice.test.topology.share;
+
+import alice.codesegment.CodeSegment;
+
+public class StartFishMovement extends CodeSegment{
+	@Override
+	public void run(){
+		//new Client();
+		//new Node();
+		new CheckMyName();
+	}
+	
+
+}