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: * @(#)Engine.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package com.sun.jbi.framework;
030:
031: import java.util.logging.Logger;
032:
033: import javax.jbi.component.ComponentContext;
034:
035: /**
036: * This is an implementation of a Service Engine that is purely for
037: * unit testing. It does nothing other than log messages when its methods
038: * are called.
039: *
040: * @author Sun Microsystems, Inc.
041: */
042: public class Engine extends AbstractComponent {
043: /**
044: * Special flag for causing failure on second call to init().
045: */
046: private boolean mFirst = true;
047:
048: /**
049: * Constant for timeout tests - 1 minute sleep interval (in milliseconds).
050: */
051: private static final long TIMEOUT_INTERVAL = 60000;
052:
053: /**
054: * Public Constructor.
055: */
056: public Engine() {
057: mLog = Logger.getLogger("com.sun.jbi.framework.test.Engine");
058: mComponentType = "Engine";
059: }
060:
061: //
062: // Overridden ComponentLifeCycle methods
063: //
064:
065: /**
066: * Initialize the Service Engine.
067: * @param context the JBI component context created by the JBI framework.
068: * @throws javax.jbi.JBIException if an error occurs.
069: */
070: public void init(ComponentContext context)
071: throws javax.jbi.JBIException {
072: if (null != context) {
073: mContext = context;
074: mComponentName = context.getComponentName();
075: if (mComponentName.equals(Constants.SE_NAME_BAD_INIT)) {
076: throw new javax.jbi.JBIException("EngineBadInit");
077: } else {
078: mLog.info("Engine " + mComponentName + " initialized");
079: }
080: } else {
081: throw new javax.jbi.JBIException(
082: "Null argument received for " + "ComponentContext");
083: }
084:
085: // This code is here to allow a special test case to run, where the
086: // engine is being started after having been shut down, and the
087: // init() method throws an exception. The second time init() is
088: // called, it throws an exception.
089:
090: if (mFirst) {
091: mFirst = false;
092: } else {
093: throw new javax.jbi.JBIException(
094: "Engine initialization failed");
095: }
096: }
097:
098: /**
099: * Get the JMX ObjectName for any additional MBean for this SE. This
100: * implementation always returns null.
101: * @return javax.management.ObjectName is always null.
102: */
103: public javax.management.ObjectName getExtensionMBeanName() {
104: return null;
105: }
106:
107: /**
108: * Start the Service Engine.
109: * @throws javax.jbi.JBIException if an error occurs.
110: */
111: public void start() throws javax.jbi.JBIException {
112: if (mComponentName.equals(Constants.SE_NAME_BAD_START)) {
113: throw new javax.jbi.JBIException("EngineBadStart");
114: } else if (mComponentName
115: .equals(Constants.SE_NAME_TIMEOUT_START)) {
116: try {
117: Thread.sleep(TIMEOUT_INTERVAL); /* 5 minutes */
118: } catch (java.lang.InterruptedException iEx) {
119: throw new javax.jbi.JBIException("EngineInterrupted");
120: }
121: } else {
122: mLog.info("Engine " + mComponentName + " started");
123: }
124: }
125:
126: /**
127: * Stop the Service Engine.
128: * @throws javax.jbi.JBIException if an error occurs.
129: */
130: public void stop() throws javax.jbi.JBIException {
131: if (mComponentName.equals(Constants.SE_NAME_BAD_STOP)) {
132: throw new javax.jbi.JBIException("EngineBadStop");
133: } else if (mComponentName
134: .equals(Constants.SE_NAME_TIMEOUT_STOP)) {
135: try {
136: Thread.sleep(TIMEOUT_INTERVAL); /* 5 minutes */
137: } catch (java.lang.InterruptedException iEx) {
138: throw new javax.jbi.JBIException("EngineInterrupted");
139: }
140: } else {
141: mLog.info("Engine " + mComponentName + " stopped");
142: }
143: }
144:
145: /**
146: * Shut down the Service Engine.
147: * @throws javax.jbi.JBIException if an error occurs.
148: */
149: public void shutDown() throws javax.jbi.JBIException {
150: if (mComponentName.equals(Constants.SE_NAME_BAD_SHUTDOWN)) {
151: throw new javax.jbi.JBIException("EngineBadShutdown");
152: } else if (mComponentName
153: .equals(Constants.SE_NAME_BAD_SHUTDOWN_BOOTSTRAP_ONUNINSTALL)) {
154: throw new javax.jbi.JBIException("EngineBadShutdown");
155: } else if (mComponentName
156: .equals(Constants.SE_NAME_TIMEOUT_SHUTDOWN)) {
157: try {
158: Thread.sleep(TIMEOUT_INTERVAL); /* 5 minutes */
159: } catch (java.lang.InterruptedException iEx) {
160: throw new javax.jbi.JBIException("EngineInterrupted");
161: }
162: } else {
163: mLog.info("Engine " + mComponentName + " shut down");
164: }
165: }
166:
167: //
168: // ServiceUnitManager methods
169: //
170:
171: /**
172: * Deploy a Service Unit.
173: * @param serviceUnitName the name of the Service Unit being deployed.
174: * @param serviceUnitRootPath the full path to the Service Unit artifact
175: * root directory.
176: * @return a deployment status message.
177: * @throws javax.jbi.management.DeploymentException if the deployment
178: * operation is unsuccessful.
179: */
180: public String deploy(String serviceUnitName,
181: String serviceUnitRootPath)
182: throws javax.jbi.management.DeploymentException {
183: mLog.info("Engine " + mComponentName
184: + " deployed Service Unit " + serviceUnitName);
185: return null;
186: }
187:
188: /**
189: * Initialize the deployment.
190: * @param serviceUnitName the name of the Service Unit being initialized.
191: * @param serviceUnitRootPath the full path to the Service Unit artifact
192: * root directory.
193: * @throws javax.jbi.management.DeploymentException if the Service Unit is
194: * not deployed, or is in an incorrect state.
195: */
196: public void init(String serviceUnitName, String serviceUnitRootPath)
197: throws javax.jbi.management.DeploymentException {
198: mLog.info("Engine " + mComponentName
199: + " initialized Service Unit " + serviceUnitName);
200: }
201:
202: /**
203: * Shut down the deployment.
204: * @param serviceUnitName the name of the Service Unit being shut down.
205: * @throws javax.jbi.management.DeploymentException if the Service Unit
206: * is not deployed, or is in an incorrect state.
207: */
208: public void shutDown(String serviceUnitName)
209: throws javax.jbi.management.DeploymentException {
210: mLog.info("Engine " + mComponentName
211: + " shut down Service Unit " + serviceUnitName);
212: }
213:
214: /**
215: * Start the deployment.
216: * @param serviceUnitName the name of the Service Unit being started.
217: * @throws javax.jbi.management.DeploymentException if the Service Unit
218: * is not deployed, or is in an incorrect state.
219: */
220: public void start(String serviceUnitName)
221: throws javax.jbi.management.DeploymentException {
222: mLog.info("Engine " + mComponentName + " started Service Unit "
223: + serviceUnitName);
224: }
225:
226: /**
227: * Stop the deployment.
228: * @param serviceUnitName the name of the Service Unit being stopped.
229: * @throws javax.jbi.management.DeploymentException if the Service Unit
230: * is not deployed, or is in an incorrect state.
231: */
232: public void stop(String serviceUnitName)
233: throws javax.jbi.management.DeploymentException {
234: mLog.info("Engine " + mComponentName + " stopped Service Unit "
235: + serviceUnitName);
236: }
237:
238: /**
239: * Undeploy a Service Unit from the component.
240: * @param serviceUnitName the name of the Service Unit being undeployed.
241: * @param serviceUnitRootPath the full path to the Service Unit artifact
242: * root directory.
243: * @return an undeployment status message.
244: * @throws javax.jbi.management.DeploymentException if the undeployment
245: * operation is unsuccessful.
246: */
247: public String undeploy(String serviceUnitName,
248: String serviceUnitRootPath)
249: throws javax.jbi.management.DeploymentException {
250: mLog.info("Engine " + mComponentName
251: + " undeployed Service Unit " + serviceUnitName);
252: return null;
253: }
254: }
|