1 17 package org.apache.servicemix.jbi.framework; 18 19 import javax.jbi.JBIException; 20 import javax.management.JMException ; 21 import javax.management.MBeanOperationInfo ; 22 import javax.naming.NamingException ; 23 24 import org.apache.commons.logging.Log; 25 import org.apache.commons.logging.LogFactory; 26 import org.apache.servicemix.client.DefaultServiceMixClient; 27 import org.apache.servicemix.client.ServiceMixClient; 28 import org.apache.servicemix.jbi.management.BaseSystemService; 29 import org.apache.servicemix.jbi.management.OperationInfoHelper; 30 31 34 public class ClientFactory extends BaseSystemService implements ClientFactoryMBean { 35 36 private static final Log logger = LogFactory.getLog(ClientFactory.class); 37 38 private String jndiName = DEFAULT_JNDI_NAME; 39 40 public ClientFactory() { 41 } 42 43 46 public String getJndiName() { 47 return jndiName; 48 } 49 50 53 public void setJndiName(String jndiName) { 54 this.jndiName = jndiName; 55 } 56 57 public ServiceMixClient createClient() throws JBIException { 58 return new DefaultServiceMixClient(getContainer()); 59 } 60 61 protected Class getServiceMBean() { 62 return ClientFactoryMBean.class; 63 } 64 65 public String getDescription() { 66 return "Client Factory Service"; 67 } 68 69 public MBeanOperationInfo [] getOperationInfos() throws JMException { 70 OperationInfoHelper helper = new OperationInfoHelper(); 71 helper.addOperation(getObjectToManage(), "createClient", 0, "create a new client"); 72 return OperationInfoHelper.join(super.getOperationInfos(), helper.getOperationInfos()); 73 } 74 75 80 public void start() throws javax.jbi.JBIException { 81 try { 82 getContainer().getNamingContext().bind(jndiName, this); 83 super.start(); 84 } catch (NamingException e) { 85 logger.error("Cound not start ClientFactory: " + e); 86 if (logger.isDebugEnabled()) { 87 logger.debug("Could not start ClientFactory", e); 88 } 89 } 90 } 91 92 97 public void stop() throws javax.jbi.JBIException { 98 try { 99 super.stop(); 100 getContainer().getNamingContext().unbind(jndiName); 101 } catch (NamingException e) { 102 logger.error("Cound not stop ClientFactory: " + e); 103 if (logger.isDebugEnabled()) { 104 logger.debug("Could not stop ClientFactory", e); 105 } 106 } 107 } 108 109 } 110 | Popular Tags |