001: /*
002: * BEGIN_HEADER - DO NOT EDIT
003: *
004: * The contents of this file are subject to the terms
005: * of the Common Development and Distribution License
006: * (the "License"). You may not use this file except
007: * in compliance with the License.
008: *
009: * You can obtain a copy of the license at
010: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011: * See the License for the specific language governing
012: * permissions and limitations under the License.
013: *
014: * When distributing Covered Code, include this CDDL
015: * HEADER in each file and include the License file at
016: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017: * If applicable add the following below this CDDL HEADER,
018: * with the fields enclosed by brackets "[]" replaced with
019: * your own identifying information: Portions Copyright
020: * [year] [name of copyright owner]
021: */
022:
023: /*
024: * @(#)TransformationEngineLifeCycle.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package com.sun.jbi.engine.xslt;
030:
031: import com.sun.jbi.engine.xslt.util.ServiceManager;
032: import com.sun.jbi.engine.xslt.util.StringTranslator;
033:
034: import java.util.logging.Logger;
035:
036: import javax.jbi.component.ComponentContext;
037: import javax.jbi.component.ServiceUnitManager;
038:
039: import javax.jbi.messaging.DeliveryChannel;
040: import javax.management.ObjectName;
041:
042: /**
043: * This class implements ComponentLifeCycle. The JBI framework will start this
044: * engine class automatically when JBI framework starts up.
045: *
046: * @author Sun Microsystems, Inc.
047: */
048: public class TransformationEngineLifeCycle implements
049: javax.jbi.component.ComponentLifeCycle, TEResources {
050: /**
051: * Engine context passed down from framework to this transformation engine.
052: */
053: private ComponentContext mContext = null;
054:
055: /**
056: * Engine context passed down from framework to this transformation engine.
057: */
058: private DeliveryChannel mChannel = null;
059:
060: /**
061: * Refernce to logger.
062: */
063: private Logger mLogger = null;
064:
065: /**
066: * Refernce to Receiver.
067: */
068: private Receiver mRcvrProcessor = null;
069:
070: /**
071: * Refernce to service manager.
072: */
073: private ServiceManager mServiceManager = null;
074:
075: /**
076: *
077: */
078: private StringTranslator mTranslator = null;
079:
080: /**
081: *
082: */
083: private TransformationEngineSUManager mSUManager = null;
084:
085: /**
086: *
087: */
088: private boolean mInitSuccess = false;
089:
090: /**
091: * Get the JMX ObjectName for any additional MBean for this BC. If there is
092: * none, return null.
093: *
094: * @return ObjectName the JMX object name of the additional MBean or null
095: * if there is no additional MBean.
096: */
097: public ObjectName getExtensionMBeanName() {
098: return null;
099: }
100:
101: public ServiceUnitManager getSUManager() {
102: return mSUManager;
103: }
104:
105: //javax.jbi.component.ComponentLifeCycle methods
106:
107: /**
108: * Initialize the transformation engine. This performs initialization
109: * required by the transformation engine but does not make it ready to
110: * process messages. This method is called immediately after installation
111: * of the Transformation engine. It is also called when the JBI framework
112: * is starting up, and any time the transformation engine is being
113: * restarted after previously being shut down through a call to
114: * shutDown().
115: *
116: * @param context the JBI environment mContext
117: *
118: * @throws javax.jbi.JBIException if the transformation engine is unable to
119: * initialize.
120: */
121: public void init(javax.jbi.component.ComponentContext context)
122: throws javax.jbi.JBIException {
123: if (context == null) {
124: throw (new javax.jbi.JBIException(mTranslator
125: .getString(TEResources.CONTEXT_IS_NULL),
126: new NullPointerException()));
127: }
128:
129: mContext = context;
130:
131: //Set ComponentContext on TransformationEngineContext
132: TransformationEngineContext teCtx = TransformationEngineContext
133: .getInstance();
134: teCtx.setContext(context);
135:
136: mTranslator = new StringTranslator("com.sun.jbi.engine.xslt",
137: this .getClass().getClassLoader());
138:
139: mLogger = TransformationEngineContext.getInstance().getLogger(
140: "");
141:
142: mServiceManager = ServiceManager.getInstance();
143: mServiceManager.setComponentContext(mContext);
144:
145: mSUManager = new TransformationEngineSUManager();
146: mSUManager.setContext(mContext);
147:
148: mInitSuccess = true;
149: mLogger.info(mTranslator.getString(TEResources.INIT_END));
150: }
151:
152: /**
153: * Shutdown the transformation engine. This performs cleanup before the BPE
154: * is terminated. Once this method has been called, init() must be called
155: * before the transformation engine can be started again with a call to
156: * start().
157: *
158: * @throws javax.jbi.JBIException if the transformation engine is unable to
159: * shut down.
160: */
161: public void shutDown() throws javax.jbi.JBIException {
162: mLogger.info(mTranslator
163: .getString(TEResources.TE_SHUTDOWN_START));
164: mContext = null;
165: mSUManager = null;
166: mServiceManager = null;
167: mRcvrProcessor = null;
168: mLogger
169: .info(mTranslator
170: .getString(TEResources.TE_SHUTDOWN_END));
171: }
172:
173: /**
174: * Start the transformation engine. This makes the BPE ready to process
175: * messages. This method is called after init() completes when the JBI
176: * framework is starting up, and when the transformation engine is being
177: * restarted after a previous call to shutDown(). If stop() was called
178: * previously but shutDown() was not, start() can be called without a call
179: * to init().
180: *
181: * @throws javax.jbi.JBIException if the transformation engine is unable to
182: * start.
183: */
184: public void start() throws javax.jbi.JBIException {
185: mLogger.info(mTranslator.getString(TEResources.ENGINE_STARTED));
186:
187: if (!mInitSuccess) {
188: mLogger.severe(mTranslator
189: .getString(TEResources.INIT_FAILED));
190:
191: return;
192: }
193:
194: mChannel = mContext.getDeliveryChannel();
195:
196: if (mChannel == null) {
197: throw (new javax.jbi.JBIException(mTranslator
198: .getString(TEResources.ENGINE_CHANNEL_IS_NULL),
199: new NullPointerException()));
200: }
201:
202: mRcvrProcessor = new Receiver(mContext);
203:
204: mServiceManager.setComponentContext(mContext);
205: (new Thread(mRcvrProcessor)).start();
206:
207: mLogger.info(mTranslator.getString(TEResources.TE_START_END));
208: }
209:
210: /**
211: * Stop the transformation engine. This makes the BPE stop accepting
212: * messages for processing. After a call to this method, start() can be
213: * called again without first calling init().
214: *
215: * @throws javax.jbi.JBIException if the transformation engine is unable to
216: * stop.
217: */
218: public void stop() throws javax.jbi.JBIException {
219: mLogger.info(mTranslator.getString(TEResources.TE_STOP_START));
220:
221: // To add code to stop all services
222: try {
223: mServiceManager.stopAllServices();
224:
225: if (mRcvrProcessor != null) {
226: mRcvrProcessor.cease();
227: }
228:
229: if (mChannel != null) {
230: mChannel.close();
231: }
232: } catch (Throwable ex) {
233: ex.printStackTrace();
234: }
235:
236: mLogger.info(mTranslator.getString(TEResources.TE_STOP_END));
237: }
238: }
|