1 17 package org.apache.servicemix.common; 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 40 public class BaseBootstrap implements Bootstrap { 41 42 protected final transient Log logger = LogFactory.getLog(getClass()); 43 44 protected InstallationContext context; 45 protected ObjectName mbeanName; 46 47 public BaseBootstrap() { 48 } 49 50 public ObjectName getExtensionMBeanName() { 51 return mbeanName; 52 } 53 54 protected Object getExtensionMBean() throws Exception { 55 return null; 56 } 57 58 protected ObjectName createExtensionMBeanName() throws Exception { 59 return this.context.getContext().getMBeanNames().createCustomComponentMBeanName("bootstrap"); 60 } 61 62 65 public void init(InstallationContext installContext) throws JBIException { 66 try { 67 if (logger.isDebugEnabled()) { 68 logger.debug("Initializing bootstrap"); 69 } 70 this.context = installContext; 71 doInit(); 72 if (logger.isDebugEnabled()) { 73 logger.debug("Bootstrap initialized"); 74 } 75 } catch (JBIException e) { 76 throw e; 77 } catch (Exception e) { 78 throw new JBIException("Error calling init", e); 79 } 80 } 81 82 protected void doInit() throws Exception { 83 Object mbean = getExtensionMBean(); 84 if (mbean != null) { 85 this.mbeanName = createExtensionMBeanName(); 86 MBeanServer server = this.context.getContext().getMBeanServer(); 87 if (server == null) { 88 throw new JBIException("null mBeanServer"); 89 } 90 if (server.isRegistered(this.mbeanName)) { 91 server.unregisterMBean(this.mbeanName); 92 } 93 server.registerMBean(mbean, this.mbeanName); 94 } 95 } 96 97 100 public void cleanUp() throws JBIException { 101 try { 102 if (logger.isDebugEnabled()) { 103 logger.debug("Cleaning up bootstrap"); 104 } 105 doCleanUp(); 106 if (logger.isDebugEnabled()) { 107 logger.debug("Bootstrap cleaned up"); 108 } 109 } catch (JBIException e) { 110 throw e; 111 } catch (Exception e) { 112 throw new JBIException("Error calling cleanUp", e); 113 } 114 } 115 116 protected void doCleanUp() throws Exception { 117 if (this.mbeanName != null) { 118 MBeanServer server = this.context.getContext().getMBeanServer(); 119 if (server == null) { 120 throw new JBIException("null mBeanServer"); 121 } 122 if (server.isRegistered(this.mbeanName)) { 123 server.unregisterMBean(this.mbeanName); 124 } 125 } 126 } 127 128 131 public void onInstall() throws JBIException { 132 try { 133 if (logger.isDebugEnabled()) { 134 logger.debug("Bootstrap onInstall"); 135 } 136 doOnInstall(); 137 if (logger.isDebugEnabled()) { 138 logger.debug("Bootstrap onInstall done"); 139 } 140 } catch (JBIException e) { 141 throw e; 142 } catch (Exception e) { 143 throw new JBIException("Error calling onInstall", e); 144 } 145 } 146 147 protected void doOnInstall() throws Exception { 148 } 149 150 153 public void onUninstall() throws JBIException { 154 try { 155 if (logger.isDebugEnabled()) { 156 logger.debug("Bootstrap onUninstall"); 157 } 158 doOnUninstall(); 159 if (logger.isDebugEnabled()) { 160 logger.debug("Bootstrap onUninstall done"); 161 } 162 } catch (JBIException e) { 163 throw e; 164 } catch (Exception e) { 165 throw new JBIException("Error calling onUninstall", e); 166 } 167 } 168 169 protected void doOnUninstall() throws Exception { 170 } 171 172 } 173 | Popular Tags |