com.orderlysoftware.orderlycalls.base
Class Service

java.lang.Object
  extended by com.orderlysoftware.orderlycalls.base.Service
Direct Known Subclasses:
AGIServer, ExampleService, ManagerClient

public abstract class Service
extends java.lang.Object

Service is the base class for all OrderlyCalls Named Services.

OrderlyCalls translates entries in its XML configuration file into running Service objects. The XML settings for each Service in the file are translated into Settingsobjects which are passed to the Service on creation.

You can extend the Service class to implement your own Service classes, and the Settingsobject to define your own initialisation settings for your Services.

You should read the ExampleServicecode and documentation if you intend to write your own Services.

Author:
Matt King, M.A. Oxon.

Field Summary
 ServiceLogger log
           
protected  Settings settings
           
 
Constructor Summary
Service()
          Default constructor.
Service(Settings settings)
          Creates a Service with the specified Settings.
 
Method Summary
static java.util.concurrent.ExecutorService getExecutorService()
          Returns a general-purpose thread execution service.
static Service getInstance(java.lang.Class serviceClass, Settings settings, boolean reuse)
          Gets an initialised Service instance.
static Service getInstance(Settings settings)
          Gets an initialised Service instance.
static Service getInstance(Settings settings, boolean reuse)
          Gets an initialised Service instance.
static Service getInstanceByName(java.lang.String name)
          Gets an initialised Service instance by the name of the Settings object.
 java.lang.String getLogName()
          Gets a string to identify this service for logging.
 java.lang.String getName()
          Gets the name of the Settings object used to create this instance.
 Settings getSettings()
          Gets the Settingsobject.
abstract  void init()
          Initialise the service based on the given Settingsobject.
abstract  boolean isRunning()
          Determines whether this service is active.
static void setExecutorService(java.util.concurrent.ExecutorService executorService)
           
abstract  void shutdown()
          Shutdown this Service
static void shutdownAll()
          Subclasses SHOULD override this method to shutdown only services of a particular subclass.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

public ServiceLogger log

settings

protected Settings settings
Constructor Detail

Service

public Service()
Default constructor.

Subclasses MUST define a zero-argument constructor in order to work with the OrderlyCalls system.


Service

public Service(Settings settings)
Creates a Service with the specified Settings.

Subclasses MUST call this constructor using super(settings).

Subclasses MUST NOT perform service initialisation from within this constructor.

Parameters:
settings - The settings object to use.
Method Detail

getInstance

public static Service getInstance(java.lang.Class serviceClass,
                                  Settings settings,
                                  boolean reuse)
Gets an initialised Service instance.

This method creates an instance of the given class (which MUST subclass Service) using the passed Settingsobject.

If reuse is true, and a Service has already been created with the given Settings, then the pre-existing service is called.

If a new Service object is created, its init() method is then called.

This method MUST NOT be overridden/hidden by subclasses.

Parameters:
serviceClass - the class of Service to create
settings - the Settingsobject to use
reuse - whether or not to reuse an existing Service object.
Returns:

getInstance

public static Service getInstance(Settings settings)
Gets an initialised Service instance.

All descendant services MUST override this method in order to get a service of the appropriate subclass.

Parameters:
settings - The settings to use in creating the service.
Returns:
an inialised Service instance.

getInstance

public static Service getInstance(Settings settings,
                                  boolean reuse)
Gets an initialised Service instance.

All descendant services MUST override this method in order to get a service of the appropriate subclass.

Parameters:
settings - The settings to use in creating the service.
reuse - Whether or not to reuse an existing Service object.
Returns:
An initialies Service instance.

getInstanceByName

public static Service getInstanceByName(java.lang.String name)
Gets an initialised Service instance by the name of the Settings object.

Subclasses SHOULD NOT override this method; instead create a new method:

 
  
   
    public static void MyService getInstance(String name) {
        return (MyService)getInstanceByName(name);
    } 
    
   
  
 

Parameters:
settings - The settings to use in creating the service.
reuse - Whether or not to reuse an existing Service object.
Returns:
An initialised Service instance.

init

public abstract void init()
Initialise the service based on the given Settingsobject.


shutdown

public abstract void shutdown()
Shutdown this Service


getSettings

public Settings getSettings()
Gets the Settingsobject.

Returns:
The Settingsobject used to initialise this Service.

isRunning

public abstract boolean isRunning()
Determines whether this service is active.

Returns:
true if running, false otherwise.

getName

public java.lang.String getName()
Gets the name of the Settings object used to create this instance.

Returns:
the name of this service (defers to the Settingsobject).

getLogName

public java.lang.String getLogName()
Gets a string to identify this service for logging.

Returns:
"ServiceClass:serviceName"

shutdownAll

public static void shutdownAll()
Subclasses SHOULD override this method to shutdown only services of a particular subclass.


getExecutorService

public static java.util.concurrent.ExecutorService getExecutorService()
Returns a general-purpose thread execution service.

Returns:
Returns the executorService.

setExecutorService

public static void setExecutorService(java.util.concurrent.ExecutorService executorService)
Parameters:
executorService - The executorService to set.