com.metamatrix.platform.service.controller
Class AbstractService

java.lang.Object
  extended by com.metamatrix.platform.service.controller.AbstractService
All Implemented Interfaces:
EventObjectListener, ServiceInterface, java.util.EventListener
Direct Known Subclasses:
AuthorizationServiceImpl, ConfigurationServiceImpl, ConnectorService, MembershipServiceImpl, QueryService, SessionServiceImpl

public abstract class AbstractService
extends java.lang.Object
implements ServiceInterface, EventObjectListener

Base class for all services.


Field Summary
 
Fields inherited from interface com.metamatrix.platform.service.api.ServiceInterface
WAIT_TO_DIE_TIME
 
Constructor Summary
AbstractService()
          Default constructor.
 
Method Summary
 void checkState()
          If service is not open an exception is thrown.
protected abstract  void closeService()
          Close the service to new work if applicable.
 void die()
          This method will gracefully shutdown the service.
 void dieNow()
          This method will shutdown the service immediately.
 java.util.Collection<ConnectionPoolStats> getConnectionPoolStats()
          Returns a list of ConnectionPoolStat objects for the specific ConnectorBinding service If there are no ConnectionPoolStats, null is returned.
 int getCurrentState()
          Return current state of of the service.
 java.lang.String getHostname()
          Return name of the host service is running on.
 ServiceID getID()
          Return id of this service.
 java.lang.Throwable getInitException()
           
 java.lang.String getInstanceName()
          Return instance name of this service.
 java.lang.String getProcessName()
          Get process name on which this service is running on
 java.util.Properties getProperties()
          Return the properties that were used to init this service.
 java.util.Collection getQueueStatistics()
          Returns a list of QueueStats objects that represent the queues in this service.
 WorkerPoolStats getQueueStatistics(java.lang.String name)
          Returns a QueueStats object that represent the queue in this service.
protected  java.lang.String getResourceName()
          This method should be overridden when the extending class when it will use a resource name other than the ComponentTypeName for looking up its resource connection properties.
 ServiceData getServiceData()
           
protected  java.lang.String getServiceName()
          Return name of service (instance name)
 java.lang.String getServiceType()
          Return the type of service (QueryService, SubscriptionService, etc...)
 java.util.Date getStartTime()
          Return time service was initializes.
 java.util.Date getStateChangeTime()
          Return the time the current state was entered.
 void init(ServiceID id, DeployedComponentID deployedComponentID, java.util.Properties props, ClientServiceRegistry listenerRegistry, ClassLoaderManager clManager)
          Initialize a service using the properties specified.
protected abstract  void initService(java.util.Properties props)
          Perform initialization and commence processing.
 boolean isAlive()
          Method used to determine if service is still alive.
 boolean isClosed()
          Return true if service is closed.
 boolean isInitialized()
          Return true if service has been initialized.
 boolean isOpen()
          Return true if service is open
protected abstract  void killService()
          Terminate all processing and reclaim resources.
 void processEvent(java.util.EventObject obj)
          This method is called when a ServiceEvent that service has registered for is received via the MessageBus.
protected  void registerForEvents()
          Register for events.
 void setInitException(java.lang.Throwable error)
          Set the initializaton exception
protected  void unregisterForEvents()
          UnRegister for events.
 void updateState(int newState)
          Update state and stateChangedTime with new state; If newState == state then do nothing.
protected abstract  void waitForServiceToClear()
          Wait until the service has completed all outstanding work.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractService

public AbstractService()
Default constructor.

Method Detail

init

public void init(ServiceID id,
                 DeployedComponentID deployedComponentID,
                 java.util.Properties props,
                 ClientServiceRegistry listenerRegistry,
                 ClassLoaderManager clManager)
Initialize a service using the properties specified. The properties MUST contain a property SERVICE_TYPE and SERVICE_SUB_TYPE which identifies the type of service. All other properties are service specific. The properties object supplied MUST NOT CONTAIN DEFAULTS as the default properties DO NOT serialize. If a properties object which uses defaults is supplied, a call to getProperties() will return an incomplete set of properties since the method is typically invoked remotely.

Specified by:
init in interface ServiceInterface
Parameters:
id - The ServiceID this service was registered with
deployedComponentID - Unique identifier of this deployed component.
props - the properties which define the service configuration
controller - ServiceBusInterface which supplies resources such as event processing

getServiceType

public final java.lang.String getServiceType()
Return the type of service (QueryService, SubscriptionService, etc...)

Specified by:
getServiceType in interface ServiceInterface
Returns:
String representing type of service.

getCurrentState

public final int getCurrentState()
Return current state of of the service. STATE_NOT_INITIALIZED STATE_OPEN STATE_CLOSED STATE_SUSPENDED

Specified by:
getCurrentState in interface ServiceInterface
Returns:
int representing current state.

getStateChangeTime

public final java.util.Date getStateChangeTime()
Return the time the current state was entered.

Specified by:
getStateChangeTime in interface ServiceInterface
Returns:
Date representing time of state change.

getID

public final ServiceID getID()
Return id of this service.

Specified by:
getID in interface ServiceInterface
Returns:
ServiceID

