1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.impl.internal.admin; |
12 | |
|
13 | |
import org.mule.MuleManager; |
14 | |
import org.mule.impl.AlreadyInitialisedException; |
15 | |
import org.mule.impl.endpoint.MuleEndpointURI; |
16 | |
import org.mule.impl.model.ModelHelper; |
17 | |
import org.mule.providers.service.TransportFactory; |
18 | |
import org.mule.transformers.wire.SerializationWireFormat; |
19 | |
import org.mule.transformers.wire.WireFormat; |
20 | |
import org.mule.umo.UMODescriptor; |
21 | |
import org.mule.umo.UMOException; |
22 | |
import org.mule.umo.endpoint.UMOEndpointURI; |
23 | |
import org.mule.umo.lifecycle.InitialisationException; |
24 | |
import org.mule.umo.manager.UMOAgent; |
25 | |
import org.mule.umo.manager.UMOManager; |
26 | |
import org.mule.umo.provider.UMOConnector; |
27 | |
import org.mule.util.StringUtils; |
28 | |
|
29 | |
import org.apache.commons.logging.Log; |
30 | |
import org.apache.commons.logging.LogFactory; |
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | 0 | public class MuleAdminAgent implements UMOAgent |
37 | |
{ |
38 | |
public static final String DEFAULT_MANAGER_ENDPOINT = "_muleManagerEndpoint"; |
39 | |
|
40 | |
public static final String AGENT_NAME = "Mule Admin"; |
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | 0 | protected static final Log logger = LogFactory.getLog(MuleAdminAgent.class); |
46 | |
|
47 | |
private String serverEndpoint; |
48 | |
|
49 | |
private WireFormat wireFormat; |
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
public String getName() |
57 | |
{ |
58 | 0 | return AGENT_NAME; |
59 | |
} |
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
public void setName(String name) |
67 | |
{ |
68 | |
|
69 | 0 | } |
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
public String getDescription() |
77 | |
{ |
78 | 0 | return getName() + ": accepting connections on " + serverEndpoint; |
79 | |
} |
80 | |
|
81 | |
public void start() throws UMOException |
82 | |
{ |
83 | |
|
84 | 0 | } |
85 | |
|
86 | |
public void stop() throws UMOException |
87 | |
{ |
88 | |
|
89 | 0 | } |
90 | |
|
91 | |
public void dispose() |
92 | |
{ |
93 | |
|
94 | 0 | } |
95 | |
|
96 | |
public void registered() |
97 | |
{ |
98 | |
|
99 | 0 | } |
100 | |
|
101 | |
public void unregistered() |
102 | |
{ |
103 | |
|
104 | 0 | } |
105 | |
|
106 | |
public void initialise() throws InitialisationException |
107 | |
{ |
108 | 0 | if (wireFormat == null) |
109 | |
{ |
110 | 0 | wireFormat = new SerializationWireFormat(); |
111 | |
} |
112 | 0 | serverEndpoint = MuleManager.getConfiguration().getServerUrl(); |
113 | 0 | UMOManager manager = MuleManager.getInstance(); |
114 | |
|
115 | |
try |
116 | |
{ |
117 | 0 | if (StringUtils.isEmpty(serverEndpoint)) |
118 | |
{ |
119 | |
|
120 | 0 | logger.warn("No serverEndpointUrl specified, MuleAdminAgent will not start. E.g. use " |
121 | |
+ "<mule-environment-properties serverUrl=\"tcp://example.com:60504\"/> "); |
122 | |
|
123 | |
|
124 | 0 | manager.unregisterAgent(this.getName()); |
125 | |
|
126 | 0 | return; |
127 | |
} |
128 | |
|
129 | |
|
130 | 0 | if (ModelHelper.isComponentRegistered(MuleManagerComponent.MANAGER_COMPONENT_NAME)) |
131 | |
{ |
132 | 0 | logger.info("Mule manager component has already been initialised, ignoring server url"); |
133 | |
} |
134 | |
else |
135 | |
{ |
136 | 0 | if (manager.lookupConnector(DEFAULT_MANAGER_ENDPOINT) != null) |
137 | |
{ |
138 | 0 | throw new AlreadyInitialisedException("Server Components", this); |
139 | |
} |
140 | |
|
141 | |
|
142 | 0 | serverEndpoint = MuleManager.getInstance().lookupEndpointIdentifier(serverEndpoint, |
143 | |
serverEndpoint); |
144 | 0 | UMOEndpointURI endpointUri = new MuleEndpointURI(serverEndpoint); |
145 | 0 | UMOConnector connector = TransportFactory.getOrCreateConnectorByProtocol(endpointUri); |
146 | |
|
147 | |
|
148 | 0 | if (manager.lookupConnector(connector.getName()) == null) |
149 | |
{ |
150 | 0 | connector.setName(DEFAULT_MANAGER_ENDPOINT); |
151 | 0 | connector.initialise(); |
152 | 0 | manager.registerConnector(connector); |
153 | |
} |
154 | |
|
155 | 0 | logger.info("Registering Admin listener on: " + serverEndpoint); |
156 | 0 | UMODescriptor descriptor = MuleManagerComponent.getDescriptor(connector, endpointUri, |
157 | |
wireFormat); |
158 | 0 | ModelHelper.registerSystemComponent(descriptor); |
159 | |
} |
160 | |
} |
161 | 0 | catch (UMOException e) |
162 | |
{ |
163 | 0 | throw new InitialisationException(e, this); |
164 | 0 | } |
165 | 0 | } |
166 | |
|
167 | |
public String toString() |
168 | |
{ |
169 | 0 | return "MuleAdminAgent{" + "serverEndpoint='" + serverEndpoint + "'" + "}"; |
170 | |
} |
171 | |
|
172 | |
public WireFormat getWireFormat() |
173 | |
{ |
174 | 0 | return wireFormat; |
175 | |
} |
176 | |
|
177 | |
public void setWireFormat(WireFormat wireFormat) |
178 | |
{ |
179 | 0 | this.wireFormat = wireFormat; |
180 | 0 | } |
181 | |
} |