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 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 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 return AGENT_NAME;
59 }
60
61
62
63
64
65
66 public void setName(String name)
67 {
68
69 }
70
71
72
73
74
75
76 public String getDescription()
77 {
78 return getName() + ": accepting connections on " + serverEndpoint;
79 }
80
81 public void start() throws UMOException
82 {
83
84 }
85
86 public void stop() throws UMOException
87 {
88
89 }
90
91 public void dispose()
92 {
93
94 }
95
96 public void registered()
97 {
98
99 }
100
101 public void unregistered()
102 {
103
104 }
105
106 public void initialise() throws InitialisationException
107 {
108 if (wireFormat == null)
109 {
110 wireFormat = new SerializationWireFormat();
111 }
112 serverEndpoint = MuleManager.getConfiguration().getServerUrl();
113 UMOManager manager = MuleManager.getInstance();
114
115 try
116 {
117 if (StringUtils.isEmpty(serverEndpoint))
118 {
119
120 logger.warn("No serverEndpointUrl specified, MuleAdminAgent will not start. E.g. use "
121 + "<mule-environment-properties serverUrl=\"tcp://example.com:60504\"/> ");
122
123
124 manager.unregisterAgent(this.getName());
125
126 return;
127 }
128
129
130 if (ModelHelper.isComponentRegistered(MuleManagerComponent.MANAGER_COMPONENT_NAME))
131 {
132 logger.info("Mule manager component has already been initialised, ignoring server url");
133 }
134 else
135 {
136 if (manager.lookupConnector(DEFAULT_MANAGER_ENDPOINT) != null)
137 {
138 throw new AlreadyInitialisedException("Server Components", this);
139 }
140
141
142 serverEndpoint = MuleManager.getInstance().lookupEndpointIdentifier(serverEndpoint,
143 serverEndpoint);
144 UMOEndpointURI endpointUri = new MuleEndpointURI(serverEndpoint);
145 UMOConnector connector = TransportFactory.getOrCreateConnectorByProtocol(endpointUri);
146
147
148 if (manager.lookupConnector(connector.getName()) == null)
149 {
150 connector.setName(DEFAULT_MANAGER_ENDPOINT);
151 connector.initialise();
152 manager.registerConnector(connector);
153 }
154
155 logger.info("Registering Admin listener on: " + serverEndpoint);
156 UMODescriptor descriptor = MuleManagerComponent.getDescriptor(connector, endpointUri,
157 wireFormat);
158 ModelHelper.registerSystemComponent(descriptor);
159 }
160 }
161 catch (UMOException e)
162 {
163 throw new InitialisationException(e, this);
164 }
165 }
166
167 public String toString()
168 {
169 return "MuleAdminAgent{" + "serverEndpoint='" + serverEndpoint + "'" + "}";
170 }
171
172 public WireFormat getWireFormat()
173 {
174 return wireFormat;
175 }
176
177 public void setWireFormat(WireFormat wireFormat)
178 {
179 this.wireFormat = wireFormat;
180 }
181 }