org.robokind.api.common.osgi.lifecycle
Class AbstractLifecycleProvider<I,T extends I>

java.lang.Object
  extended by org.robokind.api.common.osgi.lifecycle.AbstractLifecycleProvider<I,T>
Type Parameters:
I - Interface or Base Class of the service managed by this lifecycle
T - actual type of the service managed
All Implemented Interfaces:
ServiceLifecycleProvider<I>

public abstract class AbstractLifecycleProvider<I,T extends I>
extends Object
implements ServiceLifecycleProvider<I>

Abstract implementation of ServiceLifecycleProvider. Automatically validates dependencies against the descriptors provided at creation.

Author:
Matthew Stevenson

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.robokind.api.common.osgi.lifecycle.ServiceLifecycleProvider
ServiceLifecycleProvider.Validator
 
Field Summary
protected  Properties myRegistrationProperties
          OSGi registration properties
protected  T myService
          Instance of the service being managed
 
Constructor Summary
AbstractLifecycleProvider(List<DependencyDescriptor> deps)
          Creates a new AbstractLifecycleProvider with the given DependencyDescriptors.
 
Method Summary
protected abstract  T create(Map<String,Object> dependencies)
          Called when all dependencies are available.
 void dependencyChanged(String serviceId, Object service)
          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.
protected abstract  void handleChange(String dependencyId, Object service)
          Called from dependencyChanged with validated values.
 void start(Map<String,Object> dependencies)
          Called the first time all dependencies are available.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.robokind.api.common.osgi.lifecycle.ServiceLifecycleProvider
getServiceClass
 

Field Detail

myService

protected T extends I myService
Instance of the service being managed


myRegistrationProperties

protected Properties myRegistrationProperties
OSGi registration properties

Constructor Detail

AbstractLifecycleProvider

public AbstractLifecycleProvider(List<DependencyDescriptor> deps)
Creates a new AbstractLifecycleProvider with the given DependencyDescriptors.

Parameters:
deps - descriptors of the dependencies for this lifecycle
Method Detail

start

public void start(Map<String,Object> dependencies)
Description copied from interface: ServiceLifecycleProvider
Called the first time all dependencies are available.

Specified by:
start in interface ServiceLifecycleProvider<I>
Parameters:
dependencies - dependencies needed to start the service lifecycle

create

protected abstract T create(Map<String,Object> dependencies)
Called when all dependencies are available. This should create and return the service for this lifecycle.

Parameters:
dependencies - validated map of the lifecycle's dependencies
Returns:
the service managed by this lifecycle, null if the service cannot be created

getService

public T getService()
Description copied from interface: ServiceLifecycleProvider
Returns the service managed by this lifecycle provider. Returns null if the lifecycle has not been started or if the service is unavailable.

Specified by:
getService in interface ServiceLifecycleProvider<I>
Returns:
service the service managed by this lifecycle provider

getRegistrationProperties

public Properties getRegistrationProperties()
Description copied from interface: ServiceLifecycleProvider
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.

Specified by:
getRegistrationProperties in interface ServiceLifecycleProvider<I>
Returns:
properties to be used when register the service managed by this lifecycle provider

getDependencyDescriptors

public List<DependencyDescriptor> getDependencyDescriptors()
Description copied from interface: ServiceLifecycleProvider
Returns a list describing the service dependencies required by this lifecycle provider.

Specified by:
getDependencyDescriptors in interface ServiceLifecycleProvider<I>
Returns:
list describing the service dependencies required by this lifecycle provider

dependencyChanged

public void dependencyChanged(String serviceId,
                              Object service)
Description copied from interface: ServiceLifecycleProvider
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.

Specified by:
dependencyChanged in interface ServiceLifecycleProvider<I>
Parameters:
serviceId - dependency id defined in the DependencyDescriptor
service - the new dependency, or null if the dependency is no longer available.

handleChange

protected abstract void handleChange(String dependencyId,
                                     Object service)
Called from dependencyChanged with validated values.

Parameters:
dependencyId - id of the dependency changed
service - new dependency, null if the dependency was removed


Copyright © 2011-2012. All Rights Reserved.