com.tenduke.lifecycle
Class LifecycleManager

java.lang.Object
  extended by com.tenduke.lifecycle.LifecycleManager
All Implemented Interfaces:
Subject<LifecycleEvent>

public final class LifecycleManager
extends java.lang.Object
implements Subject<LifecycleEvent>

Initialization and shutdown procedures for a 10Duke SDK based application.

Lifecycle manager is responsible for essential initialization procedures that are to happen before SDK classes and static methods are used. Although some static methods can be used without calling beginLifecycle() first, it is advisable to do so except for the methods listed below.

Things you can set before calling beginLifecycle()

If the above values are not explicitly set, consult the documentation for each class about how their default values are obtained.

When the application no longer needs 10Duke SDK, call endLifecycle() to free system resources.

Usually the application lifecycle coincides with the 10Duke SDK life cycle, but this is not mandatory.


Method Summary
 void attach(Observer<LifecycleEvent> observer)
          Attach observer for lifecycle events.
 void beginLifecycle()
           Begin 10Duke SDK life cycle with default configuration seach.
 void beginLifecycleCore()
           Begin 10Duke SDK life cycle without initialization.
 void detach(Observer<LifecycleEvent> observer)
          Detach observer for lifecycle events.
 void endLifecycle()
           End 10Duke SDK life cycle.
 LifecycleState getLifecycleState()
          Get the lifecycle state.
 ServiceManager getServiceManager()
          Return the service manager instance that is exposed to external users like jsp.
static LifecycleManager instance()
          Return the application instance that is exposed to external users like jsp.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

attach

public void attach(Observer<LifecycleEvent> observer)
Attach observer for lifecycle events.

Specified by:
attach in interface Subject<LifecycleEvent>
Parameters:
observer - Observer to be attached.

beginLifecycle

public void beginLifecycle()
                    throws java.lang.Throwable

Begin 10Duke SDK life cycle with default configuration seach.

First initializes the scan path, logs some useful info and initializes the main configuraiton, i.e,

  1. Call Configuration.logLocationInformation() to log useful information.
  2. Call Configuration.initializeConfiguration() to read the main configuration. If you wish to use custom root and main URIs, set them before calling beginLifecycle() method.

After this, the beginLifecycleCore() is called, which performs the following (events are of type LifecycleEvent):

  1. Send APPLICATION_START event to observers.
  2. Execute a platform start sequence. The platform start sequence includes:
    1. Send PRE_PLATFORM_START event to observers.
    2. Initialize capability to create objects dynamically by data contract name: SerializableObjectFactory.loadAllSerializableClasses().
    3. Initialize reporting framework by: ReportingClientInitializer.initialize().
    4. Send POST_PLATFORM_START event to observers.
  3. Execute a service start sequence. The service start sequence includes:
    1. Send PRE_SERVICES_START event to observers.
    2. Create a new ServiceManager and call ServiceManager.initializeServiceManager() on it. All dynamically loadable services listed in the main configuration are created.
    3. Call startService() method on each Service just created. Services are started in the order in the main configuration file.
    4. Send POST_SERVICES_START event to observers.
  4. Send APPLICATION_STARTED event to observers
  5. Mark LifecycleState to LIFECYCLE_ACTIVE or LIFECYCLE_CORRUPTED depending whether the startup was successful or not, correspondingly. The life cycle state can be checked with getLifecycleState() method.

Throws:
java.lang.Throwable - If error occurred while beginning application life cycle.

beginLifecycleCore

public void beginLifecycleCore()
                        throws java.lang.Throwable

Begin 10Duke SDK life cycle without initialization.

This is documented as part of the beginLifecycle() method.

Throws:
java.lang.Throwable - If error occurred while beginning application life cycle.

detach

public void detach(Observer<LifecycleEvent> observer)
Detach observer for lifecycle events.

Specified by:
detach in interface Subject<LifecycleEvent>
Parameters:
observer - Observer to be detached.

endLifecycle

public void endLifecycle()

End 10Duke SDK life cycle.

Ending sequence is the inverse of begin (events are of type LifecycleEvent):

  1. Send APPLICATION_STOP event to observers.
  2. Execute a service end sequence. The service end sequence includes:
    1. Send PRE_SERVICES_STOP event to observers.
    2. Call stopService() on each loaded service. Services are stopped in reverse startup order.
    3. Clear references to service objects.
    4. Send POST_SERVICES_STOP event to observers.
  3. Execute a platform end sequence. The platform end sequence includes:
    1. Send PRE_PLATFORM_STOP event to observers.
    2. No action, reserved for future use.
    3. Send POST_PLATFORM_STOP event to observers.
  4. Send APPLICATION_STOPPED event to observers.
  5. Mark LifecycleState to LIFECYCLE_ENDED or LIFECYCLE_ENDED_WITH_ERRORS depending whether the shutdown was successful or not, correspondingly. The life cycle state can be checked with getLifecycleState() method.


getLifecycleState

public LifecycleState getLifecycleState()
Get the lifecycle state. Before the first call to beginLifecycle() the lifecycle state is LifecycleState.LIFECYCLE_UNDEFINED.

Returns:
Lifecycle state.

getServiceManager

public ServiceManager getServiceManager()
Return the service manager instance that is exposed to external users like jsp. Usually application uses just one service manager, but if application uses several service managers, this is the one that is intended for external use.

Returns:
ServiceManager

instance

public static LifecycleManager instance()
Return the application instance that is exposed to external users like jsp. An application in this context defines just one entry point and one application instance.

Returns:
Singleton instance of LifecycleManager