Mercurial > hg > Database > Alice
changeset 469:b31b1d197c42 dispose
Add Disconnect Event Manager
author | sugi |
---|---|
date | Sun, 23 Nov 2014 22:14:30 +0900 |
parents | 27079619f5fd |
children | 780ae843cdac |
files | src/main/java/alice/topology/manager/CloseEventCodeSegment.java src/main/java/alice/topology/manager/keeparive/CatchDisconnectEvent.java src/main/java/alice/topology/manager/keeparive/ListManager.java src/main/java/alice/topology/node/CloseEventCodeSegment.java src/main/java/alice/topology/node/ConfigurationFinish.java src/main/java/alice/topology/node/DisconnectEventManager.java src/main/java/alice/topology/node/ExecuteEvent.java src/main/java/alice/topology/node/RegisterEvent.java |
diffstat | 8 files changed, 146 insertions(+), 22 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/alice/topology/manager/CloseEventCodeSegment.java Sat Nov 22 18:07:24 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,20 +0,0 @@ -package alice.topology.manager; - -import alice.codesegment.CodeSegment; -import alice.daemon.ConnectionInfo; -import alice.datasegment.CommandType; -import alice.datasegment.Receiver; - -public abstract class CloseEventCodeSegment extends CodeSegment { - - private Receiver metaInfo = ids.create(CommandType.PEEK); - - public CloseEventCodeSegment(){ - metaInfo.setKey("disconnect"); - } - - public ConnectionInfo getConnectionInfo() { - return metaInfo.asClass(ConnectionInfo.class); - } - -}
--- a/src/main/java/alice/topology/manager/keeparive/CatchDisconnectEvent.java Sat Nov 22 18:07:24 2014 +0900 +++ b/src/main/java/alice/topology/manager/keeparive/CatchDisconnectEvent.java Sun Nov 23 22:14:30 2014 +0900 @@ -1,7 +1,7 @@ package alice.topology.manager.keeparive; import alice.daemon.ConnectionInfo; -import alice.topology.manager.CloseEventCodeSegment; +import alice.topology.node.CloseEventCodeSegment; public class CatchDisconnectEvent extends CloseEventCodeSegment{
--- a/src/main/java/alice/topology/manager/keeparive/ListManager.java Sat Nov 22 18:07:24 2014 +0900 +++ b/src/main/java/alice/topology/manager/keeparive/ListManager.java Sun Nov 23 22:14:30 2014 +0900 @@ -29,7 +29,7 @@ add(newInfo); } } - show(); + //show(); need debug option } private void add(TaskInfo newInfo){
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/topology/node/CloseEventCodeSegment.java Sun Nov 23 22:14:30 2014 +0900 @@ -0,0 +1,16 @@ +package alice.topology.node; + +import alice.codesegment.CodeSegment; +import alice.daemon.ConnectionInfo; +import alice.datasegment.CommandType; +import alice.datasegment.Receiver; + +public abstract class CloseEventCodeSegment extends CodeSegment { + + public Receiver metaInfo = ids.create(CommandType.PEEK); + + public ConnectionInfo getConnectionInfo() { + return metaInfo.asClass(ConnectionInfo.class); + } + +}
--- a/src/main/java/alice/topology/node/ConfigurationFinish.java Sat Nov 22 18:07:24 2014 +0900 +++ b/src/main/java/alice/topology/node/ConfigurationFinish.java Sun Nov 23 22:14:30 2014 +0900 @@ -5,6 +5,7 @@ import alice.codesegment.CodeSegment; import alice.datasegment.CommandType; import alice.datasegment.Receiver; +import alice.topology.manager.keeparive.CatchDisconnectEvent; public class ConfigurationFinish extends CodeSegment { @@ -24,6 +25,9 @@ ods.put("manager", "done", ValueFactory.createNilValue()); Start cs = new Start(startCS); cs.done.setKey("manager", "start"); + + DisconnectEventManager.getInstance().setKey(); + DisconnectEventManager.getInstance().register(CatchDisconnectEvent.class); return; }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/topology/node/DisconnectEventManager.java Sun Nov 23 22:14:30 2014 +0900 @@ -0,0 +1,39 @@ +package alice.topology.node; + +import java.util.ArrayList; + +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +import alice.datasegment.Receiver; + +public class DisconnectEventManager extends CodeSegment{ + + private Receiver info = ids.create(CommandType.PEEK); + private static DisconnectEventManager instance = new DisconnectEventManager(); + + private <T> DisconnectEventManager() { + ods.put("_DEVENTLIST", new ArrayList<Class<T>>()); + } + + public static DisconnectEventManager getInstance() { + return instance; + } + + public void setKey() { + ids.init(); + info.setKey("disconnect"); + } + + @SuppressWarnings("rawtypes") + @Override + public void run() { + new ExecuteEvent(); + setKey(); + } + + @SuppressWarnings("rawtypes") + public synchronized <T> void register(Class<T> clazz) { + ods.put("_REGISTERDEVENT", clazz); + new RegisterEvent(); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/topology/node/ExecuteEvent.java Sun Nov 23 22:14:30 2014 +0900 @@ -0,0 +1,51 @@ +package alice.topology.node; + +import java.lang.reflect.Field; +import java.util.List; + +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +import alice.datasegment.Receiver; + +public class ExecuteEvent<T> extends CodeSegment { + + public Receiver info = ids.create(CommandType.TAKE); + public Receiver info1 = ids.create(CommandType.TAKE); + + public ExecuteEvent() { + info.setKey("_DEVENTLIST"); + info1.setKey("disconnect"); + } + + @SuppressWarnings("unchecked") + @Override + public void run() { + List<Class<T>> eventList = info.asClass(List.class); + try { + for (Class<T> clazz : eventList){ + // set MetaInfo + if ("CloseEventCodeSegment".equals(clazz.getSuperclass().getSimpleName())) { + Field f = clazz.getField("metaInfo"); + CloseEventCodeSegment obj = (CloseEventCodeSegment) clazz.newInstance(); + f.set(obj, info1); + obj.ids.setKey(); + obj.ids.receive(); + } else if ("CodeSegment".equals(clazz.getSuperclass().getSimpleName())){ + clazz.newInstance(); + } else { + + } + } + } catch (InstantiationException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (NoSuchFieldException e) { + e.printStackTrace(); + } catch (SecurityException e) { + e.printStackTrace(); + } + ods.put(info.key, info.getReceiveData()); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/topology/node/RegisterEvent.java Sun Nov 23 22:14:30 2014 +0900 @@ -0,0 +1,34 @@ +package alice.topology.node; + +import java.util.List; + +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +import alice.datasegment.Receiver; + +public class RegisterEvent<T> extends CodeSegment { + + private Receiver info = ids.create(CommandType.TAKE); // new event + private Receiver info1 = ids.create(CommandType.TAKE); // event list + + public RegisterEvent() { + info.setKey("_REGISTERDEVENT"); + info1.setKey("_DEVENTLIST"); + } + + @SuppressWarnings("unchecked") + @Override + public void run() { + List<Class<T>> eventList = info1.asClass(List.class); + Class<T> clazz = (Class<T>) info.getObj(); + + // if put class type doesnt CodeSegment, not register + if ("CloseEventCodeSegment".equals(clazz.getSuperclass().getSimpleName())|| + "CodeSegment".equals(clazz.getSuperclass().getSimpleName())) { + eventList.add(clazz); + } + + ods.put(info1.key, eventList); + } + +}