com.tenduke.services
Class ServiceManager

java.lang.Object
  extended by com.tenduke.services.ServiceManager
Direct Known Subclasses:
PlatformServiceManager

public class ServiceManager
extends java.lang.Object

Class that is responsible of loading classes that implement Service interface.

Services are loaded by dynamically creating instances of configured classes that implement Service interface. Processing is controlled by a sequence of configured values in main (Configuration), where the key names start with lifecycle.servicemanager.service.classname.

The sequence is defined by appending a series of integers after the key prefix. Indices start at 1 and must be a continuous series of positive integers. Processing will break on first disruption of series of positive integers.

Configuration parameters used by ServiceManager are:

Key nameDescriptionDefault value
lifecycle.servicemanager.service.classname.*

Fully qualified class name of a service that must loaded when beginning application lifecycle (at process startup). Positive integer starting from 1 must be appended (substituting the wildcard character '*' appearing in this documentation) to each key that defines a service to be managed by ServiceManager. When there are several services, the positive integers appended to the key names must form a continuous series.

Example configuration:

 ...
 <properties version="1.0">
   ...
   <entry key="lifecycle.servicemanager.service.classname.1">com.tenduke.services.multimedia.Multimedia</entry>
   <entry key="lifecycle.servicemanager.service.classname.2">com.tenduke.services.eventfeed.EventFeedService</entry>
   <entry key="lifecycle.servicemanager.service.classname.3">com.mycompany.services.MagicExtensionService</entry>
   ...
 </properties>
 
 
N/A


Constructor Summary
protected ServiceManager()
          Protected default constructor.
  ServiceManager(ServiceContext serviceContext)
          Creates a new instance of ServiceManager.
 
Method Summary
 Service getServiceByName(java.lang.String name)
          Gets handle to a service by Service's serviceName.
 ServiceContext getServiceContext()
          Accessing the context information available to clients of the service manager.
protected  java.util.Map<java.lang.String,Service> getServices()
          Getter for the collection of services.
protected  java.lang.Object getServicesLockObject()
          Getter for the object used to synchronize access to the services collection.
 void initializeLoadedService(Service service)
          Initializing service that has been initialized by service manager service loading.
 void initializeServiceManager()
          This method should be called right after service manager instantiation.
 void removeServices()
          Stops and clears the loaded services from internal data structure.
 void startServices()
           Starts all loaded service.
 void stopServices()
           Stops all started service.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ServiceManager

protected ServiceManager()
Protected default constructor. Calls over ServiceManager constructor with null ServiceContext.


ServiceManager

public ServiceManager(ServiceContext serviceContext)
Creates a new instance of ServiceManager.

Parameters:
serviceContext - A ServiceContext instance that makes context information available for the dynamically loadable service implementations.
Method Detail

getServiceByName

public Service getServiceByName(java.lang.String name)
Gets handle to a service by Service's serviceName.

Parameters:
name - The service name to look up a service by.
Returns:
handle to a service by Service's serviceName or null if not found.

getServiceContext

public ServiceContext getServiceContext()
Accessing the context information available to clients of the service manager. The returned service manager probably represents instance of a class derived from ServiceContext.

Returns:
The ServiceContext given to the ServiceManager.

getServices

protected java.util.Map<java.lang.String,Service> getServices()
Getter for the collection of services.

Returns:
LinkedHashMap with currently loaded Services.

getServicesLockObject

protected java.lang.Object getServicesLockObject()
Getter for the object used to synchronize access to the services collection.

Returns:
The lock object used to protect internal services map.

initializeLoadedService

public void initializeLoadedService(Service service)
Initializing service that has been initialized by service manager service loading. Empty method.

Parameters:
service - The service to initialize.

initializeServiceManager

public void initializeServiceManager()
This method should be called right after service manager instantiation. This gives the service manager chance to initialize itself. Base class implementation actually loads the services.


removeServices

public void removeServices()
Stops and clears the loaded services from internal data structure.


startServices

public void startServices()

Starts all loaded service. The start sequence is determined by:

Services are started in the order defined in the list.


stopServices

public void stopServices()

Stops all started service. The stop sequence is determined by:

Services are stopped in reverse startup order.