1 10 11 package org.mule.management.agents; 12 13 15 import java.net.URI ; 16 17 import javax.management.InstanceNotFoundException ; 18 import javax.management.MBeanException ; 19 import javax.management.MBeanServer ; 20 import javax.management.MBeanServerFactory ; 21 import javax.management.ObjectName ; 22 import javax.management.ReflectionException ; 23 24 import org.mule.config.i18n.Message; 25 import org.mule.config.i18n.Messages; 26 import org.mule.umo.UMOException; 27 import org.mule.umo.lifecycle.InitialisationException; 28 import org.mule.umo.manager.UMOAgent; 29 30 37 public class JdmkAgent implements UMOAgent 38 { 39 40 private String name = "JDMK Agent"; 41 private String jmxAdaptorUrl = "http://localhost:9092"; 42 private Object adaptor; 43 private MBeanServer mBeanServer; 44 private ObjectName adaptorName; 45 46 protected Object createAdaptor() throws Exception 47 { 48 Object adaptor = null; 49 URI uri = new URI (jmxAdaptorUrl); 50 return adaptor; 52 } 53 54 59 public String getName() 60 { 61 return this.name; 62 } 63 64 69 public void setName(String name) 70 { 71 this.name = name; 72 } 73 74 79 public String getDescription() 80 { 81 return "Jdmk Http adaptor: " + jmxAdaptorUrl; 82 } 83 84 89 public void start() throws UMOException 90 { 91 try 92 { 93 mBeanServer.invoke(adaptorName, "start", null, null); 94 } 95 catch (InstanceNotFoundException e) 96 { 97 throw new JmxManagementException(new Message(Messages.FAILED_TO_START_X, "Jdmk agent"), 98 adaptorName, e); 99 } 100 catch (MBeanException e) 101 { 102 throw new JmxManagementException(new Message(Messages.FAILED_TO_START_X, "Jdmk agent"), 103 adaptorName, e); 104 } 105 catch (ReflectionException e) 106 { 107 } 109 } 110 111 116 public void stop() throws UMOException 117 { 118 try 119 { 120 mBeanServer.invoke(adaptorName, "stop", null, null); 121 } 122 catch (InstanceNotFoundException e) 123 { 124 throw new JmxManagementException(new Message(Messages.FAILED_TO_STOP_X, "Jdmk agent"), 125 adaptorName, e); 126 } 127 catch (MBeanException e) 128 { 129 throw new JmxManagementException(new Message(Messages.FAILED_TO_STOP_X, "Jdmk agent"), 130 adaptorName, e); 131 } 132 catch (ReflectionException e) 133 { 134 } 136 } 137 138 143 public void dispose() 144 { 145 try 146 { 147 stop(); 148 } 149 catch (Exception e) 150 { 151 } 153 } 154 155 160 public void registered() 161 { 162 } 164 165 170 public void unregistered() 171 { 172 } 174 175 180 public void initialise() throws InitialisationException 181 { 182 try 183 { 184 mBeanServer = (MBeanServer )MBeanServerFactory.findMBeanServer(null).get(0); 185 adaptor = createAdaptor(); 186 adaptorName = new ObjectName ("Adaptor:class=" + adaptor.getClass().getName()); 187 mBeanServer.registerMBean(adaptor, adaptorName); 188 } 189 catch (Exception e) 190 { 191 throw new InitialisationException(new Message(Messages.FAILED_TO_START_X, "Jdmk Agent"), e); 192 } 193 } 194 195 198 public String getJmxAdaptorUrl() 199 { 200 return jmxAdaptorUrl; 201 } 202 203 206 public void setJmxAdaptorUrl(String jmxAdaptorUrl) 207 { 208 this.jmxAdaptorUrl = jmxAdaptorUrl; 209 } 210 } 211 | Popular Tags |