Mercurial > hg > Database > Christie
changeset 7:21372a589bd3
add CodeGearExecutor
author | Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 27 Dec 2017 18:42:46 +0900 |
parents | 3dcfe63d6394 |
children | efaa7ad906b3 |
files | src/main/java/christie/codegear/CodeGear.java src/main/java/christie/codegear/CodeGearExecutor.java src/main/java/christie/codegear/CodeGearManager.java src/main/java/christie/codegear/StartCodeGear.java src/main/java/christie/test/StartTest.java src/main/java/christie/test/TestCodeGear.java |
diffstat | 6 files changed, 40 insertions(+), 36 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/christie/codegear/CodeGear.java Wed Dec 27 00:06:50 2017 +0900 +++ b/src/main/java/christie/codegear/CodeGear.java Wed Dec 27 18:42:46 2017 +0900 @@ -13,24 +13,21 @@ * Created by e125769 on 12/7/17. * Annotationからのinputコマンドの生成、揃ったDataGearの値を返す */ -public abstract class CodeGear implements Runnable{ +public abstract class CodeGear{ public InputDataGear idg = new InputDataGear(this); public OutputDataGear odg = new OutputDataGear(this); public ArrayList<Command> commandList = new ArrayList<Command>(); public CodeGearManager cgm; - public DataGearManager dgm; - //public CodeGearExecutor cge; + public DataGearManager localDGM; + public CodeGearExecutor cge; - public CodeGear(CodeGearManager cgm){ + public void setup(CodeGearManager cgm){ this.cgm = cgm; - //this.cge = new CodeGearExecutor(); - this.dgm = cgm.getDGM(); - } - - public void execute() {//AnnotationからInputDataGearをセット + this.cge = new CodeGearExecutor(this, this.cgm); + this.localDGM = cgm.getDGM(); odg.initODG(cgm); - for (Field field : this.getClass().getDeclaredFields()) { + for (Field field : this.getClass().getDeclaredFields()) {//AnnotationからInputDataGearをセット DataGear dg = null; try { dg = (DataGear) field.get(this); @@ -50,4 +47,9 @@ idg.finishInput(cgm, commandList); } + protected abstract void run(CodeGearManager cgm); + + public DataGearManager dgm(String dest) { + return cgm.getDGM(dest); + } }
--- a/src/main/java/christie/codegear/CodeGearExecutor.java Wed Dec 27 00:06:50 2017 +0900 +++ b/src/main/java/christie/codegear/CodeGearExecutor.java Wed Dec 27 18:42:46 2017 +0900 @@ -11,6 +11,6 @@ @Override public void run() { - //cg.run(cgm); + cg.run(cgm); } }
--- a/src/main/java/christie/codegear/CodeGearManager.java Wed Dec 27 00:06:50 2017 +0900 +++ b/src/main/java/christie/codegear/CodeGearManager.java Wed Dec 27 18:42:46 2017 +0900 @@ -13,11 +13,11 @@ */ public class CodeGearManager{ private ConcurrentHashMap<String, DataGearManager> dataGearManagers = new ConcurrentHashMap<String, DataGearManager>(); - private ThreadPoolExecutor codeGearExecutor; + private ThreadPoolExecutor threadPoolExecutor; public CodeGearManager(ThreadPoolExecutor exe) { dataGearManagers.put("local", new LocalDataGearManager()); - codeGearExecutor = exe; + threadPoolExecutor = exe; } public DataGearManager getDGM(){ @@ -33,7 +33,11 @@ } public void submit(CodeGear cg){ - codeGearExecutor.execute(cg); + threadPoolExecutor.execute(cg.cge); + } + + public void setup(CodeGear cg){ + cg.setup(this); } }
--- a/src/main/java/christie/codegear/StartCodeGear.java Wed Dec 27 00:06:50 2017 +0900 +++ b/src/main/java/christie/codegear/StartCodeGear.java Wed Dec 27 18:42:46 2017 +0900 @@ -1,22 +1,21 @@ package christie.codegear; -import java.util.HashMap; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; -public abstract class StartCodeGear implements Runnable { - ConcurrentHashMap<String, CodeGearManager> cgms = new ConcurrentHashMap<>(); - LinkedBlockingQueue<Runnable> taskQueue = new LinkedBlockingQueue<Runnable>(); - ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(Runtime.getRuntime().availableProcessors(), // initial number of threads +public abstract class StartCodeGear extends CodeGear{ + static ConcurrentHashMap<String, CodeGearManager> cgms = new ConcurrentHashMap<>(); + static LinkedBlockingQueue<Runnable> taskQueue = new LinkedBlockingQueue<Runnable>(); + static ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(Runtime.getRuntime().availableProcessors(), // initial number of threads Runtime.getRuntime().availableProcessors(), Integer.MAX_VALUE, // keepAliveTime TimeUnit.SECONDS, taskQueue); - public CodeGearManager createCGM(String name){ + public static CodeGearManager createCGM(String name){ CodeGearManager cgm = new CodeGearManager(threadPoolExecutor); cgms.put(name, cgm); return cgm; @@ -26,8 +25,5 @@ return cgms.get(name); } - public void execute(){ - threadPoolExecutor.execute(this); - } }
--- a/src/main/java/christie/test/StartTest.java Wed Dec 27 00:06:50 2017 +0900 +++ b/src/main/java/christie/test/StartTest.java Wed Dec 27 18:42:46 2017 +0900 @@ -1,5 +1,6 @@ package christie.test; +import christie.codegear.CodeGearManager; import christie.codegear.StartCodeGear; import java.util.HashMap; @@ -7,20 +8,22 @@ public class StartTest extends StartCodeGear{ public static void main(String args[]){ - new StartTest().execute(); + CodeGearManager cgm = createCGM("first"); + cgm.setup(new StartTest()); } @Override - public void run() { - TestCodeGear test = new TestCodeGear(createCGM("first")); - test.execute(); - test.dgm.put("hoge", "hogehogehoge"); + protected void run(CodeGearManager cgm) { + TestCodeGear cg = new TestCodeGear(); + cgm.setup(cg); + + localDGM.put("hoge", "hogehogehoge"); int array[][] = {{1},{2},{3},{4}}; - test.dgm.put("huga", array); + localDGM.put("huga", array); HashMap<String, Integer> piyo= new HashMap<>(); piyo.put("piyoyo", 100); - test.dgm.put("piyo", piyo); + localDGM.put("piyo", piyo); } }
--- a/src/main/java/christie/test/TestCodeGear.java Wed Dec 27 00:06:50 2017 +0900 +++ b/src/main/java/christie/test/TestCodeGear.java Wed Dec 27 18:42:46 2017 +0900 @@ -23,16 +23,15 @@ @Peek("piyo") public DataGear piyo = new DataGear<HashMap<String, Integer>>(); - public TestCodeGear(CodeGearManager cgm) { - super(cgm); - } + public void run(CodeGearManager cgm){ + System.out.println("in run!"); - @Override - public void run(){ - System.out.println("in run!"); System.out.println(hoge.getData()); System.out.println(huga.getData()); System.out.println(piyo.getData()); + + localDGM.put("hoge", "hoge2");//Queueにしないといけない + //dgm("remote").put("hoge", "hoge3"); } }