1 22 23 package org.objectweb.petals.kernel.mx4j; 24 25 import javax.management.Attribute ; 26 import javax.management.InstanceNotFoundException ; 27 import javax.management.MalformedObjectNameException ; 28 import javax.management.ObjectName ; 29 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.LifeCycleController; 35 import org.objectweb.fractal.fraclet.annotation.FractalComponent; 36 import org.objectweb.fractal.fraclet.annotation.LifeCycle; 37 import org.objectweb.fractal.fraclet.annotation.LifeCycleType; 38 import org.objectweb.fractal.fraclet.annotation.Monolog; 39 import org.objectweb.fractal.fraclet.annotation.Requires; 40 import org.objectweb.fractal.jmx.agent.AdminAttributes; 41 import org.objectweb.petals.util.LoggingUtil; 42 import org.objectweb.petals.util.SystemUtil; 43 import org.objectweb.util.monolog.api.Logger; 44 45 54 @FractalComponent 55 public class MX4JHtmlAdaptor { 56 57 private static final String ADAPTOR = "MX4JHtmlAdaptor"; 58 59 62 protected HttpAdaptorMBean adaptor; 63 64 67 @Requires(name="adminAtt",signature=org.objectweb.fractal.jmx.agent.AdminAttributes.class) 68 protected AdminAttributes adminAttributes; 69 70 73 protected LoggingUtil log; 74 75 78 @Monolog(name="logger") 79 protected Logger logger; 80 81 private ObjectName oName; 82 83 86 @LifeCycle(on=LifeCycleType.START) 87 public void start() { 88 log=new LoggingUtil(null); 89 log.start(); 90 try { 91 int port = Integer.parseInt(SystemUtil.getHtmlPort()); 93 if (adaptor != null && adaptor.isActive() 96 && adaptor.getPort() == port) { 97 return; 98 } 99 if (adaptor != null) { 101 adaptor.stop(); 102 try { 103 adminAttributes.getRawMBeanServer().unregisterMBean( 104 getObjectName()); 105 } catch (InstanceNotFoundException ignore) { 106 } 108 } 109 adaptor = new HttpAdaptor(); 110 adaptor.setPort(port); 111 adaptor.setHost("0.0.0.0"); 112 113 adaptor.addCommandProcessor("petals", new PetalsCommandProcessor()); 114 115 116 adminAttributes.getRawMBeanServer().registerMBean(adaptor, 117 getObjectName()); 118 119 ObjectName processorName = new ObjectName ( 120 "Server:name=XSLTProcessor"); 121 XSLTProcessor processor = new XSLTProcessor(); 122 123 processor.setDefaultPage("petals"); 124 processor 125 .setPathInJar("org/objectweb/petals/kernel/fractal/mx4j/xsl"); 126 127 processor.setUseCache(false); 128 adminAttributes.getRawMBeanServer().registerMBean(processor, 129 processorName); 130 adminAttributes.getRawMBeanServer().setAttribute(getObjectName(), 131 new Attribute ("ProcessorName", processorName)); 132 133 adaptor.start(); 134 } catch (Exception e) { 135 log.error("Fail to start HTML adaptor", e); 136 } 137 log.end(); 138 } 139 140 143 @LifeCycle(on=LifeCycleType.STOP) 144 public void stop() { 145 log.start(); 146 if (adaptor != null) { 147 adaptor.stop(); 148 try { 149 adminAttributes.getRawMBeanServer().unregisterMBean( 150 getObjectName()); 151 } catch (Exception ignore) { 152 log.warning("Error during MBean unregistering: " 153 + ignore.getMessage(), ignore); 154 } 155 } 156 log.end(); 157 } 158 159 163 private ObjectName getObjectName() throws MalformedObjectNameException { 164 if (oName == null) { 165 String id = '@' + Integer.toHexString(this.hashCode()); 166 oName = new ObjectName (ADAPTOR + id + ":type=html,port=" 167 + adaptor.getPort()); 168 } 169 return oName; 170 } 171 } 172 | Popular Tags |