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: * @(#)JBIFramework.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 com.sun.jbi.JBIProvider;
032: import com.sun.jbi.management.system.ManagementContext;
033: import com.sun.jbi.platform.PlatformContext;
034:
035: import java.util.Date;
036: import java.util.Properties;
037: import java.util.logging.Level;
038: import java.util.logging.Logger;
039:
040: import javax.management.MBeanServer;
041: import javax.naming.Context;
042: import javax.naming.InitialContext;
043:
044: /**
045: * This is the top-level class that provides the lifecycle for the JBI
046: * framework. The methods defined here are called by a wrapper that is specific
047: * to a particular application server implementation.
048: *
049: * @author Sun Microsystems, Inc.
050: */
051: public class JBIFramework {
052: /**
053: * The global context for the entire framework environment.
054: */
055: protected EnvironmentContext mEnvironment;
056:
057: /**
058: * The Logger instance for the framework.
059: */
060: private Logger mLog;
061:
062: /**
063: * Total elapsed time used by framework startup, in milliseconds.
064: */
065: private long mStartupElapsedTime;
066:
067: /**
068: * Total elapsed time used by framework shutdown, in milliseconds.
069: */
070: private long mShutdownElapsedTime;
071:
072: /**
073: * The StringTranslator instance for the framework.
074: */
075: private StringTranslator mTranslator;
076:
077: /**
078: * Framework start failure flag
079: */
080: private boolean mStartFailed;
081:
082: /**
083: * Component Framework started flag
084: */
085: private boolean mCfStarted;
086:
087: /**
088: * Component Registry started flag
089: */
090: private boolean mCrStarted;
091:
092: /**
093: * Configuration Service started flag
094: */
095: private boolean mCsStarted;
096:
097: /**
098: * Management Service started flag
099: */
100: private boolean mMsStarted;
101:
102: /**
103: * Normalized Message Service started flag
104: */
105: private boolean mNmsStarted;
106:
107: /**
108: * Management Runtime Service started flag
109: */
110: private boolean mMrsStarted;
111:
112: /**
113: * Flag used to indicate that the framework has started completely.
114: * In the case of a lazy initialization, mFrameworkReady will remain
115: * false until the first request for a system resource (e.g. registry),
116: * at which point the framework will be started completely and this flag
117: * will be set to true.
118: */
119: private boolean mFrameworkReady;
120:
121: /**
122: * Flag used to indicate that this is a "lazy" initializtion. This happens
123: * when there are no components that need to be any state other than
124: * <code>SHUTDOWN</code>. In this case, , mFrameworkReady will remain
125: * false until the first request for a system resource (e.g. registry),
126: * at which point the framework will be started completely.
127: */
128: private boolean mLazyInit;
129:
130: /**
131: * This method initializes the JBI framework.
132: *
133: * @param initialProperties the Properties provider.
134: * @param platformContext the PlatformContext instance.
135: * @throws javax.jbi.JBIException if any error occurs.
136: */
137: public void init(PlatformContext platformContext,
138: Properties initialProperties) throws javax.jbi.JBIException {
139: // Get time this method was entered
140: long startTime = System.currentTimeMillis();
141:
142: // Create and initialize the Environment Context. This is a singleton.
143: mEnvironment = new EnvironmentContext(platformContext, this ,
144: initialProperties);
145:
146: // Initialize common utility class.
147: com.sun.jbi.util.jmx.MBeanUtils.init(platformContext
148: .getMBeanServer());
149:
150: // Obtain the logger and message translator for the framework.
151: mLog = mEnvironment.getLogger();
152: mLog.finest("JBIFramework.init entered");
153: mTranslator = (StringTranslator) mEnvironment
154: .getStringTranslator("com.sun.jbi.framework");
155:
156: mLog.fine(mTranslator
157: .getString(LocalStringKeys.JBI_INITIALIZING));
158:
159: // Initialize the JBI repository
160: initRepository();
161:
162: // Initialize core services. If one fails, exit immediately.
163: boolean initFailed = false;
164: String serviceName = null;
165: try {
166: /**
167: * Initialize the Configuration Service.
168: * NOTE : This should always be the first service being initialized
169: * since other services depend on the Configuration MBeans registered
170: * by this service.
171: */
172: serviceName = mTranslator
173: .getString(LocalStringKeys.CS_NAME);
174: mEnvironment.getConfigurationService().initService(
175: mEnvironment);
176:
177: // Initialize the Normalized Message Service
178: serviceName = mTranslator
179: .getString(LocalStringKeys.NMS_NAME);
180: mEnvironment.getNormalizedMessageService().initService(
181: mEnvironment);
182:
183: // Initialize the Component Registry
184: serviceName = mTranslator
185: .getString(LocalStringKeys.CR_NAME);
186: mEnvironment.getComponentRegistry().initService(
187: mEnvironment);
188:
189: // Initialize the Component Framework
190: serviceName = mTranslator
191: .getString(LocalStringKeys.CF_NAME);
192: mEnvironment.getComponentFramework().initService(
193: mEnvironment);
194:
195: // Initialize the Management Service LAST
196: serviceName = mTranslator
197: .getString(LocalStringKeys.MS_NAME);
198: mEnvironment.getManagementService().initService(
199: mEnvironment);
200: } catch (Throwable initEx) {
201: initFailed = true;
202: logFailure(serviceName, initEx,
203: LocalStringKeys.INIT_SERVICE_FAILED);
204: }
205:
206: // If any service failed to initialize, prevent the framework from
207: // starting.
208: if (initFailed) {
209: String msg = mTranslator
210: .getString(LocalStringKeys.INIT_FRAMEWORK_FAILED);
211: mLog.severe(msg);
212: throw new javax.jbi.JBIException(msg);
213: }
214:
215: mLog.fine(mTranslator
216: .getString(LocalStringKeys.JBI_INITIALIZED));
217: mLog.finest("JBIFramework.init exited");
218:
219: // Add total time used by this method to startup elapsed time
220: mStartupElapsedTime = System.currentTimeMillis() - startTime;
221: }
222:
223: /**
224: * Here all we do is initialize the JNDI naming context and the Management
225: * Runtime Service. This is the minimal initialization required.
226: * @param context contains the JBI InitialContext
227: * @param namingprefix used from JNDI resolution.
228: * @throws javax.jbi.JBIException if any error occurs.
229: */
230: public void startup(InitialContext context, String namingprefix)
231: throws javax.jbi.JBIException {
232: // Get time this method was entered
233: long startTime = System.currentTimeMillis();
234: mLog.finest("JBIFramework.startup entered");
235:
236: mLog.fine(mTranslator.getString(LocalStringKeys.JBI_STARTING));
237:
238: mEnvironment.setNamingContext(context);
239: mEnvironment.setNamingPrefix(namingprefix);
240:
241: // Initialize the Management Runtime Service.
242: try {
243: removeStoppedStateFile();
244: mEnvironment.getMgmtRuntimeService().initService(
245: mEnvironment);
246: createStartedStateFile();
247: } catch (Throwable mrsEx) {
248: mStartFailed = true;
249: logFailure(mTranslator.getString(LocalStringKeys.MRS_NAME),
250: mrsEx, LocalStringKeys.INIT_SERVICE_FAILED);
251: }
252:
253: // If any service failed to start, prevent the framework from
254: // starting.
255:
256: if (mStartFailed) {
257: String msg = mTranslator
258: .getString(LocalStringKeys.START_FRAMEWORK_FAILED);
259: mLog.severe(msg);
260: throw new javax.jbi.JBIException(msg);
261: }
262:
263: // Register the Logger MBean for the Framework
264: mEnvironment.createLoggerMBeans();
265:
266: // Set up instance/cluster name properties as convenience for components
267:
268: PlatformContext platform = mEnvironment.getPlatformContext();
269: String instanceName = platform.getInstanceName();
270: System.setProperty("com.sun.jbi.instanceName", instanceName);
271: Boolean clustered = new Boolean(platform
272: .isInstanceClustered(instanceName));
273: System.setProperty("com.sun.jbi.isClustered", clustered
274: .toString());
275: if (clustered) {
276: String clusterName = platform.getTargetName();
277: System.setProperty("com.sun.jbi.clusterName", clusterName);
278: }
279:
280: String readyMsg = mTranslator
281: .getString(LocalStringKeys.JBI_READY);
282: mLog.info(readyMsg);
283: mEnvironment.getNotifier().emitRuntimeNotification(
284: EventNotifier.EventType.Ready, readyMsg);
285: mLog.finest("JBIFramework.startup exited");
286: // Add total time used by this method to startup elapsed time
287: mStartupElapsedTime += System.currentTimeMillis() - startTime;
288: setStartupTime();
289: }
290:
291: /**
292: * This method prepares the JBI and component resources for recovery.
293: *
294: * @throws javax.jbi.JBIException if any error occurs.
295: */
296: public void prepare() throws javax.jbi.JBIException {
297: // Get time this method was entered
298: long startTime = System.currentTimeMillis();
299: mLog.finest("JBIFramework.prepare entered");
300:
301: // Start the Component Registry
302: try {
303: //
304: // Defer the cleaning until we know we are going to start.
305: //
306: com.sun.jbi.management.system.ManagementContext mgmtCtx = new com.sun.jbi.management.system.ManagementContext(
307: mEnvironment);
308: mgmtCtx.getRepository().cleanRepository();
309:
310: mEnvironment.getComponentRegistry().startService();
311: mCrStarted = true;
312: } catch (Throwable crEx) {
313: mStartFailed = true;
314: logFailure(mTranslator.getString(LocalStringKeys.CR_NAME),
315: crEx, LocalStringKeys.START_SERVICE_FAILED);
316: String msg = mTranslator
317: .getString(LocalStringKeys.INIT_FRAMEWORK_FAILED);
318: mLog.severe(msg);
319: throw new javax.jbi.JBIException(msg);
320: }
321:
322: // Inform the ComponentFramework that it can prepare components now.
323: mEnvironment.getComponentFramework().prepare();
324:
325: mLog.finest("JBIFramework.prepare exited");
326:
327: // Add total time used by this method to startup elapsed time
328: mStartupElapsedTime += System.currentTimeMillis() - startTime;
329: }
330:
331: /**
332: * This method makes the JBI framework ready to process requests.
333: * This is where the remaining framework services are
334: * started, as all AppServer services are now available.
335: * @param wait when true, waits for startup to complete before returning.
336: * @throws javax.jbi.JBIException if any error occurs.
337: */
338: public void ready(boolean wait) throws javax.jbi.JBIException {
339: // Get time this method was entered
340: long startTime = System.currentTimeMillis();
341:
342: mLog.finest("JBIFramework.ready entered");
343:
344: if (mStartFailed) {
345: return;
346: }
347:
348: // Start core services. If one fails, exit immediately.
349: String serviceName = null;
350: try {
351: // Start the Configuration Service
352: serviceName = mTranslator
353: .getString(LocalStringKeys.CS_NAME);
354: mEnvironment.getConfigurationService().startService();
355: mCsStarted = true;
356:
357: // Start the Normalized Message Service
358: serviceName = mTranslator
359: .getString(LocalStringKeys.NMS_NAME);
360: mEnvironment.getNormalizedMessageService().startService();
361: mNmsStarted = true;
362:
363: // Start the Component Framework
364: serviceName = mTranslator
365: .getString(LocalStringKeys.CF_NAME);
366: mEnvironment.getComponentFramework().startService();
367: mCfStarted = true;
368:
369: // Start the Management Service
370: serviceName = mTranslator
371: .getString(LocalStringKeys.MS_NAME);
372: mEnvironment.getManagementService().startService();
373: mMsStarted = true;
374:
375: // Start the Management Runtime Service
376: // DO NOT MOVE THIS - this must remain in the ready() processing
377: // to ensure that the appserver domain config has completed first.
378: serviceName = mTranslator
379: .getString(LocalStringKeys.MRS_NAME);
380: mEnvironment.getMgmtRuntimeService().startService();
381: mMrsStarted = true;
382:
383: } catch (Throwable startEx) {
384: mStartFailed = true;
385: logFailure(serviceName, startEx,
386: LocalStringKeys.START_SERVICE_FAILED);
387: }
388:
389: // If any service failed to start, prevent the framework from
390: // starting.
391: if (mStartFailed) {
392: String msg = mTranslator
393: .getString(LocalStringKeys.START_FRAMEWORK_FAILED);
394: mLog.severe(msg);
395: throw new javax.jbi.JBIException(msg);
396: }
397:
398: // Inform the ComponentFramework that it can startup components now.
399: mEnvironment.getComponentFramework().ready(wait);
400:
401: //
402: // Mark the framework as ready, and signal anyone waiting in
403: // frameworkReady().
404: //
405: synchronized (this ) {
406: mFrameworkReady = true;
407: this .notifyAll();
408: }
409:
410: // Add total time used by this method to startup elapsed time and
411: // log the total startup time. Also add the time used by the prepare()
412: // method in case it ran. Update statistics for total startup time and
413: // last restart time.
414:
415: mStartupElapsedTime += System.currentTimeMillis() - startTime;
416: mLog.fine(mTranslator.getString(
417: LocalStringKeys.JBI_STARTUP_TIME, new Long(
418: getStartupTime())));
419: setStartupTime();
420: mEnvironment.getFrameworkStatistics().setLastRestartTime(
421: new Date());
422:
423: String startedMsg = mTranslator
424: .getString(LocalStringKeys.JBI_STARTED);
425: mLog.info(startedMsg);
426: mEnvironment.getNotifier().emitRuntimeNotification(
427: EventNotifier.EventType.Started, startedMsg);
428: mLog.finest("JBIFramework.ready exited");
429: }
430:
431: /**
432: * This method returns the startup time for the JBI Framework. It may be overridden
433: * for specific AS types. Sun AS provider includes the cost of synchronization.
434: * @return long - time for startup
435: */
436: public long getStartupTime() {
437: return (mStartupElapsedTime);
438: }
439:
440: public void setStartupTime() {
441: mEnvironment.getFrameworkStatistics().setStartupTime(
442: getStartupTime());
443: }
444:
445: /**
446: * This method stops the JBI framework and all its services and
447: * components.
448: * @throws javax.jbi.JBIException if any error occurs.
449: */
450: public void shutdown() throws javax.jbi.JBIException {
451: // Get time this method was entered
452: long startTime = System.currentTimeMillis();
453:
454: mLog.finest("JBIFramework.shutdown entered");
455: mLog.fine(mTranslator
456: .getString(LocalStringKeys.JBI_SHUTTING_DOWN));
457:
458: boolean errors = false;
459:
460: if (mMrsStarted) {
461: try {
462: removeStartedStateFile();
463: mEnvironment.getMgmtRuntimeService().stopService();
464: mMrsStarted = false;
465: } catch (Throwable mrsEx) {
466: errors = true;
467: logFailure(mTranslator
468: .getString(LocalStringKeys.MRS_NAME), mrsEx,
469: LocalStringKeys.STOP_SERVICE_FAILED);
470: }
471: }
472:
473: if (mCfStarted) {
474: try {
475: mEnvironment.getComponentFramework().stopService();
476: mCfStarted = false;
477: } catch (Throwable cfEx) {
478: errors = true;
479: logFailure(mTranslator
480: .getString(LocalStringKeys.CF_NAME), cfEx,
481: LocalStringKeys.STOP_SERVICE_FAILED);
482: }
483: }
484: if (mCrStarted) {
485: try {
486: mEnvironment.getComponentRegistry().stopService();
487: mCrStarted = false;
488: } catch (Throwable crEx) {
489: errors = true;
490: logFailure(mTranslator
491: .getString(LocalStringKeys.CR_NAME), crEx,
492: LocalStringKeys.STOP_SERVICE_FAILED);
493: }
494: }
495: if (mNmsStarted) {
496: try {
497: mEnvironment.getNormalizedMessageService()
498: .stopService();
499: mNmsStarted = false;
500: } catch (Throwable nmsEx) {
501: errors = true;
502: logFailure(mTranslator
503: .getString(LocalStringKeys.NMS_NAME), nmsEx,
504: LocalStringKeys.STOP_SERVICE_FAILED);
505: }
506: }
507: if (mMsStarted) {
508: try {
509: mEnvironment.getManagementService().stopService();
510: mMsStarted = false;
511: } catch (Throwable msEx) {
512: errors = true;
513: logFailure(mTranslator
514: .getString(LocalStringKeys.MS_NAME), msEx,
515: LocalStringKeys.STOP_SERVICE_FAILED);
516: }
517: }
518: if (mCsStarted) {
519: try {
520: mEnvironment.getConfigurationService().stopService();
521: mCsStarted = false;
522: } catch (Throwable msEx) {
523: errors = true;
524: logFailure(mTranslator
525: .getString(LocalStringKeys.CS_NAME), msEx,
526: LocalStringKeys.STOP_SERVICE_FAILED);
527: }
528: }
529:
530: String shutMsg = mTranslator
531: .getString(LocalStringKeys.JBI_SHUT_DOWN);
532: if (!errors) {
533: mLog.fine(shutMsg);
534: } else {
535: mLog.warning(mTranslator
536: .getString(LocalStringKeys.STOP_FRAMEWORK_FAILED));
537: }
538:
539: EventNotifier notifier = (EventNotifier) mEnvironment
540: .getNotifier();
541: notifier.emitRuntimeNotification(
542: EventNotifier.EventType.Stopped, shutMsg);
543: notifier.instanceStopping();
544: createStoppedStateFile();
545: mLog.finest("JBIFramework.shutdown exited");
546:
547: // Add total time used by this method to shutdown elapsed time
548: mShutdownElapsedTime += System.currentTimeMillis() - startTime;
549: }
550:
551: /**
552: * This method terminates the JBI framework and releases all resources.
553: * @throws javax.jbi.JBIException if any error occurs.
554: */
555: public void terminate() throws javax.jbi.JBIException {
556: // Get time this method was entered
557: long startTime = System.currentTimeMillis();
558:
559: mLog.finest("JBIFramework.terminate entered");
560: mLog.fine(mTranslator
561: .getString(LocalStringKeys.JBI_TERMINATING));
562:
563: mEnvironment.destroyInstance();
564:
565: mLog
566: .info(mTranslator
567: .getString(LocalStringKeys.JBI_TERMINATED));
568: mLog.finest("JBIFramework.terminate exited");
569:
570: // Add total time used by this method to shutdown elapsed time
571: mShutdownElapsedTime += System.currentTimeMillis() - startTime;
572: mLog.fine(mTranslator.getString(
573: LocalStringKeys.JBI_SHUTDOWN_TIME, new Long(
574: mShutdownElapsedTime)));
575: }
576:
577: /**
578: * Get the global framework environment context.
579: * @return The global framework environment context.
580: */
581: public com.sun.jbi.framework.EnvironmentContext getEnvironment() {
582: return mEnvironment;
583: }
584:
585: synchronized public void enterLazyMode() {
586: //
587: // Say that we are in lazy mode and signal any waiters.
588: //
589: mLog.fine("JBIFramework: Enter lazy mode...");
590: mLazyInit = true;
591: this .notifyAll();
592: }
593:
594: /**
595: * Initialize the Framework (if not already initialized.)
596: *
597: * This happens in a few situations. These situations arise because the Framework
598: * is lazy initialized if it can be determined that JBI is effectively unused.
599: * This typically happens in the DAS if no components will be started. It can also
600: * happen in a server instance in the same situation.
601: *
602: * In the DAS the framework will complete initialization in three different ways:
603: * 1) An instance requests a registry download for synchronization purposes.
604: * 2) A JBI client command is received and processed.
605: * 3) A cluster change occurred and we need to perform some framework actions.
606: *
607: * In the server instance case the Framework will be started when a JBI client request
608: * is forward by the DAS to this instance (similar to 2) above.)
609: *
610: */
611: synchronized public void frameworkReady() throws RuntimeException {
612: //
613: // See if the Framework is ready yet.
614: //
615: while (!mFrameworkReady) {
616: //
617: // If we decided on lazy initialization, then complete initialization.
618: //
619: if (mLazyInit) {
620: //
621: // Framework has not entered the ready state yet, so let's try
622: // to get there now.
623: try {
624: mLog.fine("JBIFramework: Transition to ready...");
625: //
626: // Make sure that we say the framework is ready, so that we don't attempt
627: // to start the framework again when the registry is accessed.
628: //
629: prepare();
630: ready(true);
631: } catch (Throwable ex) {
632: mFrameworkReady = false;
633: mLog.log(Level.FINE,
634: "Exception occurred making the "
635: + "runtime ready", ex);
636: throw new RuntimeException(ex.toString());
637: } finally {
638: //
639: // Signal any other waiters.
640: //
641: this .notifyAll();
642: }
643: } else {
644: try {
645: //
646: // Must be waiting for normal mode startup to complete.
647: //
648: this .wait();
649: } catch (InterruptedException ie) {
650:
651: }
652: }
653: }
654: }
655:
656: /** Indicates if the framework has entered the ready state. This flag
657: * is used by on-demand initialization logic to determine if the
658: * framework was initialized but not started.
659: * @return true if the framework is in the ready state, false otherwise.
660: */
661: synchronized boolean isFrameworkReady() {
662: return mFrameworkReady;
663: }
664:
665: /**
666: * ONLY USED FOR FRAMEWORK JUNIT TESTS
667: */
668: synchronized void setFrameworkReady() {
669: mFrameworkReady = true;
670: }
671:
672: /**
673: * Log a service failure during initialization, startup, or shutdown.
674: * @param service The name of the service which failed.
675: * @param ex The exception causing the failure.
676: * @param msgKey The message key for the failure message to be logged.
677: */
678: private void logFailure(String service, Throwable ex, String msgKey) {
679: String msg = ex.getMessage();
680: msg = (null != msg) ? msg : mTranslator
681: .getString(LocalStringKeys.NO_MESSAGE);
682: mLog.log(Level.SEVERE, mTranslator.getString(msgKey, service,
683: ex.getClass().getName(), msg), ex);
684: }
685:
686: /**
687: * Initialize the persistent Registry that is used to populate the local
688: * Component Registry.
689: * @return the Registry instance that will provide the persistent registry.
690: * @throws javax.jbi.JBIException if the registry fails to initialize.
691: */
692: com.sun.jbi.management.registry.Registry initRegistry()
693: throws javax.jbi.JBIException {
694: com.sun.jbi.management.registry.Registry registry = null;
695:
696: String regFolder = mEnvironment.getJbiInstanceRoot()
697: + java.io.File.separator + "config";
698:
699: java.util.Properties props = new java.util.Properties();
700: props
701: .setProperty(
702: com.sun.jbi.management.registry.Registry.REGISTRY_FOLDER_PROPERTY,
703: regFolder);
704:
705: // Create an instance of management context
706: com.sun.jbi.management.system.ManagementContext mgmtCtx = new com.sun.jbi.management.system.ManagementContext(
707: mEnvironment);
708:
709: registry = com.sun.jbi.management.registry.RegistryBuilder
710: .buildRegistry(new com.sun.jbi.management.registry.RegistrySpecImpl(
711: com.sun.jbi.management.registry.RegistryType.XML,
712: props, mgmtCtx));
713: return registry;
714: }
715:
716: /**
717: * Initialize the file system repository containing all JBI installation
718: * and deployment archives.
719: * @throws javax.jbi.JBIException failed to initialize repository
720: */
721: private void initRepository() throws javax.jbi.JBIException {
722: try {
723: // Create an instance of management context
724: com.sun.jbi.management.system.ManagementContext mgmtCtx = new com.sun.jbi.management.system.ManagementContext(
725: mEnvironment);
726:
727: // Initialize the repository and store a reference to it in the
728: // management context.
729: com.sun.jbi.management.repository.Repository repository = new com.sun.jbi.management.repository.Repository(
730: mgmtCtx);
731: mgmtCtx.setRepository(repository);
732: } catch (com.sun.jbi.management.repository.RepositoryException repEx) {
733: throw new javax.jbi.JBIException(repEx);
734: }
735: }
736:
737: /**
738: * Cleanup the .jbi_admin_running file and create the .jbi_admin_stopped
739: * file.
740: */
741: private void createStoppedStateFile() {
742:
743: // remove the .jbi_admin_running file
744: String parentDir = mEnvironment.getJbiInstanceRoot()
745: + java.io.File.separator
746: + com.sun.jbi.util.Constants.TMP_FOLDER;
747:
748: removeStartedStateFile();
749:
750: // create the .jbi_admin_stopped state file
751: java.io.File adminStoppedFile = new java.io.File(parentDir,
752: com.sun.jbi.util.Constants.ADMIN_STOPPED_FILE);
753: try {
754: adminStoppedFile.createNewFile();
755: } catch (java.io.IOException ioex) {
756: String errMsg = mTranslator.getString(
757: LocalStringKeys.JBI_STATE_FILE_CREATION_FAILED,
758: com.sun.jbi.util.Constants.ADMIN_STOPPED_FILE, ioex
759: .getClass().getName(), ioex.getMessage());
760: mLog.log(Level.FINE, errMsg, ioex);
761: }
762: }
763:
764: /**
765: * Remove the started state file if it exists
766: */
767: private void removeStartedStateFile() {
768: // remove the .jbi_admin_running file
769: String parentDir = mEnvironment.getJbiInstanceRoot()
770: + java.io.File.separator
771: + com.sun.jbi.util.Constants.TMP_FOLDER;
772:
773: java.io.File adminStartedFile = new java.io.File(parentDir,
774: com.sun.jbi.util.Constants.ADMIN_RUNNING_FILE);
775: if (adminStartedFile.exists()) {
776: adminStartedFile.delete();
777: }
778: }
779:
780: /**
781: * Cleanup the .jbi_admin_stopped file and create the .jbi_admin_running
782: * file.
783: */
784: private void createStartedStateFile() {
785:
786: // remove the .jbi_admin_stopped file
787: String parentDir = mEnvironment.getJbiInstanceRoot()
788: + java.io.File.separator
789: + com.sun.jbi.util.Constants.TMP_FOLDER;
790:
791: removeStoppedStateFile();
792:
793: // create the .jbi_admin_running state file
794: java.io.File adminStartedFile = new java.io.File(parentDir,
795: com.sun.jbi.util.Constants.ADMIN_RUNNING_FILE);
796: try {
797: adminStartedFile.createNewFile();
798: } catch (java.io.IOException ioex) {
799: String errMsg = mTranslator.getString(
800: LocalStringKeys.JBI_STATE_FILE_CREATION_FAILED,
801: com.sun.jbi.util.Constants.ADMIN_RUNNING_FILE, ioex
802: .getClass().getName(), ioex.getMessage());
803: mLog.log(Level.FINE, errMsg, ioex);
804: }
805: }
806:
807: /**
808: * Remove the stopped state file if it exists
809: */
810: private void removeStoppedStateFile() {
811: // remove the .jbi_admin_stopped file
812: String parentDir = mEnvironment.getJbiInstanceRoot()
813: + java.io.File.separator
814: + com.sun.jbi.util.Constants.TMP_FOLDER;
815:
816: java.io.File adminStoppedFile = new java.io.File(parentDir,
817: com.sun.jbi.util.Constants.ADMIN_STOPPED_FILE);
818: if (adminStoppedFile.exists()) {
819: adminStoppedFile.delete();
820: }
821: }
822: }
|