001: /*
002: * ChainBuilder ESB
003: * Visual Enterprise Integration
004: *
005: * Copyright (C) 2006 Bostech Corporation
006: *
007: * This program is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU General Public License as published by the
009: * Free Software Foundation; either version 2 of the License, or (at your option)
010: * any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
014: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
015: * for more details.
016: *
017: * You should have received a copy of the GNU General Public License along with
018: * this program; if not, write to the Free Software Foundation, Inc.,
019: * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: *
021: * $Id: BaseBootstrap.java 9412 2007-10-01 16:08:46Z elu $
022: */
023:
024: /*
025: * Licensed to the Apache Software Foundation (ASF) under one or more
026: * contributor license agreements. See the NOTICE file distributed with
027: * this work for additional information regarding copyright ownership.
028: * The ASF licenses this file to You under the Apache License, Version 2.0
029: * (the "License"); you may not use this file except in compliance with
030: * the License. You may obtain a copy of the License at
031: *
032: * http://www.apache.org/licenses/LICENSE-2.0
033: *
034: * Unless required by applicable law or agreed to in writing, software
035: * distributed under the License is distributed on an "AS IS" BASIS,
036: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
037: * See the License for the specific language governing permissions and
038: * limitations under the License.
039: */
040: package com.bostechcorp.cbesb.runtime.ccsl.jbi.messaging;
041:
042: import javax.jbi.JBIException;
043: import javax.jbi.component.Bootstrap;
044: import javax.jbi.component.InstallationContext;
045: import javax.management.InstanceNotFoundException;
046: import javax.management.MBeanRegistrationException;
047: import javax.management.MBeanServer;
048: import javax.management.ObjectName;
049:
050: import org.apache.commons.logging.Log;
051: import org.apache.commons.logging.LogFactory;
052:
053: public class BaseBootstrap implements Bootstrap {
054:
055: protected final transient Log logger = LogFactory
056: .getLog(getClass());
057:
058: protected InstallationContext context;
059: protected ObjectName mbeanName;
060:
061: public BaseBootstrap() {
062: }
063:
064: public ObjectName getExtensionMBeanName() {
065: return mbeanName;
066: }
067:
068: /* (non-Javadoc)
069: * @see org.apache.servicemix.common.BaseBootstrap#getExtensionMBean()
070: */
071: protected Object getExtensionMBean() throws Exception {
072: return null;
073: }
074:
075: protected ObjectName createExtensionMBeanName() throws Exception {
076: return this .context.getContext().getMBeanNames()
077: .createCustomComponentMBeanName("bootstrap");
078: }
079:
080: /* (non-Javadoc)
081: * @see javax.jbi.component.Bootstrap#init(javax.jbi.component.InstallationContext)
082: */
083: public void init(InstallationContext installContext)
084: throws JBIException {
085: try {
086: if (logger.isDebugEnabled()) {
087: logger.debug("Initializing bootstrap");
088: }
089: this .context = installContext;
090: doInit();
091: if (logger.isDebugEnabled()) {
092: logger.debug("Bootstrap initialized");
093: }
094: } catch (JBIException e) {
095: logger.error("Exception in init(): " + e.getMessage());
096: if (logger.isDebugEnabled()) {
097: logger.debug("Exception in init():", e);
098: }
099: throw e;
100: } catch (Exception e) {
101: logger.error("Error calling init: " + e.getMessage());
102: if (logger.isDebugEnabled()) {
103: logger.debug("Error calling init:", e);
104: }
105: throw new JBIException("Error calling init", e);
106: }
107: }
108:
109: protected void doInit() throws Exception {
110: Object mbean = getExtensionMBean();
111: if (mbean != null) {
112: this .mbeanName = createExtensionMBeanName();
113: MBeanServer server = this .context.getContext()
114: .getMBeanServer();
115: if (server == null) {
116: throw new JBIException("null mBeanServer");
117: }
118: if (server.isRegistered(this .mbeanName)) {
119: server.unregisterMBean(this .mbeanName);
120: }
121: server.registerMBean(mbean, this .mbeanName);
122: }
123: }
124:
125: /* (non-Javadoc)
126: * @see javax.jbi.component.Bootstrap#cleanUp()
127: */
128: public void cleanUp() throws JBIException {
129: try {
130: if (logger.isDebugEnabled()) {
131: logger.debug("Cleaning up bootstrap");
132: }
133: doCleanUp();
134: if (logger.isDebugEnabled()) {
135: logger.debug("Bootstrap cleaned up");
136: }
137: } catch (JBIException e) {
138: throw e;
139: } catch (Exception e) {
140: logger.error("Error calling cleanUp: " + e.getMessage());
141: if (logger.isDebugEnabled()) {
142: logger.debug("Error calling cleanUp:", e);
143: }
144: throw new JBIException("Error calling cleanUp", e);
145: }
146: }
147:
148: protected void doCleanUp() throws JBIException {
149: if (this .mbeanName != null) {
150: MBeanServer server = this .context.getContext()
151: .getMBeanServer();
152: if (server == null) {
153: throw new JBIException("null mBeanServer");
154: }
155: if (server.isRegistered(this .mbeanName)) {
156: try {
157: server.unregisterMBean(this .mbeanName);
158: } catch (InstanceNotFoundException e) {
159: new JBIException("MBean instance not found", e);
160: } catch (MBeanRegistrationException e) {
161: // TODO Auto-generated catch block
162: new JBIException(
163: "Exception in unregistering MBean", e);
164: }
165: }
166: }
167: }
168:
169: /* (non-Javadoc)
170: * @see javax.jbi.component.Bootstrap#onInstall()
171: */
172: public void onInstall() throws JBIException {
173: try {
174: if (logger.isDebugEnabled()) {
175: logger.debug("Bootstrap onInstall");
176: }
177: doOnInstall();
178: if (logger.isDebugEnabled()) {
179: logger.debug("Bootstrap onInstall done");
180: }
181: } catch (JBIException e) {
182: logger.error("Error calling onInstall: " + e.getMessage());
183: if (logger.isDebugEnabled()) {
184: logger.debug("Error calling onInstall:", e);
185: }
186: throw e;
187: } catch (Exception e) {
188: logger.error("Error calling onInstall: " + e.getMessage());
189: if (logger.isDebugEnabled()) {
190: logger.debug("Error calling onInstall:", e);
191: }
192: throw new JBIException("Error calling onInstall", e);
193: }
194: }
195:
196: protected void doOnInstall() throws Exception {
197: }
198:
199: /* (non-Javadoc)
200: * @see javax.jbi.component.Bootstrap#onUninstall()
201: */
202: public void onUninstall() throws JBIException {
203: try {
204: if (logger.isDebugEnabled()) {
205: logger.debug("Bootstrap onUninstall");
206: }
207: doOnUninstall();
208: if (logger.isDebugEnabled()) {
209: logger.debug("Bootstrap onUninstall done");
210: }
211: } catch (JBIException e) {
212: logger.error("Exception in onUninstall(): "
213: + e.getMessage());
214: if (logger.isDebugEnabled()) {
215: logger.debug("Exception in onUninstall():", e);
216: }
217: throw e;
218: } catch (Exception e) {
219: logger.error("Exception in onUninstall(): "
220: + e.getMessage());
221: if (logger.isDebugEnabled()) {
222: logger.debug("Exception in onUninstall():", e);
223: }
224: throw new JBIException("Error calling onUninstall", e);
225: }
226: }
227:
228: protected void doOnUninstall() throws Exception {
229: }
230:
231: }
|