org.robokind.api.common.lifecycle
Interface ServiceLifecycleProvider<T>

Type Parameters:
T - type of service managed by this lifecycle provider
All Superinterfaces:
PropertyChangeSource
All Known Implementing Classes:
AbstractLifecycleProvider, ConfiguredServiceLifecycle, GenericLifecycle, SimpleLifecycle

public interface ServiceLifecycleProvider<T>
extends PropertyChangeSource

Manages the state and availability of a service through a Dependency- Injection pattern. A ServiceLifecycleProvider defines the service dependencies as a List of ServiceDependencyDescriptors, which provide a unique String key, dependency class, and dependency filter string. When all of the dependencies are available, the service lifecycle will be started with a call to the start method. This should create the service and make it available through the getService method. Once the service is started, if a dependency is changed or removed, dependencyChanged will be called with the new dependency. Once a ServiceLifecycleProvider is initialized, it may define new dependencies or remove dependencies added in this way, but the original dependencies cannot change. When dependencies are added and removed after initialization, a property change event should be fired.

Author:
Matthew Stevenson

Nested Class Summary
static class ServiceLifecycleProvider.Validator
          The Validator is used validate a dependencyId and dependency against a list of DependencyDescriptors.
 
Field Summary
static String PROP_DEPENDENCY_ADDED
          Property change name for adding a dependency after initializing.
static String PROP_DEPENDENCY_REMOVED
          Property change name for removing a dependency after initializing.
 
Method Summary
 void dependencyChanged(String dependencyId, Object dependency, Map<String,Object> dependencies)
          Called after the service is started and a dependency is changed or removed.
 List<DependencyDescriptor> getDependencyDescriptors()
          Returns a list describing the service dependencies required by this lifecycle provider.
 Properties getRegistrationProperties()
          Returns the properties to be used when register the service managed by this lifecycle provider.
 T getService()
          Returns the service managed by this lifecycle provider.
 String[] getServiceClassNames()
          Returns the names of the interfaces this service implements and makes available.
 void start(Map<String,Object> dependencyMap)
          Called the first time all dependencies are available.
 void stop()
           
 
Methods inherited from interface org.robokind.api.common.property.PropertyChangeSource
addPropertyChangeListener, addPropertyChangeListener, removePropertyChangeListener, removePropertyChangeListener
 

Field Detail

PROP_DEPENDENCY_ADDED

static final String PROP_DEPENDENCY_ADDED
Property change name for adding a dependency after initializing.

See Also:
Constant Field Values

PROP_DEPENDENCY_REMOVED

static final String PROP_DEPENDENCY_REMOVED
Property change name for removing a dependency after initializing.

See Also:
Constant Field Values
Method Detail

start

void start(Map<String,Object> dependencyMap)
Called the first time all dependencies are available.

Parameters:
dependencyMap - dependencies needed to start the service lifecycle

stop

void stop()

dependencyChanged

void dependencyChanged(String dependencyId,
                       Object dependency,
                       Map<String,Object> dependencies)
Called after the service is started and a dependency is changed or removed. This may result in a new service or null being returned by getService.

Parameters:
dependencyId - dependency id defined in the DependencyDescriptor
dependency - the new dependency, or null if the dependency is no longer available.

getService

T getService()
Returns the service managed by this lifecycle provider. Returns null if the lifecycle has not been started or if the service is unavailable.

Returns:
service the service managed by this lifecycle provider

getDependencyDescriptors

List<DependencyDescriptor> getDependencyDescriptors()
Returns a list describing the service dependencies required by this lifecycle provider.

Returns:
list describing the service dependencies required by this lifecycle provider

getRegistrationProperties

Properties getRegistrationProperties()
Returns the properties to be used when register the service managed by this lifecycle provider. This is intended to be used as the registration properties for the OSGi Service Registry.

Returns:
properties to be used when register the service managed by this lifecycle provider

getServiceClassNames

String[] getServiceClassNames()
Returns the names of the interfaces this service implements and makes available.

Returns:
names of the interfaces this service implements and makes available


Copyright © 2011-2013. All Rights Reserved.