org.robokind.api.common.osgi.lifecycle
Class ServiceDependencyTracker

java.lang.Object
  extended by org.robokind.api.common.property.PropertyChangeNotifier
      extended by org.robokind.api.common.osgi.lifecycle.ServiceDependencyTracker
All Implemented Interfaces:
PropertyChangeSource

public class ServiceDependencyTracker
extends PropertyChangeNotifier

Monitors the OSGi Service Registry for a set of service dependencies. Fires property change events when all of the dependencies are available, and as the dependencies change. Used with DynamicServiceLauncher and ServiceLifecycleProvider to create services with OSGi-driven lifecycles.

Author:
Matthew Stevenson

Field Summary
static String PROP_ALL_DEPENDENCIES_AVAILABLE
          Property change event name for all dependencies being available.
static String PROP_DEPENDENCY_AVAILABLE
          Property change event name for a dependency becoming available.
static String PROP_DEPENDENCY_CHANGED
          Property change event name for a dependency changing.
static String PROP_DEPENDENCY_UNAVAILABLE
          Property change event name for a dependency becoming unavailable.
 
Constructor Summary
ServiceDependencyTracker(org.osgi.framework.BundleContext context)
          Creates an empty ServiceDependencyTracker with the given BundleContext.
 
Method Summary
 void addDependencyDescription(Class clazz, String dependencyId, String filterString)
          Adds the description to the list of dependency to listen for.
 void addDependencyDescription(DependencyDescriptor descriptor)
          Adds the description to the list of dependency to listen for.
 boolean dependenciesSatisfied()
          Returns true if all dependencies are available.
 Map<String,Object> getAvailableDependencies()
          Returns a map of dependency Ids dependencies.
 Object getDependency(String dependencyId)
          Returns the dependency matching the given id, null if unavailable.
 void start()
          Start tracking dependencies.
 void stop()
          Stop tracking dependencies.
 
Methods inherited from class org.robokind.api.common.property.PropertyChangeNotifier
addPropertyChangeListener, addPropertyChangeListener, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, removePropertyChangeListener, removePropertyChangeListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROP_DEPENDENCY_AVAILABLE

public static final String PROP_DEPENDENCY_AVAILABLE
Property change event name for a dependency becoming available.

See Also:
Constant Field Values

PROP_DEPENDENCY_CHANGED

public static final String PROP_DEPENDENCY_CHANGED
Property change event name for a dependency changing.

See Also:
Constant Field Values

PROP_DEPENDENCY_UNAVAILABLE

public static final String PROP_DEPENDENCY_UNAVAILABLE
Property change event name for a dependency becoming unavailable.

See Also:
Constant Field Values

PROP_ALL_DEPENDENCIES_AVAILABLE

public static final String PROP_ALL_DEPENDENCIES_AVAILABLE
Property change event name for all dependencies being available.

See Also:
Constant Field Values
Constructor Detail

ServiceDependencyTracker

public ServiceDependencyTracker(org.osgi.framework.BundleContext context)
Creates an empty ServiceDependencyTracker with the given BundleContext.

Parameters:
context -
Method Detail

dependenciesSatisfied

public boolean dependenciesSatisfied()
Returns true if all dependencies are available.

Returns:
true if all dependencies are available

getAvailableDependencies

public Map<String,Object> getAvailableDependencies()
Returns a map of dependency Ids dependencies. Returns null unless all dependencies are available.

Returns:
map of dependency Ids dependencies, null unless all dependencies are available

getDependency

public Object getDependency(String dependencyId)
Returns the dependency matching the given id, null if unavailable.

Parameters:
dependencyId - local id used with a ServiceLifecycleProvider
Returns:
service matching the DependencyDescriptor with the given id, null if the dependency is unavailable

addDependencyDescription

public void addDependencyDescription(DependencyDescriptor descriptor)
Adds the description to the list of dependency to listen for.

Parameters:
descriptor - dependency description to listen for
Throws:
IllegalStateException - if the tracker has already been started
IllegalArgumentException - if the given dependencyId already exists

addDependencyDescription

public void addDependencyDescription(Class clazz,
                                     String dependencyId,
                                     String filterString)
Adds the description to the list of dependency to listen for. Descriptions cannot be added once the tracker has been started.

Parameters:
clazz - dependency class
dependencyId - local dependency id to be used with a ServiceLifecycleProvider
filterString - optional OSGi filter String for the dependency
Throws:
IllegalStateException - if the tracker has already been started
IllegalArgumentException - if the given dependencyId already exists

start

public void start()
Start tracking dependencies.


stop

public void stop()
Stop tracking dependencies.



Copyright © 2011-2012. All Rights Reserved.