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