1 17 package org.apache.servicemix.bpe; 18 19 import org.apache.commons.logging.Log; 20 import org.apache.commons.logging.LogFactory; 21 22 import javax.jbi.JBIException; 23 import javax.jbi.component.Bootstrap; 24 import javax.jbi.component.InstallationContext; 25 import javax.management.MBeanServer ; 26 import javax.management.ObjectName ; 27 28 35 public class BPEBootstrap implements Bootstrap { 36 37 protected final transient Log logger = LogFactory.getLog(getClass()); 38 39 protected InstallationContext context; 40 protected ObjectName mbeanName; 41 42 public BPEBootstrap() { 43 } 44 45 public ObjectName getExtensionMBeanName() { 46 return mbeanName; 47 } 48 49 protected Object getExtensionMBean() throws Exception { 50 return null; 51 } 52 53 protected ObjectName createExtensionMBeanName() throws Exception { 54 return this.context.getContext().getMBeanNames().createCustomComponentMBeanName("bootstrap"); 55 } 56 57 60 public void init(InstallationContext installContext) throws JBIException { 61 try { 62 if (logger.isDebugEnabled()) { 63 logger.debug("Initializing bootstrap"); 64 } 65 this.context = installContext; 66 doInit(); 67 if (logger.isDebugEnabled()) { 68 logger.debug("Bootstrap initialized"); 69 } 70 } catch (JBIException e) { 71 throw e; 72 } catch (Exception e) { 73 throw new JBIException("Error calling init", e); 74 } 75 } 76 77 protected void doInit() throws Exception { 78 Object mbean = getExtensionMBean(); 79 if (mbean != null) { 80 this.mbeanName = createExtensionMBeanName(); 81 MBeanServer server = this.context.getContext().getMBeanServer(); 82 if (server == null) { 83 throw new JBIException("null mBeanServer"); 84 } 85 if (server.isRegistered(this.mbeanName)) { 86 server.unregisterMBean(this.mbeanName); 87 } 88 server.registerMBean(mbean, this.mbeanName); 89 } 90 } 91 92 95 public void cleanUp() throws JBIException { 96 try { 97 if (logger.isDebugEnabled()) { 98 logger.debug("Cleaning up bootstrap"); 99 } 100 doCleanUp(); 101 if (logger.isDebugEnabled()) { 102 logger.debug("Bootstrap cleaned up"); 103 } 104 } catch (JBIException e) { 105 throw e; 106 } catch (Exception e) { 107 throw new JBIException("Error calling cleanUp", e); 108 } 109 } 110 111 protected void doCleanUp() throws Exception { 112 if (this.mbeanName != null) { 113 MBeanServer server = this.context.getContext().getMBeanServer(); 114 if (server == null) { 115 throw new JBIException("null mBeanServer"); 116 } 117 if (server.isRegistered(this.mbeanName)) { 118 server.unregisterMBean(this.mbeanName); 119 } 120 } 121 } 122 123 126 public void onInstall() throws JBIException { 127 try { 128 if (logger.isDebugEnabled()) { 129 logger.debug("Bootstrap onInstall"); 130 } 131 doOnInstall(); 132 if (logger.isDebugEnabled()) { 133 logger.debug("Bootstrap onInstall done"); 134 } 135 } catch (JBIException e) { 136 throw e; 137 } catch (Exception e) { 138 throw new JBIException("Error calling onInstall", e); 139 } 140 } 141 142 protected void doOnInstall() throws Exception { 143 } 144 145 148 public void onUninstall() throws JBIException { 149 try { 150 if (logger.isDebugEnabled()) { 151 logger.debug("Bootstrap onUninstall"); 152 } 153 doOnUninstall(); 154 if (logger.isDebugEnabled()) { 155 logger.debug("Bootstrap onUninstall done"); 156 } 157 } catch (JBIException e) { 158 throw e; 159 } catch (Exception e) { 160 throw new JBIException("Error calling onUninstall", e); 161 } 162 } 163 164 protected void doOnUninstall() throws Exception { 165 } 166 167 } 168 | Popular Tags |