org.apache.xbean.kernel.standard
Class ServiceManager

java.lang.Object
  extended by org.apache.xbean.kernel.standard.ServiceManager
All Implemented Interfaces:
Comparable

public class ServiceManager
extends Object
implements Comparable

The ServiceManager handles the life cycle of a single service. The manager is responsible for gaurenteeing that all start conditions have been satisfied before the service is constructed, and that all stop conditions have been satisfied before the service is destroyed. The ServiceManager can be started and stopped several times, but once destroyed no methods may be called.

Since:
2.0
Author:
Dain Sundstrom

Constructor Summary
ServiceManager(Kernel kernel, long serviceId, ServiceName serviceName, ServiceFactory serviceFactory, ServiceMonitor serviceMonitor, long timeoutDuration, TimeUnit timeoutUnits)
          Creates a service manager for a single service.
 
Method Summary
 int compareTo(Object o)
           
 void destroy(StopStrategy stopStrategy)
          Attempts to stop and destroy the service.
 boolean equals(Object o)
           
 ClassLoader getClassLoader()
          Gets the class loader for this service.
 Object getService()
          Gets the service instance.
 ServiceFactory getServiceFactory()
          Gets the factory used to create and destroy the service instance.
 long getServiceId()
          Gets the unique id of this service in the kernel.
 ServiceName getServiceName()
          Gets the unique name of this service in the kernel.
 Set getServiceTypes()
          Gets the types of the service that will be managed by this service manager.
 long getStartTime()
          Gets the time at which this service entered the STARTING state or 0 if the service is STOPPED.
 ServiceState getState()
          Gets the current state of this service.
 int hashCode()
           
 void initialize()
          Initializes the service.
 void start(boolean recursive, StartStrategy startStrategy)
          Attempts to starts the service.
 boolean stop(StopStrategy stopStrategy)
          Attempts to stop the service.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ServiceManager

public ServiceManager(Kernel kernel,
                      long serviceId,
                      ServiceName serviceName,
                      ServiceFactory serviceFactory,
                      ServiceMonitor serviceMonitor,
                      long timeoutDuration,
                      TimeUnit timeoutUnits)
Creates a service manager for a single service.

Parameters:
kernel - the kernel in which this wraper will be registered
serviceId - the unique id of this service in the kernel
serviceName - the unique name of this service in the kernel
serviceFactory - the factory used to create and destroy the service instance
serviceMonitor - the monitor of service events
timeoutDuration - the maximum duration to wait for a lock
timeoutUnits - the unit of measure for the timeoutDuration
Method Detail

initialize

public void initialize()
                throws IllegalServiceStateException,
                       UnsatisfiedConditionsException,
                       Exception
Initializes the service.

Throws:
IllegalServiceStateException - if the service is not restartable and is disabled
UnsatisfiedConditionsException - if the service is not restartable and there were unsatisfied start conditions
Exception - if the service is not restartable and service construction threw an exception
See Also:
Kernel#registerService(ServiceName, ServiceFactory, ClassLoader)

destroy

public void destroy(StopStrategy stopStrategy)
             throws IllegalServiceStateException,
                    UnsatisfiedConditionsException
Attempts to stop and destroy the service.

Parameters:
stopStrategy - the strategy used to determine how to handle unsatisfied stop conditions
Throws:
IllegalServiceStateException - is the service did not stop
UnsatisfiedConditionsException - if there were unsatisfied stop conditions
See Also:
Kernel.unregisterService(ServiceName, StopStrategy)

getServiceId

public long getServiceId()
Gets the unique id of this service in the kernel.

Returns:
the unique id of this service in the kernel

getServiceName

public ServiceName getServiceName()
Gets the unique name of this service in the kernel.

Returns:
the unique name of this servce in the kernel

getServiceTypes

public Set getServiceTypes()
Gets the types of the service that will be managed by this service manager.

Returns:
the types of the service

getServiceFactory

public ServiceFactory getServiceFactory()
Gets the factory used to create and destroy the service instance.

Returns:
the factory for the service instance
See Also:
Kernel.getServiceFactory(ServiceName)

getClassLoader

public ClassLoader getClassLoader()
Gets the class loader for this service. This class loader is provided to the service factory in the ServiceContext object.

Returns:
the classloader for this service
See Also:
Kernel.getClassLoaderFor(ServiceName)

getService

public Object getService()
Gets the service instance.

Returns:
the service instance
See Also:
Kernel.getService(ServiceName)

getState

public ServiceState getState()
Gets the current state of this service.

Returns:
the current state of this service
See Also:
Kernel.getServiceState(ServiceName)

getStartTime

public long getStartTime()
Gets the time at which this service entered the STARTING state or 0 if the service is STOPPED.

Returns:
the start time or 0 if the service is stopped
See Also:
Kernel.getServiceStartTime(ServiceName)

start

public void start(boolean recursive,
                  StartStrategy startStrategy)
           throws IllegalServiceStateException,
                  UnregisterServiceException,
                  UnsatisfiedConditionsException,
                  Exception
Attempts to starts the service.

Parameters:
recursive - if start is successful should we start recursive the services owned by this servic
startStrategy - the strategy used to determine how to handle unsatisfied start conditions and start errors
Throws:
IllegalServiceStateException - if the service is in a state in which it can not be started
UnregisterServiceException - if the kernel should unregister this service
UnsatisfiedConditionsException - if there were unsatisfied start conditions
Exception - it service creation threw an exception
See Also:
Kernel.startService(ServiceName), Kernel.startServiceRecursive(ServiceName)

stop

public boolean stop(StopStrategy stopStrategy)
             throws UnsatisfiedConditionsException
Attempts to stop the service.

Parameters:
stopStrategy - the strategy used to determine how to handle unsatisfied stop conditions
Returns:
true if the service was sucessfully stopped; false otherwise
Throws:
UnsatisfiedConditionsException - if there were unsatisfied stop conditions
See Also:
Kernel.stopService(ServiceName)

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object o)
Overrides:
equals in class Object

compareTo

public int compareTo(Object o)
Specified by:
compareTo in interface Comparable

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2005-2009 Apache Software Foundation. All Rights Reserved.