changeset 35:6660ebba441e

add ring test but not working
author Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
date Sun, 18 Feb 2018 23:44:15 +0900
parents 7b405f622c5c
children 4479d37c8e53
files src/main/java/christie/codegear/CodeGearManager.java src/main/java/christie/test/ring/CheckMyName.java src/main/java/christie/test/ring/ConnectManager.java src/main/java/christie/test/ring/CreateFlipCodeGear.java src/main/java/christie/test/ring/FlipCodeGear.java src/main/java/christie/test/ring/StartCount.java src/main/java/christie/test/ring/StartRingTest.java
diffstat 7 files changed, 179 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/christie/codegear/CodeGearManager.java	Sat Feb 17 13:14:22 2018 +0900
+++ b/src/main/java/christie/codegear/CodeGearManager.java	Sun Feb 18 23:44:15 2018 +0900
@@ -20,13 +20,17 @@
     private LocalDataGearManager localDGM = new LocalDataGearManager();
     private ConcurrentHashMap<String, IncomingTcpConnection> acceptHash = new ConcurrentHashMap<String, IncomingTcpConnection>();
     public int cgmID;
+    public ChristieDaemon daemon;
+    public int localPort;
 
     public CodeGearManager(int cgmID, ThreadPoolExecutor exe, ConcurrentHashMap<Integer, CodeGearManager> cgmList, int localPort) {
         dgmList.put("local", localDGM);
         this.cgmList = cgmList;
         threadPoolExecutor = exe;
         this.cgmID = cgmID;
-        new ChristieDaemon(localPort, this).listen();
+        this.localPort = localPort;
+        daemon = new ChristieDaemon(localPort, this);
+        daemon.listen();
     }
 
     public LocalDataGearManager getLocalDGM(){
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/christie/test/ring/CheckMyName.java	Sun Feb 18 23:44:15 2018 +0900
@@ -0,0 +1,21 @@
+package christie.test.ring;
+
+import christie.annotation.Take;
+import christie.codegear.CodeGear;
+import christie.codegear.CodeGearManager;
+
+public class CheckMyName extends CodeGear{
+
+    @Take
+    int managerPort;
+
+    @Take
+    String managerAddress;
+
+    @Override
+    protected void run(CodeGearManager cgm) {
+        cgm.createRemoteDGM("manager", managerAddress, managerPort);
+        getDGM("manager").put("nodePort", cgm.localPort);
+        cgm.setup(new CreateFlipCodeGear());
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/christie/test/ring/ConnectManager.java	Sun Feb 18 23:44:15 2018 +0900
@@ -0,0 +1,30 @@
+package christie.test.ring;
+
+import christie.annotation.Peek;
+import christie.annotation.Take;
+import christie.codegear.CodeGear;
+import christie.codegear.CodeGearManager;
+
+public class ConnectManager extends CodeGear{
+    @Take
+    int nodePort;
+
+    @Peek
+    int max;
+
+    @Override
+    protected void run(CodeGearManager cgm) {
+        String nodeName = "node"+(nodePort-10000);
+        cgm.createRemoteDGM(nodeName, "localhost", nodePort);
+        getDGM(nodeName).put("hostname", nodeName);
+        getDGM(nodeName).put("address", "localhost");
+        if (nodePort-10000 < max-1){
+            getDGM(nodeName).put("port", nodePort+1);
+        } else {
+            getDGM(nodeName).put("port", 10000);
+            cgm.setup(new StartCount());
+            getLocalDGM().put("start_count", 1);
+        }
+        cgm.setup(new ConnectManager());
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/christie/test/ring/CreateFlipCodeGear.java	Sun Feb 18 23:44:15 2018 +0900
@@ -0,0 +1,28 @@
+package christie.test.ring;
+
+import christie.annotation.Peek;
+import christie.codegear.CodeGear;
+import christie.codegear.CodeGearManager;
+
+public class CreateFlipCodeGear extends CodeGear{
+
+    @Peek
+    String hostname;
+
+    @Peek
+    String address;
+
+    @Peek
+    int port;
+
+    @Override
+    protected void run(CodeGearManager cgm) {
+        cgm.createRemoteDGM("remote", address, port);
+        cgm.setup(new FlipCodeGear());
+        if (hostname.equals("node0")){
+            getLocalDGM().put("count", 1);
+            getLocalDGM().put("timestamp", System.currentTimeMillis());
+        }
+        getDGM("manager").put("standby", true);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/christie/test/ring/FlipCodeGear.java	Sun Feb 18 23:44:15 2018 +0900
@@ -0,0 +1,37 @@
+package christie.test.ring;
+
+import christie.annotation.Peek;
+import christie.annotation.Take;
+import christie.codegear.CodeGear;
+import christie.codegear.CodeGearManager;
+
+public class FlipCodeGear extends CodeGear{
+    @Take
+    int count;
+
+    @Take
+    long timestamp;
+
+    @Peek
+    String hostname;
+
+    @Take
+    boolean start;
+
+    @Override
+    protected void run(CodeGearManager cgm) {
+        System.out.println(hostname + " : count " + count);
+        if (count == 5) {
+            System.out.println(System.currentTimeMillis() - timestamp);
+        } else {
+            getDGM("remote").put("data", timestamp);
+            if (hostname.equals("node0")) {
+                getDGM("remote").put("count", ++count);
+            } else {
+                getDGM("remote").put("count", count);
+            }
+        }
+        cgm.setup(new FlipCodeGear());
+        getLocalDGM().put("start", start);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/christie/test/ring/StartCount.java	Sun Feb 18 23:44:15 2018 +0900
@@ -0,0 +1,32 @@
+package christie.test.ring;
+
+import christie.annotation.Peek;
+import christie.annotation.Take;
+import christie.codegear.CodeGear;
+import christie.codegear.CodeGearManager;
+
+public class StartCount extends CodeGear {
+
+    @Take
+    int start_count;
+
+    @Peek
+    int max;
+
+    @Take
+    boolean standby;
+
+
+    @Override
+    protected void run(CodeGearManager cgm) {
+        if (start_count == max){
+            for (int i = 0; i < max; i++){
+                getDGM("node"+i).put("start", true);
+            }
+        } else {
+            cgm.setup(new StartCount());
+            getLocalDGM().put("start_count", ++start_count);
+        }
+
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/christie/test/ring/StartRingTest.java	Sun Feb 18 23:44:15 2018 +0900
@@ -0,0 +1,26 @@
+package christie.test.ring;
+
+import christie.codegear.CodeGearManager;
+import christie.codegear.StartCodeGear;
+
+public class StartRingTest extends StartCodeGear{
+
+
+    public StartRingTest(CodeGearManager cgm) {
+        super(cgm);
+        int max = 3;
+        cgm.setup(new ConnectManager());
+        getLocalDGM().put("max", max);
+        for (int i = 0; i < max; i++) {
+            CodeGearManager nodeCgm = createCGM(10000 + i);
+            nodeCgm.setup(new CheckMyName());
+            nodeCgm.getLocalDGM().put("managerPort", 20000);
+            nodeCgm.getLocalDGM().put("managerAddress", "localhost");
+        }
+
+    }
+
+    public static void main (String[] args){
+        new StartRingTest(createCGM(20000));
+    }
+}