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

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

public class ServiceDependenciesTracker
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
ServiceDependenciesTracker(org.osgi.framework.BundleContext context)
          Creates an empty ServiceDependenciesTracker with the given BundleContext.
 
Method Summary
 boolean addDependencyDescription(Class clazz, String dependencyName, String filterString, DependencyDescriptor.DependencyType type)
          Adds the description to the list of dependency to listen for.
 boolean addDependencyDescription(DependencyDescriptor descriptor)
          Adds the description to the list of dependency to listen for.
 boolean dependenciesSatisfied()
          Returns true if all dependencies are available.
 void dispose()
           
 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.
 Map<String,Object> getRequiredDependencies()
          Returns a map of dependency Ids and required dependencies.
 boolean isRunning()
           
 boolean removeDependencyTracker(String name)
           
 void start()
          Start tracking dependencies.
 void stop()
          Stop tracking dependencies.
 
Methods inherited from class org.robokind.api.common.property.PropertyChangeNotifier
addPropertyChangeListener, addPropertyChangeListener, clearAllListeners, clearListeners, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getPropertyChangeListeners, getPropertyChangeListeners, hasListeners, 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

ServiceDependenciesTracker

public ServiceDependenciesTracker(org.osgi.framework.BundleContext context)
Creates an empty ServiceDependenciesTracker 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

getRequiredDependencies

public Map<String,Object> getRequiredDependencies()
Returns a map of dependency Ids and required 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 boolean 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 boolean addDependencyDescription(Class clazz,
                                        String dependencyName,
                                        String filterString,
                                        DependencyDescriptor.DependencyType type)
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
dependencyName - 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

removeDependencyTracker

public boolean removeDependencyTracker(String name)

start

public void start()
Start tracking dependencies.


isRunning

public boolean isRunning()

stop

public void stop()
Stop tracking dependencies.


dispose

public void dispose()


Copyright © 2011-2013. All Rights Reserved.