Mercurial > hg > Database > Alice
comparison src/main/java/alice/topology/node/TopologyNodeConfig.java @ 631:ffaacab84d1a
Merge dispose
author | Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 30 Nov 2017 19:42:31 +0900 |
parents | 50b5aeca0cee b7cb1062828e |
children | cb16036404ba |
comparison
equal
deleted
inserted
replaced
604:1fad28f44fec | 631:ffaacab84d1a |
---|---|
1 package alice.topology.node; | 1 package alice.topology.node; |
2 | |
3 import java.util.ArrayList; | |
4 import java.util.LinkedList; | |
2 | 5 |
3 import alice.daemon.Config; | 6 import alice.daemon.Config; |
4 | 7 |
5 public class TopologyNodeConfig extends Config { | 8 public class TopologyNodeConfig extends Config { |
6 | 9 |
7 String managerHostName; | 10 private String managerHostName; |
8 int managerPort; | 11 private int managerPort = 10000; |
9 | 12 public String cookie; |
10 public TopologyNodeConfig(String[] args) { | 13 private ArrayList<Class> eventList = new ArrayList<Class>(); |
11 super(args); | 14 |
12 for (int i = 0; i< args.length; i++) { | 15 public TopologyNodeConfig(String[] args) { |
13 if ("-host".equals(args[i])) { | 16 super(args); |
14 managerHostName = args[++i]; | 17 for (int i = 0; i< args.length; i++) { |
15 } else if ("-port".equals(args[i])) { | 18 if ("-host".equals(args[i])) { |
16 managerPort = Integer.parseInt(args[++i]); | 19 setManagerHostName(args[++i]); |
17 } | 20 } else if ("-port".equals(args[i])) { |
18 } | 21 setManagerPort(Integer.parseInt(args[++i])); |
19 } | 22 } else if ("-cookie".equals(args[i])) { |
20 | 23 cookie = args[++i]; |
24 } | |
25 } | |
26 } | |
27 | |
28 public static LinkedList<TopologyNodeConfig> MultiTopologyNodeCongingFactory(String[] args) { | |
29 LinkedList<TopologyNodeConfig> configList = new LinkedList<TopologyNodeConfig>(); | |
30 LinkedList<String> nodeConfigArgs = new LinkedList<String>(); | |
31 | |
32 for(int i = 0; i < args.length; ++i) { | |
33 if("-host".equals(args[i])) { | |
34 if(!nodeConfigArgs.isEmpty()){ | |
35 configList.add(new TopologyNodeConfig((String[]) nodeConfigArgs.toArray())); | |
36 nodeConfigArgs = new LinkedList<String>(); | |
37 } | |
38 ++i; | |
39 nodeConfigArgs.add("-host"); | |
40 nodeConfigArgs.add(args[i]); | |
41 } else if("-port".equals(args[i])) { | |
42 ++i; | |
43 nodeConfigArgs.add("-port"); | |
44 nodeConfigArgs.add(args[i]); | |
45 } else if("-cookie".equals(args[i])) { | |
46 ++i; | |
47 nodeConfigArgs.add("-cookie"); | |
48 nodeConfigArgs.add(args[i]); | |
49 } | |
50 } | |
51 | |
52 configList.add(new TopologyNodeConfig(nodeConfigArgs.toArray(new String[] {}))); | |
53 | |
54 return configList; | |
55 | |
56 } | |
21 | 57 |
22 public String getManagerHostName() { | 58 public String getManagerHostName() { |
23 return managerHostName; | 59 return managerHostName; |
24 } | 60 } |
25 | 61 |
62 public void setManagerHostName(String managerHostName) { | |
63 this.managerHostName = managerHostName; | |
64 } | |
65 | |
66 public int getManagerPort() { | |
67 return managerPort; | |
68 } | |
69 | |
70 public void setManagerPort(int managerPort) { | |
71 this.managerPort = managerPort; | |
72 } | |
73 | |
74 public void register(Class clazz) { | |
75 if ("CodeSegment".equals(clazz.getSuperclass().getSimpleName())) | |
76 eventList.add(clazz); | |
77 } | |
78 | |
79 public void executeEvent() { | |
80 for (Class clazz : eventList) | |
81 try { | |
82 clazz.newInstance(); | |
83 } catch (InstantiationException e) { | |
84 e.printStackTrace(); | |
85 } catch (IllegalAccessException e){ | |
86 | |
87 } | |
88 } | |
89 | |
26 } | 90 } |