die

public final void die()
This method will gracefully shutdown the service. Sub classes of AbstractService class should implement unregisterForEvents(), closeService(), waitForServiceToClear() and killService to gracefully shut down the service.

Specified by:
die in interface ServiceInterface

dieNow

public final void dieNow()
This method will shutdown the service immediately. Sub classes of AbstractService class should implement unregisterForEvents() and killService().

Specified by:
dieNow in interface ServiceInterface

getProperties

public final java.util.Properties getProperties()
Return the properties that were used to init this service.

Specified by:
getProperties in interface ServiceInterface
Returns:
Properties

getStartTime

public final java.util.Date getStartTime()
Return time service was initializes.

Specified by:
getStartTime in interface ServiceInterface
Returns:
Date containing time service started.

getHostname

public final java.lang.String getHostname()
Return name of the host service is running on.

Specified by:
getHostname in interface ServiceInterface
Returns:
String Host name

getProcessName

public final java.lang.String getProcessName()
Description copied from interface: ServiceInterface
Get process name on which this service is running on

Specified by:
getProcessName in interface ServiceInterface
Returns:
See Also:
ServiceInterface.getProcessName()

getInstanceName

public final java.lang.String getInstanceName()
Return instance name of this service.

Returns:
String instance name

isAlive

public final boolean isAlive()
Method used to determine if service is still alive.

Specified by:
isAlive in interface ServiceInterface

checkState

public void checkState()
                throws ServiceStateException
If service is not open an exception is thrown. All business methods in subclass should call this method.

Specified by:
checkState in interface ServiceInterface
Throws:
ServiceNotInitialized - if service has not yet been initialized.
ServiceClosedException - if service has been closed.
ServiceSuspendedException - if service is currently suspended.
ServiceStateException

isInitialized

public final boolean isInitialized()
Return true if service has been initialized.


isOpen

public final boolean isOpen()
Return true if service is open


isClosed

public final boolean isClosed()
Return true if service is closed.


initService

protected abstract void initService(java.util.Properties props)
                             throws java.lang.Exception
Perform initialization and commence processing. This method is called only once.

Throws:
java.lang.Exception

closeService

protected abstract void closeService()
                              throws java.lang.Exception
Close the service to new work if applicable. After this method is called the service should no longer accept new work to perform but should continue to process any outstanding work. This method is called by die().

Throws:
java.lang.Exception

waitForServiceToClear

protected abstract void waitForServiceToClear()
                                       throws java.lang.Exception
Wait until the service has completed all outstanding work. This method is called by die() just before calling dieNow().

Throws:
java.lang.Exception

killService

protected abstract void killService()
Terminate all processing and reclaim resources. This method is called by dieNow() and is only called once.


getResourceName

protected java.lang.String getResourceName()
This method should be overridden when the extending class when it will use a resource name other than the ComponentTypeName for looking up its resource connection properties. Generally, for services the resource name will be the ComponentTypeName. For other types (i.e., connectors, non-exposed functionality, etc.), the resource name will probably be defined as a static variable called RESOURCE_NAME.


processEvent

public void processEvent(java.util.EventObject obj)
This method is called when a ServiceEvent that service has registered for is received via the MessageBus.

Specified by:
processEvent in interface EventObjectListener

registerForEvents

protected void registerForEvents()
                          throws java.lang.Exception
Register for events. Subclassers should register for all events.

Throws:
java.lang.Exception

unregisterForEvents

protected void unregisterForEvents()
                            throws java.lang.Exception
UnRegister for events. Subclassers should register for all events.

Throws:
java.lang.Exception

getQueueStatistics

public java.util.Collection getQueueStatistics()
Returns a list of QueueStats objects that represent the queues in this service. If there are no queues, null is returned.

Specified by:
getQueueStatistics in interface ServiceInterface

getQueueStatistics

public WorkerPoolStats getQueueStatistics(java.lang.String name)
Returns a QueueStats object that represent the queue in this service. If there is no queue with the given name, null is returned.

Specified by:
getQueueStatistics in interface ServiceInterface

updateState

public void updateState(int newState)
Update state and stateChangedTime with new state; If newState == state then do nothing.

Specified by:
updateState in interface ServiceInterface
Parameters:
int - new state of service

setInitException

public void setInitException(java.lang.Throwable error)
Set the initializaton exception

Specified by:
setInitException in interface ServiceInterface
Parameters:
Throwable -

getInitException

public java.lang.Throwable getInitException()
Specified by:
getInitException in interface ServiceInterface

getServiceName

protected java.lang.String getServiceName()
Return name of service (instance name)


getServiceData

public ServiceData getServiceData()
Specified by:
getServiceData in interface ServiceInterface

getConnectionPoolStats

public java.util.Collection<ConnectionPoolStats> getConnectionPoolStats()
Description copied from interface: ServiceInterface
Returns a list of ConnectionPoolStat objects for the specific ConnectorBinding service If there are no ConnectionPoolStats, null is returned.

Specified by:
getConnectionPoolStats in interface ServiceInterface


Copyright © 2009. All Rights Reserved.