Mercurial > hg > Database > Alice
changeset 335:2f003d5703d5 META_CODESEGMENT
Meta CodeSegment Test
author | sugi |
---|---|
date | Mon, 14 Apr 2014 15:46:29 +0900 |
parents | c0c00f8f5525 |
children | 5fa184113850 |
files | src/alice/codesegment/CodeSegment.java src/alice/codesegment/CodeSegmentManager.java src/alice/codesegment/MetaCodeSegment.java src/alice/test/codesegment/api/PrintNumber.java src/alice/test/codesegment/api/PrintText.java src/alice/test/codesegment/api/TestMetaCodeSegment.java src/alice/topology/manager/StartTopologyManager.java |
diffstat | 7 files changed, 127 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/src/alice/codesegment/CodeSegment.java Mon Apr 07 20:37:38 2014 +0900 +++ b/src/alice/codesegment/CodeSegment.java Mon Apr 14 15:46:29 2014 +0900 @@ -10,6 +10,13 @@ public InputDataSegment ids = new InputDataSegment(this); public OutputDataSegment ods = new OutputDataSegment(); public ArrayList<Receiver> list = new ArrayList<Receiver>(); + public CodeSegment codeSegment; + private Class<CodeSegment> meta; + private boolean flag = false; + + public void setKey(){ + // for meta CodeSegment + } public void execute() { ids.receive(); @@ -23,4 +30,27 @@ } } + @SuppressWarnings("unchecked") + public <T> void setMeta(Class<T> cs){ + flag = true; + meta = (Class<CodeSegment>) cs; + } + + public boolean hasMeta(){ + return flag; + } + + public void setCodeSegment(CodeSegment cs){ + codeSegment = cs; + } + + public CodeSegment getCodeSegment(){ + return codeSegment; + } + + public Class<CodeSegment> getMetaClass(){ + flag = false; + return meta; + } + }
--- a/src/alice/codesegment/CodeSegmentManager.java Mon Apr 07 20:37:38 2014 +0900 +++ b/src/alice/codesegment/CodeSegmentManager.java Mon Apr 14 15:46:29 2014 +0900 @@ -10,10 +10,10 @@ private static CodeSegmentManager instance = new CodeSegmentManager(); private ThreadPoolExecutor codeSegmentExecutor = new ThreadPoolExecutor(Runtime.getRuntime().availableProcessors(), // initial number of threads - Runtime.getRuntime().availableProcessors(), - Integer.MAX_VALUE, // keepAliveTime - TimeUnit.SECONDS, - new LinkedBlockingQueue<Runnable>()); + Runtime.getRuntime().availableProcessors(), + Integer.MAX_VALUE, // keepAliveTime + TimeUnit.SECONDS, + new LinkedBlockingQueue<Runnable>()); private Logger logger = Logger.getLogger(CodeSegmentManager.class); public static CodeSegmentManager get() { @@ -21,11 +21,23 @@ } public static void submit(CodeSegment cs) { - CodeSegmentManager csManager = CodeSegmentManager.get(); - csManager.codeSegmentExecutor.execute(cs); - if (csManager.logger.isDebugEnabled()) { - csManager.logger.debug(cs.getClass().getName()); + if (cs.hasMeta()){ + try { + CodeSegment meta = cs.getMetaClass().newInstance(); + meta.setCodeSegment(cs); + meta.setKey(); + + } catch (Exception e) { + e.printStackTrace(); + } + + } else { + CodeSegmentManager csManager = CodeSegmentManager.get(); + csManager.codeSegmentExecutor.execute(cs); + if (csManager.logger.isDebugEnabled()) { + csManager.logger.debug(cs.getClass().getName()); + } } } - + }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/alice/codesegment/MetaCodeSegment.java Mon Apr 14 15:46:29 2014 +0900 @@ -0,0 +1,5 @@ +package alice.codesegment; + +public abstract class MetaCodeSegment extends CodeSegment{ + abstract public void setKey(); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/alice/test/codesegment/api/PrintNumber.java Mon Apr 14 15:46:29 2014 +0900 @@ -0,0 +1,28 @@ +package alice.test.codesegment.api; + +import alice.codesegment.CodeSegment; +import alice.codesegment.CodeSegmentManager; +import alice.datasegment.CommandType; +import alice.datasegment.Receiver; + +public class PrintNumber extends CodeSegment { + private Receiver info1 = ids.create(CommandType.PEEK); + + public PrintNumber(){ + ods.put("TEST1", 123); + + } + + @Override + public void run() { + Integer num = info1.asInteger(); + System.out.println(num); + CodeSegmentManager.submit(codeSegment);// javassist + + } + + public void setKey() { + info1.setKey("TEST1"); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/alice/test/codesegment/api/PrintText.java Mon Apr 14 15:46:29 2014 +0900 @@ -0,0 +1,23 @@ +package alice.test.codesegment.api; + +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +import alice.datasegment.Receiver; + +public class PrintText extends CodeSegment { + private Receiver info1 = ids.create(CommandType.PEEK); + + public PrintText(){ + setMeta(PrintNumber.class); + info1.setKey("TEST"); + } + + @Override + public void run() { + String str = info1.asString(); + System.out.println(str); + + new PrintText(); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/alice/test/codesegment/api/TestMetaCodeSegment.java Mon Apr 14 15:46:29 2014 +0900 @@ -0,0 +1,19 @@ +package alice.test.codesegment.api; + +import alice.codesegment.CodeSegment; +import alice.daemon.AliceDaemon; +import alice.daemon.Config; + +public class TestMetaCodeSegment extends CodeSegment{ + public static void main(String[] args){ + new AliceDaemon(new Config(args)).listen(); + new TestMetaCodeSegment().execute(); + } + + @Override + public void run() { + new PrintText(); + ods.put("TEST", "START"); + } + +}
--- a/src/alice/topology/manager/StartTopologyManager.java Mon Apr 07 20:37:38 2014 +0900 +++ b/src/alice/topology/manager/StartTopologyManager.java Mon Apr 14 15:46:29 2014 +0900 @@ -74,6 +74,7 @@ logger.error("File format error: " + conf.confFilePath); e.printStackTrace(); } + HashMap<String, ArrayList<HostMessage>> connectionList = new HashMap<String, ArrayList<HostMessage>>(); ods.put("connection", connectionList); ods.put("_ABSIPTABLE" ,new ArrayList<HostMessage>());