org.apache.xbean.kernel
Interface ServiceFactory

All Known Implementing Classes:
AbstractServiceFactory, StaticServiceFactory

public interface ServiceFactory

A service factory is responsible for construction and destruction of a single service. A service factory provides the kernel the start conditions, stopped conditions, owned services and enabled status of the service.

Since:
2.0
Author:
Dain Sundstrom

Method Summary
 void addStartCondition(ServiceCondition startCondition)
          Adds start condition to this service.
 void addStopCondition(ServiceCondition stopCondition)
          Adds stop condition to this service.
 Object createService(ServiceContext serviceContext)
          Creates the service instance.
 void destroyService(ServiceContext serviceContext)
          Destroys the service instance.
 ClassLoader getClassLoader()
          Gets the class loader associated with this service.
 Set getOwnedServices()
          Gets the names of services owned by this service.
 Set getStartConditions()
          Get an unmodifable snapshot of the conditions that must be satisfied before this service can be started.
 Set getStopConditions()
          Get an unmodifable snapshot of the conditions that must be satisfied before this service can be stopped.
 Class[] getTypes()
          Gets the types of the service this service factory will create.
 boolean isEnabled()
          Determines if the service can be instantiated in a kernel.
 boolean isRestartable()
          A restartable service can be started and stopped repeatedly in the kernel.
 void removeStartCondition(ServiceCondition startCondition)
          Removes a start condition from this service.
 void removeStopCondition(ServiceCondition stopCondition)
          Removes a stop condition from this service.
 void setEnabled(boolean enabled)
          Sets the enabled status of this service factory.
 

Method Detail

getTypes

Class[] getTypes()
Gets the types of the service this service factory will create. These types is used to index the service within the kernel. It is a start error to return an object from create service that is not an instance of every type. This is the only type used to index the service, so if the service factory returns a subclass of this type from createService, the subtypes will now be reflected in the index.

Returns:
the type of the service this service factory will create

isRestartable

boolean isRestartable()
A restartable service can be started and stopped repeatedly in the kernel. A service that is not restartable immediately enters the RUNNING state when registered with the kernel, and can not be started or stopped.

Returns:
true if this service can be started and stopped; false otherwise

isEnabled

boolean isEnabled()
Determines if the service can be instantiated in a kernel. A disabled restartable service can not be started and a disabled non-restartable service can not be loaded into a kernel.

Returns:
true if the service factory is enabled; false otherwise

setEnabled

void setEnabled(boolean enabled)
Sets the enabled status of this service factory. A disabled restartable service can not be started and a disabled non-restartable service can not be loaded into a kernel.

Parameters:
enabled - the new enabled state of this factory

getStartConditions

Set getStartConditions()
Get an unmodifable snapshot of the conditions that must be satisfied before this service can be started.

Returns:
the start conditions of this service

addStartCondition

void addStartCondition(ServiceCondition startCondition)
                       throws NullPointerException
Adds start condition to this service.

Parameters:
startCondition - the new start condition
Throws:
NullPointerException - if startCondition is null

removeStartCondition

void removeStartCondition(ServiceCondition startCondition)
                          throws NullPointerException
Removes a start condition from this service.

Parameters:
startCondition - the start condition to remove
Throws:
NullPointerException - if startCondition is null

getStopConditions

Set getStopConditions()
Get an unmodifable snapshot of the conditions that must be satisfied before this service can be stopped.

Returns:
the stop conditions of this service

addStopCondition

void addStopCondition(ServiceCondition stopCondition)
                      throws NullPointerException
Adds stop condition to this service.

Parameters:
stopCondition - the new stop condition
Throws:
NullPointerException - if stopCondition is null

removeStopCondition

void removeStopCondition(ServiceCondition stopCondition)
                         throws NullPointerException
Removes a stop condition from this service.

Parameters:
stopCondition - the stop condition to remove
Throws:
NullPointerException - if stopCondition is null

getOwnedServices

Set getOwnedServices()
Gets the names of services owned by this service. This information is used for the startRecursive method on the kernel. When a servcie is started with startRecursive all owned services will be started with startRecursive.

Returns:
the names of the services owned by this service

createService

Object createService(ServiceContext serviceContext)
                     throws Exception
Creates the service instance.

Parameters:
serviceContext - context information for the new service
Returns:
the service instance
Throws:
Exception - if a problem occurs during construction

destroyService

void destroyService(ServiceContext serviceContext)
Destroys the service instance.

Parameters:
serviceContext - the context information for the service

getClassLoader

ClassLoader getClassLoader()
Gets the class loader associated with this service.

Returns:
the class loader associated with the service


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