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