Mercurial > hg > Database > Alice
changeset 415:79a0c18dd2c3 dispose
Merge with 5b05279291a161ad8bfa16b0bcb674ee0a83c96a
author | sugi |
---|---|
date | Mon, 07 Jul 2014 16:41:25 +0900 |
parents | b42eee3348b2 (diff) 5b05279291a1 (current diff) |
children | 6508ed6ea6a6 |
files | .classpath .project .settings/org.eclipse.jdt.core.prefs lib/j3d-core-1.3.1.jar lib/j3dutils.jar lib/vecmath-1.5.2.jar |
diffstat | 9 files changed, 262 insertions(+), 60 deletions(-) [+] |
line wrap: on
line diff
--- a/.classpath Thu Jul 03 14:48:43 2014 +0900 +++ b/.classpath Mon Jul 07 16:41:25 2014 +0900 @@ -6,8 +6,6 @@ <classpathentry kind="src" path="src/test/java"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER" exported="true"/> <classpathentry kind="lib" path="/Users/YU/workspace/Alice/lib/com.alexmerz.graphviz.jar" exported="true"/> - <classpathentry kind="lib" path="/Users/YU/workspace/Alice/lib/j3d-core-1.3.1.jar" exported="true"/> - <classpathentry kind="lib" path="/Users/YU/workspace/Alice/lib/j3dutils.jar" exported="true"/> <classpathentry kind="lib" path="/Users/YU/workspace/Alice/lib/javassist.jar" exported="true"/> <classpathentry kind="lib" path="/Users/YU/workspace/Alice/lib/jimColModelImporterJFX.jar" exported="true"/> <classpathentry kind="lib" path="/Users/YU/workspace/Alice/lib/jimObjModelImporterJFX.jar" exported="true"/> @@ -18,5 +16,4 @@ <classpathentry kind="lib" path="/Users/YU/workspace/Alice/lib/slf4j-api-1.6.1.jar" exported="true"/> <classpathentry kind="lib" path="/Users/YU/workspace/Alice/lib/slf4j-log4j12-1.6.1-sources.jar" exported="true"/> <classpathentry kind="lib" path="/Users/YU/workspace/Alice/lib/slf4j-log4j12-1.6.1.jar" exported="true"/> - <classpathentry kind="lib" path="/Users/YU/workspace/Alice/lib/vecmath-1.5.2.jar" exported="true"/> </classpath>
--- a/.settings/org.eclipse.jdt.core.prefs Thu Jul 03 14:48:43 2014 +0900 +++ b/.settings/org.eclipse.jdt.core.prefs Mon Jul 07 16:41:25 2014 +0900 @@ -1,5 +1,5 @@ # -#Wed Jul 02 15:56:17 JST 2014 +#Mon Jul 07 16:33:01 JST 2014 org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.compliance=1.8 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
--- a/src/main/java/alice/daemon/dispose/DisposeManager.java Thu Jul 03 14:48:43 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,22 +0,0 @@ -package alice.daemon.dispose; - -import alice.codesegment.CodeSegment; - -public class DisposeManager extends CodeSegment{ - private static DisposeManager instance = new DisposeManager(); - - private DisposeManager(){} - public static DisposeManager getInstance(){ - return instance; - } - - @Override - public void run() { - - - } - - public synchronized void setCodeSegment(String managerKey, CodeSegment cs){ - ods.put("_DISPOSE"+managerKey, cs); - } -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/reflection/CloseEventManager.java Mon Jul 07 16:41:25 2014 +0900 @@ -0,0 +1,93 @@ +package alice.test.reflection; + +import javassist.CannotCompileException; +import javassist.ClassPool; +import javassist.CtClass; +import javassist.CtConstructor; +import javassist.CtField; +import javassist.NotFoundException; + + +public class CloseEventManager { + public static CloseEventManager closeManager = new CloseEventManager(); + + private CloseEventManager(){} + public static CloseEventManager getInstance(){ + return closeManager; + } + private ClassPool cp = ClassPool.getDefault(); + + public <T> void setCodeSegment(String managerKey, Class<T> clazz){ + System.out.println("convert class name "+clazz.getName()); + CtClass cs = null; + String metaName = clazz.getSimpleName()+"Meta"; + try { + // if cannot get mataName Class go catch NotFoundException + cs = cp.get(clazz.getName()+"Meta"); + // already created + Class<?> metaClazz = cp.getClassLoader().loadClass(metaName); + metaClazz.newInstance(); + } catch (ClassNotFoundException e) { + System.out.println("ClassLoder loadClass error"); + e.printStackTrace(); + } catch (InstantiationException e) { + System.out.println("newInstance() error"); + } catch (IllegalAccessException e) { + System.out.println("newInstance() error"); + } catch (NotFoundException e) { + try { + CtClass parent = cp.get(clazz.getName()); + + // check super class is CS + boolean checkSuperClass = parent.getSuperclass().getSimpleName().equals("CodeSegment"); + if (!checkSuperClass) { + // argument wrong + return; + } else { + cs = cp.get(clazz.getName()); + + // define meta inputDataSegment + CtClass receiver = cp.get("alice.datasegment.Receiver"); + + // need check exist field name + String metaFieldName = "metaInfo"; + CtField cf = new CtField(receiver ,metaFieldName, cs); + cs.addField(cf, "ids.create(alice.datasegment.CommandType.TAKE)"); + + CtConstructor[] ccArray = cs.getConstructors(); + CtConstructor cc = null; + for (int i = 0; i < ccArray.length; i++){ + if (ccArray[i].getName().equals(clazz.getSimpleName())) + cc = ccArray[i]; + } + String metaSetKey = metaFieldName+".setKey(\"TEST\");"; + + String meta = "System.out.println(\"test\");"; + String meta2 = "System.out.println(list.size());"; + System.out.println(cc.isConstructor()); + cc.insertAfter(metaSetKey); + cc.insertAfter(meta); + cc.insertAfter(meta2); + + cs.setName(metaName); + + Class<?> metaClass = cs.toClass(); + cp.get(cs.getName()); + System.out.println(cs.getName()); + metaClass.newInstance(); + } + } catch (NotFoundException e1) { + System.out.println("not found super Class"); + return; + } catch (CannotCompileException e1) { + e1.printStackTrace(); + } catch (InstantiationException e1) { + e1.printStackTrace(); + } catch (IllegalAccessException e1) { + e1.printStackTrace(); + } + } + } + + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/reflection/DisposeManager.java Mon Jul 07 16:41:25 2014 +0900 @@ -0,0 +1,80 @@ +package alice.test.reflection; + +import javassist.CannotCompileException; +import javassist.ClassPool; +import javassist.CtClass; +import javassist.CtField; +import javassist.CtNewConstructor; +import javassist.NotFoundException; + +public class DisposeManager { + private static DisposeManager instance = new DisposeManager(); + private ClassPool cp = ClassPool.getDefault(); + + private DisposeManager(){} + + public static DisposeManager getInstance(){ + return instance; + } + + public <T> void setCodeSegment(String managerKey, Class<T> clazz){ + CtClass cs = null; + String metaName = "Meta"+clazz.getSimpleName(); + try { + // if cannot get mataName Class go catch NotFoundException + cs = cp.get(metaName); + // already created + Class<?> metaClazz = cp.getClassLoader().loadClass(metaName); + metaClazz.newInstance(); + } catch (ClassNotFoundException e) { + System.out.println("ClassLoder loadClass error"); + e.printStackTrace(); + } catch (InstantiationException e) { + System.out.println("newInstance() error"); + } catch (IllegalAccessException e) { + System.out.println("newInstance() error"); + } catch (NotFoundException e) { + try { + CtClass parent = cp.get(clazz.getName()); + + // check super class is CS + boolean checkSuperClass = parent.getSuperclass().getSimpleName().equals("CodeSegment"); + if (!checkSuperClass) { + // argument wrong + return; + } else { + cs = cp.makeClass("Meta"+clazz.getSimpleName()); + cs.setSuperclass(parent); + + // define meta inputDataSegment + CtClass receiver = cp.get("alice.datasegment.Receiver"); + + // need check exist name + String metaFieldName = "metaInfo"; + + CtField cf = new CtField(receiver ,metaFieldName, cs); + cs.addField(cf, "ids.create(alice.datasegment.CommandType.PEEK)"); + + String cnst = "public "+metaName+"(){" + + metaFieldName+".setKey(\"TEST\");" + + "}"; + + cs.addConstructor(CtNewConstructor.make(cnst, cs)); + + Class<?> metaClass = cs.toClass(); + metaClass.newInstance(); + } + } catch (NotFoundException e1) { + System.out.println("not found super Class"); + return; + } catch (CannotCompileException e1) { + e1.printStackTrace(); + } catch (InstantiationException e1) { + e1.printStackTrace(); + } catch (IllegalAccessException e1) { + e1.printStackTrace(); + } + } + + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/reflection/DisposeManagerTest.java Mon Jul 07 16:41:25 2014 +0900 @@ -0,0 +1,17 @@ +package alice.test.reflection; + +import alice.daemon.AliceDaemon; +import alice.daemon.Config; + +public class DisposeManagerTest { + public static void main(String[] args){ + new AliceDaemon(new Config(args)).listen(); // logger off + CSTemplate cs = new CSTemplate(); + cs.ods.put("key1", "String data"); + cs.ods.put("TEST", "TEST"); + //DisposeManager.getInstance().setCodeSegment("local", MetaCodeSegment.class); + //CloseEventManager.getInstance().setCodeSegment("local", MetaCodeSegment.class); + CloseEventManager.getInstance().setCodeSegment("local", alice.test.reflection.MetaCodeSegment.class); + + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/test/reflection/MetaCodeSegment.java Mon Jul 07 16:41:25 2014 +0900 @@ -0,0 +1,36 @@ +package alice.test.reflection; + +import org.msgpack.type.Value; + +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +import alice.datasegment.Receiver; + +public class MetaCodeSegment extends CodeSegment { + + // create input datasegment arg1 + Receiver arg1 = ids.create(CommandType.TAKE); + + public MetaCodeSegment(){ + arg1.setKey("key1", arg1.index); + } + + @Override + public void run() { + System.out.println("type = " + arg1.type); + System.out.println("index = " + arg1.index); + System.out.println("data = " + arg1.getVal()); + System.out.println(((Value)arg1.getVal()).getType()); + + if (arg1.index == 10) { + System.exit(0); + return; + } + System.out.println(MetaCodeSegment.class); + //DisposeManager.getInstance().setCodeSegment("local", MetaCodeSegment.class); + CloseEventManager.getInstance().setCodeSegment("local", MetaCodeSegment.class); + // DataSegment.get("local").update + //ods.update("local", "key1", "String data"); + } + +} \ No newline at end of file
--- a/src/main/java/alice/topology/manager/IncomingHosts.java Thu Jul 03 14:48:43 2014 +0900 +++ b/src/main/java/alice/topology/manager/IncomingHosts.java Mon Jul 07 16:41:25 2014 +0900 @@ -12,38 +12,40 @@ import alice.topology.HostMessage; public class IncomingHosts extends CodeSegment { - - HashMap<String, LinkedList<NodeInfo>> topology; - LinkedList<String> nodeNames; - Receiver host = ids.create(CommandType.TAKE); - - public IncomingHosts(HashMap<String, LinkedList<NodeInfo>> topology, LinkedList<String> nodeNames) { - this.topology = topology; - this.nodeNames = nodeNames; - } + + HashMap<String, LinkedList<NodeInfo>> topology; + LinkedList<String> nodeNames; + Receiver host = ids.create(CommandType.TAKE); + + public IncomingHosts(HashMap<String, LinkedList<NodeInfo>> topology, + LinkedList<String> nodeNames) { + this.topology = topology; + this.nodeNames = nodeNames; + this.host.setKey("local", "host"); + } - @Override - public void run() { - HostMessage host = this.host.asClass(HostMessage.class); - String nodeName = nodeNames.poll(); - // Manager connect to Node - DataSegment.connect(nodeName, "", host.name, host.port); - ods.put(nodeName, "host", nodeName); - LinkedList<NodeInfo> nodes = topology.get(nodeName); - for (NodeInfo nodeInfo : nodes) { - HostMessage newHost = new HostMessage(host.name, host.port, nodeInfo.connectionName, nodeInfo.reverseName); - ods.put("local", nodeInfo.sourceNodeName, newHost); - } - - if (nodeNames.isEmpty()) { - // configuration finish - for (String key : topology.keySet()) { - ods.put("local", key, ValueFactory.createNilValue()); - } - } else { - IncomingHosts cs = new IncomingHosts(topology, nodeNames); - cs.host.setKey("local", "host"); - } - } + @Override + public void run() { + HostMessage host = this.host.asClass(HostMessage.class); + String nodeName = nodeNames.poll(); + // Manager connect to Node + DataSegment.connect(nodeName, "", host.name, host.port); + ods.put(nodeName, "host", nodeName); + LinkedList<NodeInfo> nodes = topology.get(nodeName); + for (NodeInfo nodeInfo : nodes) { + HostMessage newHost = new HostMessage(host.name, host.port, + nodeInfo.connectionName, nodeInfo.reverseName); + ods.put("local", nodeInfo.sourceNodeName, newHost); + } + + if (nodeNames.isEmpty()) { + // configuration finish + for (String key : topology.keySet()) { + ods.put("local", key, ValueFactory.createNilValue()); + } + } else { + new IncomingHosts(topology, nodeNames); + } + } }
--- a/src/main/java/alice/topology/manager/StartTopologyManager.java Thu Jul 03 14:48:43 2014 +0900 +++ b/src/main/java/alice/topology/manager/StartTopologyManager.java Mon Jul 07 16:41:25 2014 +0900 @@ -76,8 +76,7 @@ e.printStackTrace(); } - IncomingHosts cs1 = new IncomingHosts(topology, nodeNames); - cs1.host.setKey("local", "host"); + new IncomingHosts(topology, nodeNames); ConfigWaiter cs3 = new ConfigWaiter(nodeNum); cs3.done.setKey("local", "done");