org.apache.xbean.kernel
Interface ServiceFactory

All Known Implementing Classes:
AbstractServiceFactory

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
Version:
$Id$
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.
 java.lang.Object createService(ServiceContext serviceContext)
          Creates the service instance.
 void destroyService(ServiceContext serviceContext)
          Destroys the service instance.
 java.util.Set getOwnedServices()
          Gets the names of services owned by this service.
 java.util.Set getStartConditions()
          Get an unmodifable snapshot of the conditions that must be satisfied before this service can be started.
 java.util.Set getStopConditions()
          Get an unmodifable snapshot of the conditions that must be satisfied before this service can be stopped.
 java.lang.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

public java.lang.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

public 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

public 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

public 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

public java.util.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

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

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

removeStartCondition

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

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

getStopConditions

public java.util.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

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

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

removeStopCondition

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

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

getOwnedServices

public java.util.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

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

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

destroyService

public void destroyService(ServiceContext serviceContext)
Destroys the service instance.

Parameters:
serviceContext - the context information for the service


Copyright © {inceptionYear}-2006 Apache Software Foundation. All Rights Reserved.