1 27 package org.objectweb.speedo.jmx; 28 29 import mx4j.log.Log; 30 import mx4j.tools.adaptor.http.HttpAdaptor; 31 import mx4j.tools.adaptor.http.HttpAdaptorMBean; 32 import mx4j.tools.adaptor.http.XSLTProcessor; 33 34 import org.objectweb.fractal.api.control.BindingController; 35 import org.objectweb.fractal.api.control.LifeCycleController; 36 import org.objectweb.fractal.jmx.agent.AdminAttributes; 37 import org.objectweb.fractal.jmx.comm.CommunicatorAttributes; 38 import org.objectweb.util.monolog.api.BasicLevel; 39 import org.objectweb.util.monolog.api.Logger; 40 41 import javax.management.Attribute ; 42 import javax.management.MBeanServer ; 43 import javax.management.ObjectName ; 44 45 50 public class MX4J_HtmlAdaptor 51 implements BindingController, LifeCycleController, CommunicatorAttributes { 52 53 private static final String ADAPTOR = "MX4J_HtmlAdaptor"; 54 private final static String BINDING_ADMIN_ATT = "adminAtt"; 55 private AdminAttributes adminAtt; 56 private HttpAdaptorMBean adapter = null; 57 private int port; 58 private Logger logger; 59 60 private ObjectName getObjectName() throws Exception { 61 String id = '@' + Integer.toHexString(this.hashCode()); 62 return new ObjectName (ADAPTOR + id 63 + ":type=html,port=" + adapter.getPort()); 64 } 65 66 public String [] listFc() { 70 return new String [] {BINDING_ADMIN_ATT}; 71 } 72 73 public Object lookupFc(final String itfName) { 74 if (BINDING_ADMIN_ATT.equals(itfName)) { 75 return adminAtt; 76 } else { 77 return null; 78 } 79 } 80 81 public void bindFc(final String itfName, final Object itfValue) { 82 if ("logger".equals(itfName)) { 83 logger = (Logger) itfValue; 84 } else if (BINDING_ADMIN_ATT.equals(itfName)) { 85 adminAtt = (AdminAttributes) itfValue; 86 } 87 } 88 89 public void unbindFc(final String itfName) { 90 if (BINDING_ADMIN_ATT.equals(itfName)) { 91 adminAtt = null; 92 } 93 } 94 95 99 public int getPort() { 100 return port; 101 } 102 103 public void setPort(final int port) { 104 this.port = port; 105 } 106 107 public String getFcState() { 111 return null; 112 } 113 114 public synchronized void startFc() { 115 try { 116 if (adapter != null 117 && adapter.isActive() 118 && adapter.getPort() == port) { 119 return; 120 } 121 Log.redirectTo(new MX4JLoggerMonolog(logger)); 122 MBeanServer server = adminAtt.getRawMBeanServer(); 123 adapter = new HttpAdaptor(); 124 server.registerMBean(adapter, getObjectName()); 125 126 XSLTProcessor processor = new XSLTProcessor(); 127 processor.setPathInJar("org/objectweb/speedo/jmx/xsl"); 128 processor.setUseCache(false); 129 ObjectName processorName = new ObjectName ("Server:name=XSLTProcessor"); 130 server.registerMBean(processor, processorName); 131 132 server.setAttribute(getObjectName(), 133 new Attribute ("ProcessorName", processorName)); 134 135 adapter.setPort(port); 136 adapter.start(); 137 logger.log(BasicLevel.INFO, "MX4J HTTP Adaptor launched: " 138 + "\n\tUrl: http://" + adapter.getHost() 139 + ":" + adapter.getPort()); 140 } catch (Exception e) { 141 logger.log(BasicLevel.ERROR, 142 "Error during the instanciation of the MX4J Htttp adaptor:", e); 143 } 144 } 145 146 public void stopFc() { 147 if (adapter != null) { 148 adapter.stop(); 149 try { 150 adminAtt.getRawMBeanServer().unregisterMBean(getObjectName()); 151 } catch (Exception ignore) { 152 } 153 } 154 } 155 } 156 | Popular Tags |