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