Mercurial > hg > Database > Alice
annotate src/alice/topology/manager/StartTopologyManager.java @ 335:2f003d5703d5 META_CODESEGMENT
Meta CodeSegment Test
author | sugi |
---|---|
date | Mon, 14 Apr 2014 15:46:29 +0900 |
parents | d136c65d8904 |
children | 5fa184113850 |
rev | line source |
---|---|
27 | 1 package alice.topology.manager; |
22
2ca2d961a8d2
implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2 |
2ca2d961a8d2
implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
3 import java.io.File; |
2ca2d961a8d2
implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
4 import java.io.FileNotFoundException; |
2ca2d961a8d2
implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
5 import java.io.FileReader; |
2ca2d961a8d2
implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
6 import java.util.ArrayList; |
2ca2d961a8d2
implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
7 import java.util.HashMap; |
2ca2d961a8d2
implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
8 import java.util.LinkedList; |
2ca2d961a8d2
implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
9 |
2ca2d961a8d2
implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
10 import org.apache.log4j.Logger; |
2ca2d961a8d2
implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
11 |
30 | 12 import alice.codesegment.CodeSegment; |
266 | 13 import alice.topology.HostMessage; |
30 | 14 |
22
2ca2d961a8d2
implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
15 import com.alexmerz.graphviz.ParseException; |
2ca2d961a8d2
implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
16 import com.alexmerz.graphviz.Parser; |
2ca2d961a8d2
implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
17 import com.alexmerz.graphviz.objects.Edge; |
2ca2d961a8d2
implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
18 import com.alexmerz.graphviz.objects.Graph; |
2ca2d961a8d2
implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
19 import com.alexmerz.graphviz.objects.Node; |
2ca2d961a8d2
implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
20 |
2ca2d961a8d2
implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
21 public class StartTopologyManager extends CodeSegment { |
2ca2d961a8d2
implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
22 |
2ca2d961a8d2
implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
23 TopologyManagerConfig conf; |
2ca2d961a8d2
implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
24 Logger logger = Logger.getLogger(StartTopologyManager.class); |
2ca2d961a8d2
implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
25 |
2ca2d961a8d2
implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
26 public StartTopologyManager(TopologyManagerConfig conf) { |
27 | 27 this.conf = conf; |
22
2ca2d961a8d2
implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
28 } |
2ca2d961a8d2
implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
29 |
2ca2d961a8d2
implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
30 @Override |
2ca2d961a8d2
implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
31 public void run() { |
2ca2d961a8d2
implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
32 LinkedList<String> nodeNames = new LinkedList<String>(); |
24 | 33 HashMap<String, LinkedList<NodeInfo>> topology = new HashMap<String, LinkedList<NodeInfo>>(); |
35
ac3b48c5f4da
share width each other with tree
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
30
diff
changeset
|
34 int nodeNum = 0; |
22
2ca2d961a8d2
implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
35 try { |
2ca2d961a8d2
implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
36 FileReader reader = new FileReader(new File(conf.confFilePath)); |
2ca2d961a8d2
implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
37 Parser parser = new Parser(); |
2ca2d961a8d2
implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
38 parser.parse(reader); |
2ca2d961a8d2
implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
39 ArrayList<Graph> graphs = parser.getGraphs(); |
2ca2d961a8d2
implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
40 for (Graph graph : graphs) { |
2ca2d961a8d2
implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
41 ArrayList<Node> nodes = graph.getNodes(false); |
35
ac3b48c5f4da
share width each other with tree
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
30
diff
changeset
|
42 nodeNum = nodes.size(); |
22
2ca2d961a8d2
implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
43 for (Node node : nodes) { |
24 | 44 String nodeName = node.getId().getId(); |
45 nodeNames.add(nodeName); | |
46 topology.put(nodeName, new LinkedList<NodeInfo>()); | |
22
2ca2d961a8d2
implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
47 } |
2ca2d961a8d2
implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
48 ArrayList<Edge> edges = graph.getEdges(); |
28
98ab26e09a98
Configuration Manager work and implements reverseKey
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
27
diff
changeset
|
49 HashMap<String, NodeInfo> hash = new HashMap<String, NodeInfo>(); |
22
2ca2d961a8d2
implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
50 for (Edge edge : edges) { |
2ca2d961a8d2
implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
51 String connection = edge.getAttribute("label"); |
2ca2d961a8d2
implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
52 String source = edge.getSource().getNode().getId().getId(); |
28
98ab26e09a98
Configuration Manager work and implements reverseKey
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
27
diff
changeset
|
53 String target = edge.getTarget().getNode().getId().getId(); |
24 | 54 LinkedList<NodeInfo> sources = topology.get(target); |
28
98ab26e09a98
Configuration Manager work and implements reverseKey
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
27
diff
changeset
|
55 NodeInfo nodeInfo = new NodeInfo(source, connection); |
98ab26e09a98
Configuration Manager work and implements reverseKey
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
27
diff
changeset
|
56 sources.add(nodeInfo); |
42 | 57 hash.put(source + "," + target, nodeInfo); |
28
98ab26e09a98
Configuration Manager work and implements reverseKey
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
27
diff
changeset
|
58 } |
98ab26e09a98
Configuration Manager work and implements reverseKey
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
27
diff
changeset
|
59 for (Edge edge : edges) { |
98ab26e09a98
Configuration Manager work and implements reverseKey
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
27
diff
changeset
|
60 String connection = edge.getAttribute("label"); |
98ab26e09a98
Configuration Manager work and implements reverseKey
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
27
diff
changeset
|
61 String source = edge.getSource().getNode().getId().getId(); |
98ab26e09a98
Configuration Manager work and implements reverseKey
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
27
diff
changeset
|
62 String target = edge.getTarget().getNode().getId().getId(); |
42 | 63 NodeInfo nodeInfo = hash.get(target + "," + source); |
28
98ab26e09a98
Configuration Manager work and implements reverseKey
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
27
diff
changeset
|
64 if (nodeInfo != null) { |
98ab26e09a98
Configuration Manager work and implements reverseKey
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
27
diff
changeset
|
65 nodeInfo.reverseName = connection; |
98ab26e09a98
Configuration Manager work and implements reverseKey
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
27
diff
changeset
|
66 } |
22
2ca2d961a8d2
implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
67 } |
2ca2d961a8d2
implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
68 } |
2ca2d961a8d2
implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
69 |
2ca2d961a8d2
implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
70 } catch (FileNotFoundException e) { |
2ca2d961a8d2
implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
71 logger.error("File not found: " + conf.confFilePath); |
2ca2d961a8d2
implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
72 e.printStackTrace(); |
2ca2d961a8d2
implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
73 } catch (ParseException e) { |
2ca2d961a8d2
implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
74 logger.error("File format error: " + conf.confFilePath); |
2ca2d961a8d2
implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
75 e.printStackTrace(); |
2ca2d961a8d2
implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
76 } |
335 | 77 |
266 | 78 HashMap<String, ArrayList<HostMessage>> connectionList = new HashMap<String, ArrayList<HostMessage>>(); |
269 | 79 ods.put("connection", connectionList); |
80 ods.put("_ABSIPTABLE" ,new ArrayList<HostMessage>()); | |
81 | |
82 new createABSIPList(); | |
83 | |
30 | 84 IncomingHosts cs1 = new IncomingHosts(topology, nodeNames); |
273 | 85 cs1.host.setKey("host"); |
86 cs1.connection.setKey("connection"); | |
35
ac3b48c5f4da
share width each other with tree
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
30
diff
changeset
|
87 |
ac3b48c5f4da
share width each other with tree
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
30
diff
changeset
|
88 ConfigWaiter cs3 = new ConfigWaiter(nodeNum); |
ac3b48c5f4da
share width each other with tree
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
30
diff
changeset
|
89 cs3.done.setKey("local", "done"); |
269 | 90 |
91 | |
22
2ca2d961a8d2
implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
92 } |
2ca2d961a8d2
implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
93 |
2ca2d961a8d2
implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
94 } |