1 17 package org.apache.servicemix.http; 18 19 import javax.jbi.JBIException; 20 import javax.jbi.component.Bootstrap; 21 import javax.jbi.component.InstallationContext; 22 import javax.management.MBeanServer ; 23 import javax.management.ObjectName ; 24 25 32 public class HttpBootstrap implements Bootstrap { 33 34 protected InstallationContext context; 35 protected ObjectName mbeanName; 36 protected HttpConfiguration configuration; 37 38 public HttpBootstrap() { 39 configuration = new HttpConfiguration(); 40 } 41 42 public ObjectName getExtensionMBeanName() { 43 return mbeanName; 44 } 45 46 protected Object getExtensionMBean() throws Exception { 47 return configuration; 48 } 49 50 protected ObjectName createExtensionMBeanName() throws Exception { 51 return this.context.getContext().getMBeanNames().createCustomComponentMBeanName("bootstrap"); 52 } 53 54 57 public void init(InstallationContext installContext) throws JBIException { 58 try { 59 this.context = installContext; 60 doInit(); 61 } catch (JBIException e) { 62 throw e; 63 } catch (Exception e) { 64 throw new JBIException("Error calling init", e); 65 } 66 } 67 68 protected void doInit() throws Exception { 69 Object mbean = getExtensionMBean(); 70 if (mbean != null) { 71 this.mbeanName = createExtensionMBeanName(); 72 MBeanServer server = this.context.getContext().getMBeanServer(); 73 if (server == null) { 74 throw new JBIException("null mBeanServer"); 75 } 76 if (server.isRegistered(this.mbeanName)) { 77 server.unregisterMBean(this.mbeanName); 78 } 79 server.registerMBean(mbean, this.mbeanName); 80 } 81 } 82 83 86 public void cleanUp() throws JBIException { 87 try { 88 doCleanUp(); 89 } catch (JBIException e) { 90 throw e; 91 } catch (Exception e) { 92 throw new JBIException("Error calling cleanUp", e); 93 } 94 } 95 96 protected void doCleanUp() throws Exception { 97 if (this.mbeanName != null) { 98 MBeanServer server = this.context.getContext().getMBeanServer(); 99 if (server == null) { 100 throw new JBIException("null mBeanServer"); 101 } 102 if (server.isRegistered(this.mbeanName)) { 103 server.unregisterMBean(this.mbeanName); 104 } 105 } 106 } 107 108 111 public void onInstall() throws JBIException { 112 try { 113 doOnInstall(); 114 } catch (JBIException e) { 115 throw e; 116 } catch (Exception e) { 117 throw new JBIException("Error calling onInstall", e); 118 } 119 } 120 121 protected void doOnInstall() throws Exception { 122 } 123 124 127 public void onUninstall() throws JBIException { 128 try { 129 doOnUninstall(); 130 } catch (JBIException e) { 131 throw e; 132 } catch (Exception e) { 133 throw new JBIException("Error calling onUninstall", e); 134 } 135 } 136 137 protected void doOnUninstall() throws Exception { 138 } 139 140 } 141 | Popular Tags |