Mercurial > hg > Database > Alice
changeset 518:fc313323c53b dispose
add reconnect event
author | sugi |
---|---|
date | Thu, 22 Jan 2015 16:01:32 +0900 |
parents | 80e461aa10e9 |
children | 16f44f2060cc |
files | src/main/java/alice/topology/manager/CreateTreeTopology.java src/main/java/alice/topology/node/ClosedEventManager.java src/main/java/alice/topology/node/ConfigurationFinish.java src/main/java/alice/topology/node/Start.java src/main/java/alice/topology/node/StartTopologyNode.java src/main/java/alice/topology/node/TopologyNodeConfig.java |
diffstat | 6 files changed, 29 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/alice/topology/manager/CreateTreeTopology.java Thu Jan 22 11:43:34 2015 +0900 +++ b/src/main/java/alice/topology/manager/CreateTreeTopology.java Thu Jan 22 16:01:32 2015 +0900 @@ -57,6 +57,7 @@ DataSegment.connect(nodeName, nodeName, host.name, host.port); ods.put(nodeName, "host", nodeName); ods.put(nodeName, "cookie", cookie); + ods.put(nodeName, "reconnect", reconnect); ods.put(info4.key, absCookieTable); ods.put(info1.key, count);
--- a/src/main/java/alice/topology/node/ClosedEventManager.java Thu Jan 22 11:43:34 2015 +0900 +++ b/src/main/java/alice/topology/node/ClosedEventManager.java Thu Jan 22 16:01:32 2015 +0900 @@ -6,6 +6,7 @@ import alice.datasegment.CommandType; import alice.datasegment.Receiver; +@SuppressWarnings("rawtypes") public class ClosedEventManager extends CodeSegment{ private Receiver info = ids.create(CommandType.PEEK); @@ -24,14 +25,12 @@ 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();
--- a/src/main/java/alice/topology/node/ConfigurationFinish.java Thu Jan 22 11:43:34 2015 +0900 +++ b/src/main/java/alice/topology/node/ConfigurationFinish.java Thu Jan 22 16:01:32 2015 +0900 @@ -25,6 +25,8 @@ ods.put("manager", "done", ValueFactory.createNilValue()); Start cs = new Start(startCS); cs.done.setKey("manager", "start"); + cs.config.setKey("TNConfig"); + cs.reconnect.setKey("reconnect"); new StartKeepAlive().execute(); new ReceiveCloseMessage(CommandType.PEEK);
--- a/src/main/java/alice/topology/node/Start.java Thu Jan 22 11:43:34 2015 +0900 +++ b/src/main/java/alice/topology/node/Start.java Thu Jan 22 16:01:32 2015 +0900 @@ -9,7 +9,8 @@ public class Start extends CodeSegment { public Receiver done = ids.create(CommandType.PEEK); - + public Receiver reconnect = ids.create(CommandType.PEEK); + public Receiver config = ids.create(CommandType.PEEK); private Logger logger = Logger.getLogger(Start.class); private CodeSegment startCS; @@ -21,6 +22,11 @@ @Override public void run() { logger.info("Configuration finished."); + boolean reconncet = this.reconnect.asClass(boolean.class); + if (reconncet) { + TopologyNodeConfig tnconfig = this.config.asClass(TopologyNodeConfig.class); + tnconfig.executeEvent(); + } if (startCS == null) return;
--- a/src/main/java/alice/topology/node/StartTopologyNode.java Thu Jan 22 11:43:34 2015 +0900 +++ b/src/main/java/alice/topology/node/StartTopologyNode.java Thu Jan 22 16:01:32 2015 +0900 @@ -20,6 +20,7 @@ @Override public void run() { + ods.put("TNConfig", conf); DataSegment.connect("manager", "manager", conf.getManagerHostName(), conf.getManagerPort()); String localHostName = null; try {
--- a/src/main/java/alice/topology/node/TopologyNodeConfig.java Thu Jan 22 11:43:34 2015 +0900 +++ b/src/main/java/alice/topology/node/TopologyNodeConfig.java Thu Jan 22 16:01:32 2015 +0900 @@ -1,12 +1,16 @@ package alice.topology.node; +import java.util.ArrayList; + import alice.daemon.Config; +@SuppressWarnings("rawtypes") public class TopologyNodeConfig extends Config { private String managerHostName; private int managerPort = 10000; public String cookie; + private ArrayList<Class> eventList = new ArrayList<Class>(); public TopologyNodeConfig(String[] args) { super(args); @@ -37,4 +41,17 @@ this.managerPort = managerPort; } + public void register(Class clazz) { + if ("CodeSegment".equals(clazz.getSuperclass().getSimpleName())) + eventList.add(clazz); + } + + public void executeEvent() { + for (Class clazz : eventList) + try { + clazz.newInstance(); + } catch (InstantiationException | IllegalAccessException e) { + e.printStackTrace(); + } + } }