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