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