1
2
3
4
5
6
7
8
9
10 package org.mule.module.management.agent;
11
12 import org.mule.api.MuleContext;
13 import org.mule.api.context.MuleContextAware;
14 import org.mule.api.registry.RegistrationException;
15
16 import org.apache.commons.logging.Log;
17 import org.apache.commons.logging.LogFactory;
18
19 import java.util.Collections;
20 import java.util.HashMap;
21 import java.util.Map;
22
23 import javax.management.MBeanServer;
24 import javax.management.remote.rmi.RMIConnectorServer;
25
26
27
28
29
30
31 public class JmxAgentConfigurer implements MuleContextAware
32 {
33
34
35 public static final Map DEFAULT_CONNECTOR_SERVER_PROPERTIES;
36
37
38
39
40 protected static final Log logger = LogFactory.getLog(JmxAgentConfigurer.class);
41
42 protected MuleContext muleContext;
43
44
45
46
47 protected boolean locateServer = true;
48
49 private boolean createServer = false;
50 private String connectorServerUrl;
51 private MBeanServer mBeanServer;
52 private Map connectorServerProperties = null;
53 private boolean enableStatistics = true;
54 private boolean createRmiRegistry = true;
55
56
57
58
59 private Map credentials = new HashMap();
60
61 static
62 {
63 Map props = new HashMap(1);
64 props.put(RMIConnectorServer.JNDI_REBIND_ATTRIBUTE, "true");
65 DEFAULT_CONNECTOR_SERVER_PROPERTIES = Collections.unmodifiableMap(props);
66 }
67
68 public JmxAgentConfigurer()
69 {
70 connectorServerProperties = new HashMap(DEFAULT_CONNECTOR_SERVER_PROPERTIES);
71 }
72
73
74
75
76 public boolean isCreateServer()
77 {
78 return createServer;
79 }
80
81
82
83
84 public void setCreateServer(boolean createServer)
85 {
86 this.createServer = createServer;
87 }
88
89
90
91
92 public boolean isLocateServer()
93 {
94 return locateServer;
95 }
96
97
98
99
100 public void setLocateServer(boolean locateServer)
101 {
102 this.locateServer = locateServer;
103 }
104
105
106
107
108 public String getConnectorServerUrl()
109 {
110 return connectorServerUrl;
111 }
112
113
114
115
116 public void setConnectorServerUrl(String connectorServerUrl)
117 {
118 this.connectorServerUrl = connectorServerUrl;
119 }
120
121
122
123
124 public boolean isEnableStatistics()
125 {
126 return enableStatistics;
127 }
128
129
130
131
132 public void setEnableStatistics(boolean enableStatistics)
133 {
134 this.enableStatistics = enableStatistics;
135 }
136
137
138
139
140 public MBeanServer getMBeanServer()
141 {
142 return mBeanServer;
143 }
144
145
146
147
148 public void setMBeanServer(MBeanServer mBeanServer)
149 {
150 this.mBeanServer = mBeanServer;
151 }
152
153
154
155
156
157
158 public Map getConnectorServerProperties()
159 {
160 return connectorServerProperties;
161 }
162
163
164
165
166
167
168
169
170 public void setConnectorServerProperties(Map connectorServerProperties)
171 {
172 this.connectorServerProperties = connectorServerProperties;
173 }
174
175
176
177
178
179
180
181 public void setCredentials(final Map newCredentials)
182 {
183 this.credentials.clear();
184 if (newCredentials != null && !newCredentials.isEmpty())
185 {
186 this.credentials.putAll(newCredentials);
187 }
188 }
189
190 public boolean isCreateRmiRegistry()
191 {
192 return createRmiRegistry;
193 }
194
195 public void setCreateRmiRegistry(boolean createRmiRegistry)
196 {
197 this.createRmiRegistry = createRmiRegistry;
198 }
199
200 public void setMuleContext(MuleContext context)
201 {
202 this.muleContext = context;
203 try
204 {
205
206 JmxAgent agent = muleContext.getRegistry().lookupObject(JmxAgent.class);
207
208 if (getMBeanServer() != null)
209 {
210 agent.setMBeanServer(getMBeanServer());
211 }
212 if (getConnectorServerUrl() != null)
213 {
214 agent.setConnectorServerUrl(getConnectorServerUrl());
215 }
216 if (getConnectorServerProperties() != null && !getConnectorServerProperties().isEmpty())
217 {
218 agent.setConnectorServerProperties(getConnectorServerProperties());
219 }
220
221 agent.setCreateServer(isCreateServer());
222 agent.setLocateServer(isLocateServer());
223 agent.setEnableStatistics(isEnableStatistics());
224 agent.setCreateRmiRegistry(isCreateRmiRegistry());
225 }
226 catch (RegistrationException e)
227 {
228 throw new RuntimeException(e);
229 }
230 }
231
232 public void setName(String name)
233 {
234
235 }
236 }