1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.module.client.remoting; |
12 | |
|
13 | |
import org.mule.AbstractAgent; |
14 | |
import org.mule.api.MuleException; |
15 | |
import org.mule.api.endpoint.InboundEndpoint; |
16 | |
import org.mule.api.lifecycle.InitialisationException; |
17 | |
import org.mule.api.service.Service; |
18 | |
import org.mule.api.transformer.wire.WireFormat; |
19 | |
import org.mule.config.i18n.CoreMessages; |
20 | |
import org.mule.module.client.remoting.notification.RemoteDispatcherNotification; |
21 | |
import org.mule.module.client.remoting.notification.RemoteDispatcherNotificationListener; |
22 | |
import org.mule.transformer.wire.SerializedMuleMessageWireFormat; |
23 | |
|
24 | |
import org.apache.commons.logging.Log; |
25 | |
import org.apache.commons.logging.LogFactory; |
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
public class RemoteDispatcherAgent extends AbstractAgent |
32 | |
{ |
33 | |
public static final String AGENT_NAME = "RemoteDispatcherServer"; |
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | 0 | protected static final Log logger = LogFactory.getLog(RemoteDispatcherAgent.class); |
39 | |
|
40 | |
private WireFormat wireFormat; |
41 | |
|
42 | |
private InboundEndpoint endpoint; |
43 | |
|
44 | |
|
45 | |
public RemoteDispatcherAgent() |
46 | |
{ |
47 | 0 | super(AGENT_NAME); |
48 | 0 | } |
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
public String getDescription() |
56 | |
{ |
57 | 0 | return getName() + ": accepting connections on " + endpoint.getEndpointURI().getAddress(); |
58 | |
} |
59 | |
|
60 | |
public void start() throws MuleException |
61 | |
{ |
62 | |
|
63 | 0 | } |
64 | |
|
65 | |
public void stop() throws MuleException |
66 | |
{ |
67 | |
|
68 | 0 | } |
69 | |
|
70 | |
public void dispose() |
71 | |
{ |
72 | |
|
73 | 0 | } |
74 | |
|
75 | |
public void registered() |
76 | |
{ |
77 | |
|
78 | 0 | } |
79 | |
|
80 | |
public void unregistered() |
81 | |
{ |
82 | |
|
83 | 0 | } |
84 | |
|
85 | |
public void initialise() throws InitialisationException |
86 | |
{ |
87 | 0 | if (endpoint == null) |
88 | |
{ |
89 | 0 | throw new IllegalArgumentException(CoreMessages.objectIsNull("remote-endpoint").getMessage()); |
90 | |
} |
91 | |
|
92 | 0 | if (wireFormat == null) |
93 | |
{ |
94 | 0 | wireFormat = new SerializedMuleMessageWireFormat(); |
95 | |
} |
96 | |
|
97 | |
|
98 | 0 | muleContext.getNotificationManager().addInterfaceToType( |
99 | |
RemoteDispatcherNotificationListener.class, |
100 | |
RemoteDispatcherNotification.class); |
101 | |
|
102 | |
try |
103 | |
{ |
104 | |
|
105 | 0 | if (muleContext.getRegistry().lookupService(RemoteDispatcherComponent.MANAGER_COMPONENT_NAME) != null) |
106 | |
{ |
107 | 0 | logger.info("Mule manager component has already been initialised, ignoring server url"); |
108 | |
} |
109 | |
else |
110 | |
{ |
111 | |
|
112 | 0 | Service component = RemoteDispatcherComponent.getSerivce(endpoint, wireFormat, |
113 | |
muleContext.getConfiguration().getDefaultEncoding(), muleContext.getConfiguration() |
114 | |
.getDefaultSynchronousEventTimeout(), muleContext); |
115 | 0 | muleContext.getRegistry().registerService(component); |
116 | |
} |
117 | |
} |
118 | 0 | catch (MuleException e) |
119 | |
{ |
120 | 0 | throw new InitialisationException(e, this); |
121 | 0 | } |
122 | 0 | } |
123 | |
|
124 | |
public String toString() |
125 | |
{ |
126 | 0 | String address = "not set"; |
127 | 0 | if(endpoint!=null) |
128 | |
{ |
129 | 0 | address = endpoint.getEndpointURI().getAddress(); |
130 | |
} |
131 | 0 | return "RemoteDispatcherAgent{" + "remote-endpoint='" + address + "'" + "}"; |
132 | |
} |
133 | |
|
134 | |
public WireFormat getWireFormat() |
135 | |
{ |
136 | 0 | return wireFormat; |
137 | |
} |
138 | |
|
139 | |
public void setWireFormat(WireFormat wireFormat) |
140 | |
{ |
141 | 0 | this.wireFormat = wireFormat; |
142 | 0 | } |
143 | |
|
144 | |
public InboundEndpoint getEndpoint() |
145 | |
{ |
146 | 0 | return endpoint; |
147 | |
} |
148 | |
|
149 | |
public void setEndpoint(InboundEndpoint endpoint) |
150 | |
{ |
151 | 0 | this.endpoint = endpoint; |
152 | 0 | } |
153 | |
} |