Mercurial > hg > Database > Christie
changeset 1:3ea61d0bfc34
add dependency proccess but not work
author | Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 11 Dec 2017 21:19:25 +0900 |
parents | c082039368f5 |
children | bacdcb5e6dcf |
files | build.gradle src/main/java/christie/codegear/CodeGear.java src/main/java/christie/codegear/CodeGearManager.java src/main/java/christie/codegear/Command.java src/main/java/christie/codegear/CommandType.java src/main/java/christie/codegear/GodeGearManager.java src/main/java/christie/codegear/InputDataGear.java src/main/java/christie/codegear/OutputDataGear.java src/main/java/christie/codegear/StartCodeGear.java src/main/java/christie/datagear/DataGearManager.java src/main/java/christie/datagear/LocalDataGearManager.java src/main/java/christie/datagear/RemoteDataGearManager.java src/main/java/christie/datagear/StringData.java src/main/java/christie/test/StartTest.java src/main/java/christie/test/TestCodeGear.java |
diffstat | 15 files changed, 258 insertions(+), 30 deletions(-) [+] |
line wrap: on
line diff
--- a/build.gradle Thu Dec 07 21:45:59 2017 +0900 +++ b/build.gradle Mon Dec 11 21:19:25 2017 +0900 @@ -1,6 +1,9 @@ apply plugin: 'java' +apply plugin: 'eclipse' +apply plugin: 'maven' -sourceCompatibility = 1.9 +sourceCompatibility = 1.9; +targetCompatibility = 1.9; [compileJava, compileTestJava]*.options*.encoding = 'UTF-8' group = 'cr.ie.u_ryukyu.ac.jp' @@ -11,7 +14,7 @@ } dependencies { - testCompile group: 'junit', name: 'junit', version: '4.11' + testCompile group: 'junit', name: 'junit', version: '4.21' } jar {
--- a/src/main/java/christie/codegear/CodeGear.java Thu Dec 07 21:45:59 2017 +0900 +++ b/src/main/java/christie/codegear/CodeGear.java Mon Dec 11 21:19:25 2017 +0900 @@ -2,6 +2,7 @@ import christie.annotation.Take; import christie.datagear.DataGear; +import christie.datagear.DataGearManager; import christie.datagear.StringData; import java.lang.reflect.Field; @@ -10,24 +11,45 @@ /** * Created by e125769 on 12/7/17. + * Annotationからのinputコマンドの生成、揃ったDataGearの値を返す */ -public interface CodeGear extends Runnable { +public interface CodeGear extends Runnable{ InputDataGear idg = new InputDataGear(); OutputDataGear odg = new OutputDataGear(); - + //CodeGearManager cgm = null; + ArrayList<Command> commandList = new ArrayList<Command>(); - default void setKey(){//AnnotationからInputDataGearをセット らidgに待ち合わせ + default void setKey(CodeGearManager cgm){//AnnotationからInputDataGearをセット for (Field field : this.getClass().getDeclaredFields()) { + if (field.isAnnotationPresent(Take.class)){//何故かここに入らない + Take ano = field.getAnnotation(Take.class); + System.out.println(ano.value()); + commandList.add(new Command(this, null, "local", ano.value(), CommandType.TAKE)); + } + } + idg.finishInput(cgm, this, commandList); + } + + default void setValue(){//Annotationから揃ったInputDataGearの値をキャスト + for (Field field : this.getClass().getDeclaredFields()) { + field.setAccessible(true); if (field.isAnnotationPresent(Take.class)){ Take ano = field.getAnnotation(Take.class); - System.out.println(ano.value()); - //idg.dataGears.put(ano.value(), field.get()); + try { + field.set(this, idg.inputs.get(ano.value()));//ダウンキャストできるか? + } catch (IllegalAccessException e) { + e.printStackTrace(); + } } } } - default void setValue(){//Annotationから揃ったInputDataGearの値をキャスト + default void put(String key, Object data){ + //cgm.getDGM("local").put(key, new DataGear(data)); + } + default void put(String dist, String key, Object data){ + //cgm.getDGM(dist).put(key, new DataGear(data)); } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/christie/codegear/CodeGearManager.java Mon Dec 11 21:19:25 2017 +0900 @@ -0,0 +1,38 @@ +package christie.codegear; + +import christie.datagear.DataGearManager; +import christie.datagear.LocalDataGearManager; +import christie.datagear.RemoteDataGearManager; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.ThreadFactory; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; + +/** + * Created by e125769 on 12/7/17. + * CodeGearの実行 + */ +public class CodeGearManager{ + private HashMap<String, DataGearManager> dataGearManagers = new HashMap<String, DataGearManager>(); + private ThreadPoolExecutor codeGearExecutor; + + public CodeGearManager(ThreadPoolExecutor exe) { + dataGearManagers.put("local", new LocalDataGearManager()); + codeGearExecutor = exe; + } + + public void submit(CodeGear cg){ + codeGearExecutor.execute(cg); + } + + public DataGearManager getDGM(String dest){ + return dataGearManagers.get(dest); + } + + public void createRemoteDataGeareManager(String dist){ + dataGearManagers.put(dist, new RemoteDataGearManager()); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/christie/codegear/Command.java Mon Dec 11 21:19:25 2017 +0900 @@ -0,0 +1,20 @@ +package christie.codegear; + +import christie.datagear.DataGear; + +public class Command { + public CodeGear cs; + public DataGear dg; + public String dest; + public String key; + public CommandType type; + + public Command(CodeGear cs, DataGear dg, String dest, String key, CommandType type){ + this.cs = cs; + this.dg = dg; + this.dest = dest; + this.key = key; + this.type = type; + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/christie/codegear/CommandType.java Mon Dec 11 21:19:25 2017 +0900 @@ -0,0 +1,8 @@ +package christie.codegear; + +import java.util.HashMap; + +public enum CommandType { + PUT, + TAKE; +}
--- a/src/main/java/christie/codegear/GodeGearManager.java Thu Dec 07 21:45:59 2017 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,14 +0,0 @@ -package christie.codegear; - -import christie.datagear.DataGearManager; - -import java.util.HashMap; -import java.util.concurrent.ThreadPoolExecutor; - -/** - * Created by e125769 on 12/7/17. - */ -public class GodeGearManager{ - HashMap<String, DataGearManager> dataGearManagers = new HashMap<String, DataGearManager>(); - ThreadPoolExecutor codeGearExecutor; -}
--- a/src/main/java/christie/codegear/InputDataGear.java Thu Dec 07 21:45:59 2017 +0900 +++ b/src/main/java/christie/codegear/InputDataGear.java Mon Dec 11 21:19:25 2017 +0900 @@ -2,11 +2,51 @@ import christie.datagear.DataGear; +import java.util.ArrayList; import java.util.HashMap; /** * Created by e125769 on 12/7/17. + * inputDataGearの待ち合わせの管理 */ public class InputDataGear { - HashMap<String, DataGear> dataGears = new HashMap<String, DataGear>(); + HashMap<String, DataGear> inputs = new HashMap<String, DataGear>();//受け皿 + CodeGearManager cgm; + CodeGear cg; + int count = 0; + + void finishInput(CodeGearManager cgm, CodeGear cg, ArrayList<Command> commandList){ + this.cgm = cgm; + this.cg = cg; + count = commandList.size(); + + if(count == 0){ + submitCG(); + } + + for(Command cm : commandList){ + if (cgm.getDGM(cm.dest).dataGears.containsKey(cm.key)) { + this.cgm.getDGM(cm.dest).runCommand(cm); + } else { + this.cgm.getDGM(cm.dest).addWaitList(cm);//全体のinputにこのCGのinputを追加 + } + } + } + + public void setInputs(String key, DataGear value){ + inputs.put(key, value); + count(); + } + + public void count(){//Commandが実行されるたびにデクリメント + if (--count == 0){ + cg.setValue(); + submitCG(); + } + } + + void submitCG(){ + cgm.submit(cg); + } + }
--- a/src/main/java/christie/codegear/OutputDataGear.java Thu Dec 07 21:45:59 2017 +0900 +++ b/src/main/java/christie/codegear/OutputDataGear.java Mon Dec 11 21:19:25 2017 +0900 @@ -1,7 +1,20 @@ package christie.codegear; +import christie.datagear.DataGear; + /** * Created by e125769 on 12/7/17. */ public class OutputDataGear { + CodeGearManager cgm; + CodeGear cg; + + public void initODG(CodeGearManager cgm, CodeGear cg){ + this.cgm = cgm; + this.cg = cg; + } + + public void put(String key,DataGear dg){ + cgm.getDGM("local").put(key, dg); + } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/christie/codegear/StartCodeGear.java Mon Dec 11 21:19:25 2017 +0900 @@ -0,0 +1,19 @@ +package christie.codegear; + +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; + +public interface StartCodeGear { + default CodeGearManager createCodeGearManager(ThreadPoolExecutor exe){ + return new CodeGearManager(exe); + } + + default ThreadPoolExecutor createThreadPool(){ + return new ThreadPoolExecutor(Runtime.getRuntime().availableProcessors(), // initial number of threads + Runtime.getRuntime().availableProcessors(), + Integer.MAX_VALUE, // keepAliveTime + TimeUnit.SECONDS, + new LinkedBlockingQueue<Runnable>()); + } +}
--- a/src/main/java/christie/datagear/DataGearManager.java Thu Dec 07 21:45:59 2017 +0900 +++ b/src/main/java/christie/datagear/DataGearManager.java Mon Dec 11 21:19:25 2017 +0900 @@ -1,14 +1,25 @@ package christie.datagear; +import christie.codegear.CodeGear; +import christie.codegear.Command; import christie.datagear.DataGear; +import java.util.ArrayList; +import java.util.HashMap; import java.util.TreeMap; /** * Created by e125769 on 12/7/17. + * PUT/TAKEなどDataGearManagerに対するComandの実行。 */ public interface DataGearManager { TreeMap<String, DataGear> dataGears = new TreeMap<String, DataGear>(); - DataGear take(String key); + HashMap<String, Command> waitList = new HashMap<String, Command>(); + void take(String key); void put(String key, DataGear data); + void runCommand(Command cm); + + default void addWaitList(Command command){ + waitList.put(command.key, command); + } }
--- a/src/main/java/christie/datagear/LocalDataGearManager.java Thu Dec 07 21:45:59 2017 +0900 +++ b/src/main/java/christie/datagear/LocalDataGearManager.java Mon Dec 11 21:19:25 2017 +0900 @@ -1,16 +1,33 @@ package christie.datagear; +import christie.codegear.Command; + /** * Created by e125769 on 12/7/17. */ public class LocalDataGearManager implements DataGearManager { - public DataGear take(String key) { - return null; + public void take(String key) { + } public void put(String key, DataGear data) { + dataGears.put(key, data); + if (waitList.containsKey(key)){ + waitList.get(key).dg = data; + runCommand(waitList.get(key)); + } + } + + public void runCommand(Command cm){ + switch (cm.type){ + case TAKE: + cm.cs.idg.setInputs(cm.key, cm.dg); + dataGears.remove(cm.key); + break; + } + waitList.remove(cm.key); } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/christie/datagear/RemoteDataGearManager.java Mon Dec 11 21:19:25 2017 +0900 @@ -0,0 +1,20 @@ +package christie.datagear; + +import christie.codegear.Command; + +public class RemoteDataGearManager implements DataGearManager{ + @Override + public void take(String key) { + + } + + @Override + public void put(String key, DataGear data) { + + } + + @Override + public void runCommand(Command cm) { + + } +}
--- a/src/main/java/christie/datagear/StringData.java Thu Dec 07 21:45:59 2017 +0900 +++ b/src/main/java/christie/datagear/StringData.java Mon Dec 11 21:19:25 2017 +0900 @@ -8,6 +8,12 @@ Class<T> clazz; T data; + public StringData(String s){ + setData(s); + setClazz(String.class); + } + + public Class getClazz() { return clazz; }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/christie/test/StartTest.java Mon Dec 11 21:19:25 2017 +0900 @@ -0,0 +1,18 @@ +package christie.test; + +import christie.codegear.CodeGearManager; +import christie.codegear.StartCodeGear; +import christie.datagear.StringData; + +import java.util.concurrent.ThreadPoolExecutor; + +public class StartTest implements StartCodeGear{ + public static void main(String args[]){ + StartTest start = new StartTest(); + TestCodeGear test = new TestCodeGear(); + CodeGearManager cgm = start.createCodeGearManager(start.createThreadPool()); + test.setKey(cgm); + test.odg.initODG(cgm, test); + test.odg.put("hoge", new StringData("hogehogehoge")); + } +}
--- a/src/main/java/christie/test/TestCodeGear.java Thu Dec 07 21:45:59 2017 +0900 +++ b/src/main/java/christie/test/TestCodeGear.java Mon Dec 11 21:19:25 2017 +0900 @@ -2,8 +2,10 @@ import christie.annotation.Take; import christie.codegear.CodeGear; +import christie.codegear.CodeGearManager; import christie.datagear.StringData; + /** * Created by e125769 on 12/7/17. */ @@ -12,11 +14,16 @@ @Take("hoge") StringData hoge; - public static void main(String args[]){ - System.out.println("hello"); - } + /*public static void main(String args[]){ + TestCodeGear test = new TestCodeGear(); + CodeGearManager cgm = new CodeGearManager(); + test.setKey(cgm); + test.odg.initODG(cgm, test); + odg.put("hoge", new StringData("hogehogehoge")); + }*/ public void run() { - //System.out.println(hoge.getData()); + System.out.println("in run!"); + System.out.println(hoge.getData()); } }