1 24 25 package org.objectweb.cjdbc.controller.jmx; 26 27 import java.net.InetAddress ; 28 import java.net.UnknownHostException ; 29 import java.util.ArrayList ; 30 import java.util.List ; 31 32 import javax.management.Attribute ; 33 import javax.management.MBeanServer ; 34 import javax.management.ObjectName ; 35 36 import org.objectweb.cjdbc.common.i18n.Translate; 37 import org.objectweb.cjdbc.common.jmx.JmxException; 38 import org.objectweb.cjdbc.common.log.Trace; 39 import org.objectweb.cjdbc.common.net.SSLConfiguration; 40 41 47 public class HttpAdaptor 48 49 { 50 static Trace logger = Trace 51 .getLogger("org.objectweb.cjdbc.controller.jmx"); 52 53 private String hostName; 54 private int port; 55 private SSLConfiguration sslConfig; 57 58 private mx4j.tools.adaptor.http.HttpAdaptor adaptor; 59 private ObjectName objectName; 60 private ObjectName processorName; 61 62 private static List httpAdaptors = new ArrayList (); 63 64 72 public HttpAdaptor(String hostName, int port, SSLConfiguration sslConfig) 73 throws JmxException 74 { 75 if (hostName != null) 76 { 77 this.hostName = hostName; 78 } 79 else 80 { 81 try 82 { 83 84 this.hostName = InetAddress.getLocalHost().getHostName(); 85 } 86 catch (UnknownHostException ex) 87 { 88 throw new JmxException(ex); 89 } 90 } 91 this.port = port; 92 this.sslConfig = sslConfig; 94 addHttpAdaptor(this); 95 } 96 97 102 public void start() throws JmxException 103 { 104 try 105 { 106 107 MBeanServer server = MBeanServerManager.getInstance(); 108 logger.info(Translate.get("jmx.create.http.adaptor", new Object []{ 110 hostName, String.valueOf(port)})); 111 adaptor = new mx4j.tools.adaptor.http.HttpAdaptor(); 112 objectName = new ObjectName ("Server:name=HttpAdaptor"); 113 server.registerMBean(adaptor, objectName); 114 adaptor.setHost(hostName); 115 adaptor.setPort(port); 116 logger.debug(Translate.get("jmx.create.xslt.processor")); 118 processorName = new ObjectName ("Server:name=XSLTProcessor"); 119 server.createMBean(mx4j.tools.adaptor.http.XSLTProcessor.class.getName(), 120 processorName, null); 121 server.setAttribute(objectName, new Attribute ("ProcessorName", 122 processorName)); 123 if (this.sslConfig != null) 124 { 125 throw new JmxException("ssl for http not implemented"); 127 } 128 adaptor.start(); 129 } 130 catch (Exception e) 131 { 132 e.printStackTrace(); 133 throw new JmxException(e); 134 } 135 } 136 137 142 public void stop() throws JmxException 143 { 144 try 145 { 146 MBeanServer server = MBeanServerManager.getInstance(); 147 adaptor.stop(); 148 server.unregisterMBean(objectName); 149 server.unregisterMBean(processorName); 150 } 151 catch (Exception e) 152 { 153 throw new JmxException(e); 154 } 155 } 156 157 162 public static List getHttpAdaptors() 163 { 164 return httpAdaptors; 165 } 166 167 172 private static synchronized void addHttpAdaptor(HttpAdaptor httpAdaptor) 173 { 174 httpAdaptors.add(httpAdaptor); 175 } 176 } 177 | Popular Tags |