1 10 11 package org.mule.management.agents; 12 13 import java.util.HashMap ; 14 import java.util.Map ; 15 16 import org.mule.MuleManager; 17 import org.mule.umo.UMOException; 18 import org.mule.umo.lifecycle.InitialisationException; 19 import org.mule.umo.lifecycle.RecoverableException; 20 import org.mule.umo.manager.UMOAgent; 21 22 28 public class DefaultJmxSupportAgent implements UMOAgent 29 { 30 31 public static final String DEFAULT_REMOTING_URI = "service:jmx:rmi:///jndi/rmi://localhost:1099/server"; 32 33 private String name = "Default Jmx"; 34 private boolean loadJdmkAgent = false; 35 private boolean loadMx4jAgent = false; 36 37 42 public String getName() 43 { 44 return name; 45 } 46 47 52 public void setName(String name) 53 { 54 this.name = name; 55 } 56 57 62 public String getDescription() 63 { 64 return "Default Jmx Agent Support"; 65 } 66 67 public void registered() 68 { 69 } 71 72 public void unregistered() 73 { 74 } 76 77 public void start() throws UMOException 78 { 79 } 81 82 public void stop() throws UMOException 83 { 84 } 86 87 92 public void dispose() 93 { 94 } 96 97 110 public void initialise() throws InitialisationException, RecoverableException 111 { 112 113 try 114 { 115 UMOAgent agent = createRmiAgent(); 116 if (!isAgentRegistered(agent)) 117 { 118 MuleManager.getInstance().registerAgent(agent); 119 } 120 agent = createJmxAgent(); 121 if (!isAgentRegistered(agent)) 122 { 123 MuleManager.getInstance().registerAgent(agent); 124 } 125 agent = createLog4jAgent(); 126 if (!isAgentRegistered(agent)) 127 { 128 MuleManager.getInstance().registerAgent(agent); 129 } 130 agent = createJmxNotificationAgent(); 131 if (!isAgentRegistered(agent)) 132 { 133 MuleManager.getInstance().registerAgent(agent); 134 } 135 if (loadJdmkAgent) 136 { 137 agent = createJdmkAgent(); 138 if (!isAgentRegistered(agent)) 139 { 140 MuleManager.getInstance().registerAgent(agent); 141 } 142 } 143 144 if (loadMx4jAgent) 145 { 146 agent = createMx4jAgent(); 147 if (!isAgentRegistered(agent)) 148 { 149 MuleManager.getInstance().registerAgent(agent); 150 } 151 } 152 153 MuleManager.getInstance().unregisterAgent(name); 155 } 156 catch (UMOException e) 157 { 158 throw new InitialisationException(e, this); 159 } 160 } 161 162 protected JmxAgent createJmxAgent() 163 { 164 JmxAgent agent = new JmxAgent(); 165 agent.setConnectorServerUrl(DEFAULT_REMOTING_URI); 166 Map props = new HashMap (); 167 props.put("jmx.remote.jndi.rebind", "true"); 168 agent.setConnectorServerProperties(props); 169 return agent; 170 } 171 172 protected Log4jAgent createLog4jAgent() 173 { 174 return new Log4jAgent(); 175 } 176 177 protected RmiRegistryAgent createRmiAgent() 178 { 179 return new RmiRegistryAgent(); 180 } 181 182 protected JmxServerNotificationAgent createJmxNotificationAgent() 183 { 184 return new JmxServerNotificationAgent(); 185 } 186 187 protected Mx4jAgent createMx4jAgent() 188 { 189 return new Mx4jAgent(); 190 } 191 192 protected JdmkAgent createJdmkAgent() 193 { 194 return new JdmkAgent(); 195 } 196 197 protected boolean isAgentRegistered(UMOAgent agent) 198 { 199 return MuleManager.getInstance().lookupAgent(agent.getName()) != null; 200 } 201 202 public boolean isLoadJdmkAgent() 203 { 204 return loadJdmkAgent; 205 } 206 207 public void setLoadJdmkAgent(boolean loadJdmkAgent) 208 { 209 this.loadJdmkAgent = loadJdmkAgent; 210 } 211 212 public boolean isLoadMx4jAgent() 213 { 214 return loadMx4jAgent; 215 } 216 217 public void setLoadMx4jAgent(boolean loadMx4jAgent) 218 { 219 this.loadMx4jAgent = loadMx4jAgent; 220 } 221 } 222 | Popular Tags |