changeset 24:0930b0554299

use DataGears
author Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
date Thu, 25 Jan 2018 23:02:02 +0900
parents 695705dba324
children 76fac42a840e
files src/main/java/christie/codegear/CodeGearManager.java src/main/java/christie/daemon/ChristieDaemon.java src/main/java/christie/daemon/Config.java src/main/java/christie/daemon/IncomingTcpConnection.java src/main/java/christie/datagear/Command/RemotePeekCommand.java src/main/java/christie/datagear/Command/RemoteTakeCommand.java src/main/java/christie/datagear/DataGearManager.java src/main/java/christie/datagear/DataGears.java src/main/java/christie/datagear/LocalDataGearManager.java src/main/java/christie/datagear/RemoteDataGearManager.java src/main/java/christie/test/Remote/RemoteTestConfig.java src/main/java/christie/test/Remote/StartRemotePut.java src/main/java/christie/test/RemoteTake/StartRemoteTake.java
diffstat 13 files changed, 17 insertions(+), 67 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/christie/codegear/CodeGearManager.java	Thu Jan 25 17:46:55 2018 +0900
+++ b/src/main/java/christie/codegear/CodeGearManager.java	Thu Jan 25 23:02:02 2018 +0900
@@ -1,7 +1,6 @@
 package christie.codegear;
 
 import christie.daemon.ChristieDaemon;
-import christie.daemon.Config;
 import christie.daemon.IncomingTcpConnection;
 import christie.datagear.DataGearManager;
 import christie.datagear.LocalDataGearManager;
@@ -21,7 +20,6 @@
     private LocalDataGearManager localDGM = new LocalDataGearManager();
     private ConcurrentHashMap<String, IncomingTcpConnection> acceptHash = new ConcurrentHashMap<String, IncomingTcpConnection>();
     public int cgmID;
