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 | |
public String getDescription() |
54 | |
{ |
55 | 0 | return getName() + ": accepting connections on " + endpoint.getEndpointURI().getAddress(); |
56 | |
} |
57 | |
|
58 | |
public void start() throws MuleException |
59 | |
{ |
60 | |
|
61 | 0 | } |
62 | |
|
63 | |
public void stop() throws MuleException |
64 | |
{ |
65 | |
|
66 | 0 | } |
67 | |
|
68 | |
public void dispose() |
69 | |
{ |
70 | |
|
71 | 0 | } |
72 | |
|
73 | |
|
74 | |
public void initialise() throws InitialisationException |
75 | |
{ |
76 | 0 | if (endpoint == null) |
77 | |
{ |
78 | 0 | throw new IllegalArgumentException(CoreMessages.objectIsNull("remote-endpoint").getMessage()); |
79 | |
} |
80 | |
|
81 | 0 | if (wireFormat == null) |
82 | |
{ |
83 | 0 | wireFormat = new SerializedMuleMessageWireFormat(); |
84 | |
} |
85 | 0 | wireFormat.setMuleContext(muleContext); |
86 | |
|
87 | |
|
88 | |
|
89 | 0 | muleContext.getNotificationManager().addInterfaceToType( |
90 | |
RemoteDispatcherNotificationListener.class, |
91 | |
RemoteDispatcherNotification.class); |
92 | |
|
93 | |
try |
94 | |
{ |
95 | |
|
96 | 0 | if (muleContext.getRegistry().lookupService(RemoteDispatcherComponent.MANAGER_COMPONENT_NAME) != null) |
97 | |
{ |
98 | 0 | logger.info("Mule manager component has already been initialised, ignoring server url"); |
99 | |
} |
100 | |
else |
101 | |
{ |
102 | |
|
103 | 0 | Service component = RemoteDispatcherComponent.getSerivce(endpoint, wireFormat, |
104 | |
muleContext.getConfiguration().getDefaultEncoding(), muleContext.getConfiguration() |
105 | |
.getDefaultResponseTimeout(), muleContext); |
106 | 0 | muleContext.getRegistry().registerService(component); |
107 | |
} |
108 | |
} |
109 | 0 | catch (MuleException e) |
110 | |
{ |
111 | 0 | throw new InitialisationException(e, this); |
112 | 0 | } |
113 | 0 | } |
114 | |
|
115 | |
public String toString() |
116 | |
{ |
117 | 0 | String address = "not set"; |
118 | 0 | if(endpoint!=null) |
119 | |
{ |
120 | 0 | address = endpoint.getEndpointURI().getAddress(); |
121 | |
} |
122 | 0 | return "RemoteDispatcherAgent{" + "remote-endpoint='" + address + "'" + "}"; |
123 | |
} |
124 | |
|
125 | |
public WireFormat getWireFormat() |
126 | |
{ |
127 | 0 | return wireFormat; |
128 | |
} |
129 | |
|
130 | |
public void setWireFormat(WireFormat wireFormat) |
131 | |
{ |
132 | 0 | this.wireFormat = wireFormat; |
133 | 0 | } |
134 | |
|
135 | |
public InboundEndpoint getEndpoint() |
136 | |
{ |
137 | 0 | return endpoint; |
138 | |
} |
139 | |
|
140 | |
public void setEndpoint(InboundEndpoint endpoint) |
141 | |
{ |
142 | 0 | this.endpoint = endpoint; |
143 | 0 | } |
144 | |
} |