|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| package org.codehaus.wadi.group.vm; |
|
17 |
| |
|
18 |
| import org.codehaus.wadi.group.Address; |
|
19 |
| import org.codehaus.wadi.group.Cluster; |
|
20 |
| import org.codehaus.wadi.group.EndPoint; |
|
21 |
| import org.codehaus.wadi.group.Envelope; |
|
22 |
| import org.codehaus.wadi.group.MessageExchangeException; |
|
23 |
| import org.codehaus.wadi.group.impl.AbstractDispatcher; |
|
24 |
| |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| public class VMDispatcher extends AbstractDispatcher { |
|
30 |
| private final VMLocalPeer localNode; |
|
31 |
| private final VMLocalCluster cluster; |
|
32 |
| |
|
33 |
8
| public VMDispatcher(VMBroker cluster, String nodeName, EndPoint endPoint) {
|
|
34 |
8
| localNode = new VMLocalPeer(nodeName);
|
|
35 |
8
| this.cluster = new VMLocalCluster(cluster, localNode, this);
|
|
36 |
| } |
|
37 |
| |
|
38 |
91
| public Cluster getCluster() {
|
|
39 |
91
| return cluster;
|
|
40 |
| } |
|
41 |
| |
|
42 |
8
| public void start() throws MessageExchangeException {
|
|
43 |
8
| cluster.registerDispatcher(this);
|
|
44 |
| } |
|
45 |
| |
|
46 |
4
| public void stop() throws MessageExchangeException {
|
|
47 |
4
| cluster.unregisterDispatcher(this);
|
|
48 |
| } |
|
49 |
| |
|
50 |
0
| public String getPeerName(Address address) {
|
|
51 |
0
| if (null == address) {
|
|
52 |
0
| return "<NULL Destination>";
|
|
53 |
| } |
|
54 |
| |
|
55 |
0
| if (address instanceof VMAddress) {
|
|
56 |
0
| return ((VMAddress) address).getNodeName();
|
|
57 |
0
| } else if (address instanceof VMClusterAddress) {
|
|
58 |
0
| return ((VMClusterAddress) address).getClusterName();
|
|
59 |
| } |
|
60 |
| |
|
61 |
0
| throw new IllegalArgumentException("Expected " +
|
|
62 |
| VMAddress.class.getName() + |
|
63 |
| " or " + VMClusterAddress.class.getName() + |
|
64 |
| ". Was:" + address.getClass().getName()); |
|
65 |
| } |
|
66 |
| |
|
67 |
3
| protected void doSend(Address target, Envelope envelope) throws MessageExchangeException {
|
|
68 |
3
| cluster.send(target, envelope);
|
|
69 |
| } |
|
70 |
| |
|
71 |
3
| public Envelope createEnvelope() {
|
|
72 |
3
| return new VMEnvelope();
|
|
73 |
| } |
|
74 |
| |
|
75 |
4
| public String toString() {
|
|
76 |
4
| return "VMDispatcher for node " + localNode;
|
|
77 |
| } |
|
78 |
| |
|
79 |
| } |