-    public Config conf;//ToDo: make daemon from config
 
     public CodeGearManager(int cgmID, ThreadPoolExecutor exe, ConcurrentHashMap<Integer, CodeGearManager> cgms, int localPort) {
         dataGearManagers.put("local", localDGM);
--- a/src/main/java/christie/daemon/ChristieDaemon.java	Thu Jan 25 17:46:55 2018 +0900
+++ b/src/main/java/christie/daemon/ChristieDaemon.java	Thu Jan 25 23:02:02 2018 +0900
@@ -14,11 +14,6 @@
     private AcceptThread acceptThread;
     public CodeGearManager cgm;
 
-    public ChristieDaemon(Config conf, CodeGearManager cgm) {
-        this.localPort = conf.localPort;
-        this.cgm = cgm;
-    }
-
     public ChristieDaemon(int localPort, CodeGearManager cgm) {
         this.localPort = localPort;
         this.cgm = cgm;
--- a/src/main/java/christie/daemon/Config.java	Thu Jan 25 17:46:55 2018 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,15 +0,0 @@
-package christie.daemon;
-
-public class Config {
-
-    public int localPort = 10000;
-
-    public Config(String[] args) {
-        for (int i = 0; i< args.length; i++) {
-            if ("-localPort".equals(args[i])) {
-                localPort = Integer.parseInt(args[++i]);
-            }
-        }
-    }
-
-}
--- a/src/main/java/christie/daemon/IncomingTcpConnection.java	Thu Jan 25 17:46:55 2018 +0900
+++ b/src/main/java/christie/daemon/IncomingTcpConnection.java	Thu Jan 25 23:02:02 2018 +0900
@@ -44,7 +44,7 @@
             try {
                 RemoteMessage msg = unpacker.read(RemoteMessage.class);
                 CommandType type = CommandType.getCommandTypeFromId(msg.type);
-                int dataSize = unpacker.readInt();
+                int dataSize = unpacker.readInt();//ここでとまる
                 byte[] data = new byte[dataSize];
                 switch (type) {
                     case PUT:
--- a/src/main/java/christie/datagear/Command/RemotePeekCommand.java	Thu Jan 25 17:46:55 2018 +0900
+++ b/src/main/java/christie/datagear/Command/RemotePeekCommand.java	Thu Jan 25 23:02:02 2018 +0900
@@ -5,6 +5,6 @@
 public class RemotePeekCommand extends RemoteTakeCommand {
     public RemotePeekCommand(String fromDgmName, String key, Class clazz, Connection cn) {
         super(fromDgmName, key, clazz, cn);
-        this.type = CommandType.PEEK;
+        this.type = CommandType.REMOTEPEEK;
     }
 }
--- a/src/main/java/christie/datagear/Command/RemoteTakeCommand.java	Thu Jan 25 17:46:55 2018 +0900
+++ b/src/main/java/christie/datagear/Command/RemoteTakeCommand.java	Thu Jan 25 23:02:02 2018 +0900
@@ -9,7 +9,7 @@
 public class RemoteTakeCommand extends Command {
 
     public RemoteTakeCommand(String fromDgmName, String key, Class clazz, Connection cn) {
-        this.type = CommandType.TAKE;
+        this.type = CommandType.REMOTETAKE;
         this.fromDgmName = fromDgmName;
         this.key = key;
         this.clazz = clazz;
--- a/src/main/java/christie/datagear/DataGearManager.java	Thu Jan 25 17:46:55 2018 +0900
+++ b/src/main/java/christie/datagear/DataGearManager.java	Thu Jan 25 23:02:02 2018 +0900
@@ -10,7 +10,7 @@
  * PUT/TAKEなどDataGearManagerに対するComandの実行。
  */
 public abstract class DataGearManager {
-    protected TreeMap<String, LinkedBlockingQueue<DataGear>> dataGears = new TreeMap<String, LinkedBlockingQueue<DataGear>>();
+    protected DataGears dataGears = new DataGears();
     public WaitList waitList = new WaitList();
     public abstract void take(Command cm);
     public abstract void put(String key, Object data);
--- a/src/main/java/christie/datagear/DataGears.java	Thu Jan 25 17:46:55 2018 +0900
+++ b/src/main/java/christie/datagear/DataGears.java	Thu Jan 25 23:02:02 2018 +0900
@@ -6,7 +6,7 @@
 public class DataGears {
     protected TreeMap<String, LinkedBlockingQueue<DataGear>> dataGears = new TreeMap<String, LinkedBlockingQueue<DataGear>>();
 
-    public void add(String key, DataGear dg){
+    public void put(String key, DataGear dg){
         if (dataGears.containsKey(key)) {
             dataGears.get(key).add(dg);
         } else {
@@ -29,4 +29,8 @@
     public Object peek(String key){
         return dataGears.get(key).peek().getData();
     }
+
+    public boolean containsKey(String key){
+        return dataGears.containsKey(key);
+    }
 }
--- a/src/main/java/christie/datagear/LocalDataGearManager.java	Thu Jan 25 17:46:55 2018 +0900
+++ b/src/main/java/christie/datagear/LocalDataGearManager.java	Thu Jan 25 23:02:02 2018 +0900
@@ -35,13 +35,7 @@
     public synchronized void runCommand(Command cm){
         switch (cm.type) {
             case PUT:
-                if (dataGears.containsKey(cm.key)) {
-                    dataGears.get(cm.key).add(cm.dg);
-                } else {
-                    LinkedBlockingQueue<DataGear> queue = new LinkedBlockingQueue<DataGear>();
-                    queue.add(cm.dg);
-                    dataGears.put(cm.key, queue);
-                }
+                dataGears.put(cm.key, cm.dg);
 
                 if (waitList.containsKey(cm.key)){
                     runCommand(waitList.getAndRemoveCommand(cm.key));
@@ -59,7 +53,7 @@
 
                 break;
             case PEEK:
-                cm.dg.setData(dataGears.get(cm.key).peek().getData());
+                cm.dg.setData(dataGears.peek(cm.key));
                 cm.cg.getIdg().setInputs(cm.key, cm.dg);
 
                 break;
@@ -74,9 +68,6 @@
     }
 
     private void setTakeData(Command cm){
-        cm.dg.setData(dataGears.get(cm.key).poll().getData());
-        if (dataGears.get(cm.key).isEmpty()) {
-            dataGears.remove(cm.key);
-        }
+        cm.dg.setData(dataGears.take(cm.key));
     }
 }
--- a/src/main/java/christie/datagear/RemoteDataGearManager.java	Thu Jan 25 17:46:55 2018 +0900
+++ b/src/main/java/christie/datagear/RemoteDataGearManager.java	Thu Jan 25 23:02:02 2018 +0900
@@ -55,9 +55,8 @@
     @Override
     public void take(Command cm) {
         waitList.add(cm);
-        //RemoteTakeCommand remoteCmd = new RemoteTakeCommand(cm.cgmID, connection.name, cm.key, cm.clazz, connection);
-        cm.fromDgmName = connection.name;
-        connection.write(cm);
+        RemoteTakeCommand remoteCmd = new RemoteTakeCommand(connection.name, cm.key, cm.clazz, connection);
+        connection.write(remoteCmd);
     }
 
     public void metaPut(int cgmID, String key, Object data){//meta
--- a/src/main/java/christie/test/Remote/RemoteTestConfig.java	Thu Jan 25 17:46:55 2018 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,23 +0,0 @@
-package christie.test.Remote;
-
-import christie.daemon.Config;
-
-public class RemoteTestConfig extends Config{
-
-    public String address = "127.0.0.1";
-    public int connectPort = 10001;
-
-    public RemoteTestConfig(String[] args) {
-        super(args);
-        for (int i = 0; i< args.length; i++) {
-            if ("-localPort".equals(args[i])) {
-                localPort = Integer.parseInt(args[++i]);
-            }if ("-address".equals(args[i])) {
-                address = args[++i];
-            } else if ("-connectPort".equals(args[i])) {
-                connectPort = Integer.parseInt(args[++i]);
-            }
-        }
-    }
-
-}
--- a/src/main/java/christie/test/Remote/StartRemotePut.java	Thu Jan 25 17:46:55 2018 +0900
+++ b/src/main/java/christie/test/Remote/StartRemotePut.java	Thu Jan 25 23:02:02 2018 +0900
@@ -16,7 +16,7 @@
         new StartRemotePut(cgm);
 
         cgm.createRemoteDGM("remote", "localhost", 10001);
-        cgm.setup(new CreateRemotePutTest( ));//この時点でcgm"second"は作られていない→notifyAllで対処?
+        cgm.setup(new CreateRemotePutTest());//この時点でcgm"second"は作られていない→notifyAllで対処?
 
         CodeGearManager cgm2 = createCGM(10001);
         cgm2.createRemoteDGM("remote", "localhost", 10000);
--- a/src/main/java/christie/test/RemoteTake/StartRemoteTake.java	Thu Jan 25 17:46:55 2018 +0900
+++ b/src/main/java/christie/test/RemoteTake/StartRemoteTake.java	Thu Jan 25 23:02:02 2018 +0900
@@ -5,13 +5,14 @@
 import christie.test.Remote.StartRemotePut;
 
 public class StartRemoteTake extends StartCodeGear{
+
     public StartRemoteTake(CodeGearManager cgm) {
         super(cgm);
     }
 
     public static void main(String args[]){
         CodeGearManager cgm = createCGM(10000);
-        new StartRemotePut(cgm);
+        new StartRemoteTake(cgm);
 
         cgm.createRemoteDGM("remote", "localhost", 10000);
         cgm.setup(new CreateRemoteTakeTest());