1 17 package org.apache.servicemix.jbi.jmx; 18 19 import java.util.Map ; 20 21 import javax.management.MBeanServer ; 22 import javax.management.MalformedObjectNameException ; 23 24 import org.apache.commons.logging.Log; 25 import org.apache.commons.logging.LogFactory; 26 import org.springframework.beans.factory.DisposableBean; 27 import org.springframework.beans.factory.FactoryBean; 28 import org.springframework.beans.factory.InitializingBean; 29 import org.springframework.core.Constants; 30 import org.springframework.jmx.support.MBeanRegistrationSupport; 31 32 46 public class ConnectorServerFactoryBean implements FactoryBean, InitializingBean, DisposableBean { 47 48 private Log log = LogFactory.getLog(ConnectorServerFactoryBean.class); 49 private org.springframework.jmx.support.ConnectorServerFactoryBean csfb = new org.springframework.jmx.support.ConnectorServerFactoryBean(); 50 private String serviceUrl = org.springframework.jmx.support.ConnectorServerFactoryBean.DEFAULT_SERVICE_URL; 51 private boolean daemon = false; 52 private boolean threaded = false; 53 private Map environment; 54 private String objectName; 55 private int registrationBehavior; 56 private MBeanServer server; 57 private static final Constants constants = new Constants(MBeanRegistrationSupport.class); 58 59 60 66 public void setDaemon(boolean daemon) { 67 this.daemon = daemon; 68 } 69 70 76 public void setEnvironment(Map environment) { 77 this.environment = environment; 78 } 79 80 87 public void setObjectName(String objectName) throws MalformedObjectNameException { 88 this.objectName = objectName; 89 } 90 91 102 public void setRegistrationBehavior(int registrationBehavior) { 103 this.registrationBehavior = registrationBehavior; 104 } 105 106 116 public void setRegistrationBehaviorName(String registrationBehavior) { 117 setRegistrationBehavior(constants.asNumber(registrationBehavior).intValue()); 118 } 119 120 127 public void setServer(MBeanServer server) { 128 this.server = server; 129 } 130 131 136 public void setServiceUrl(String serviceUrl) { 137 this.serviceUrl = serviceUrl; 138 } 139 140 145 public void setThreaded(boolean threaded) { 146 csfb.setThreaded(threaded); 147 } 148 149 public Object getObject() throws Exception { 150 return csfb.getObject(); 151 } 152 153 public Class getObjectType() { 154 return csfb.getObjectType(); 155 } 156 157 public boolean isSingleton() { 158 return csfb.isSingleton(); 159 } 160 161 public void afterPropertiesSet() throws Exception { 162 csfb = new org.springframework.jmx.support.ConnectorServerFactoryBean(); 163 csfb.setDaemon(daemon); 164 csfb.setThreaded(threaded); 165 csfb.setRegistrationBehavior(registrationBehavior); 166 csfb.setEnvironmentMap(environment); 167 csfb.setObjectName(objectName); 168 csfb.setServiceUrl(serviceUrl); 169 csfb.setServer(server); 170 csfb.afterPropertiesSet(); 171 log.info("JMX connector available at: " + serviceUrl); 172 } 173 174 public void destroy() throws Exception { 175 if (csfb != null) { 176 try { 177 csfb.destroy(); 178 } finally { 179 csfb = null; 180 } 181 } 182 } 183 184 } 185 | Popular Tags |