org.apache.felix.dependencymanager
Class ServiceDependency

java.lang.Object
  extended by org.apache.felix.dependencymanager.ServiceDependency
All Implemented Interfaces:
Dependency, ServiceTrackerCustomizer

public class ServiceDependency
extends java.lang.Object
implements Dependency, ServiceTrackerCustomizer

Service dependency that can track an OSGi service.

Author:
Felix Project Team

Constructor Summary
ServiceDependency(org.osgi.framework.BundleContext context)
          Creates a new service dependency.
 
Method Summary
 void addedService(org.osgi.framework.ServiceReference ref, java.lang.Object service)
           
 java.lang.Object addingService(org.osgi.framework.ServiceReference ref)
           
 java.lang.Class getInterface()
           
 java.lang.Object getService()
           
 void invokeAdded()
           
 void invokeAdded(org.osgi.framework.ServiceReference reference, java.lang.Object serviceInstance)
           
 void invokeChanged(org.osgi.framework.ServiceReference reference, java.lang.Object serviceInstance)
           
 void invokeRemoved()
           
 void invokeRemoved(org.osgi.framework.ServiceReference reference, java.lang.Object serviceInstance)
           
 boolean isAutoConfig()
           
 boolean isAvailable()
          Returns true if the dependency is available.
 boolean isRequired()
          Returns true if this a required dependency.
 void modifiedService(org.osgi.framework.ServiceReference ref, java.lang.Object service)
           
 void removedService(org.osgi.framework.ServiceReference ref, java.lang.Object service)
           
 ServiceDependency setAutoConfig(boolean autoConfig)
          Sets auto configuration for this service.
 ServiceDependency setCallbacks(java.lang.Object instance, java.lang.String added, java.lang.String removed)
           
 ServiceDependency setCallbacks(java.lang.Object instance, java.lang.String added, java.lang.String changed, java.lang.String removed)
          Sets the callbacks for this service.
 ServiceDependency setCallbacks(java.lang.String added, java.lang.String removed)
          Sets the callbacks for this service.
 ServiceDependency setCallbacks(java.lang.String added, java.lang.String changed, java.lang.String removed)
           
 ServiceDependency setRequired(boolean required)
          Sets the required flag which determines if this service is required or not.
 ServiceDependency setService(java.lang.Class serviceName)
          Sets the name of the service that should be tracked.
 ServiceDependency setService(java.lang.Class serviceName, org.osgi.framework.ServiceReference serviceReference)
          Sets the name of the service that should be tracked.
 ServiceDependency setService(java.lang.Class serviceName, java.lang.String serviceFilter)
          Sets the name of the service that should be tracked.
 void start(Service service)
          Starts tracking the dependency.
 void stop(Service service)
          Stops tracking the dependency.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ServiceDependency

public ServiceDependency(org.osgi.framework.BundleContext context)
Creates a new service dependency.

Parameters:
context - the bundle context
Method Detail

isRequired

public boolean isRequired()
Description copied from interface: Dependency
Returns true if this a required dependency. Required dependencies are dependencies that must be available before the service can be activated.

Specified by:
isRequired in interface Dependency
Returns:
true if the dependency is required

isAvailable

public boolean isAvailable()
Description copied from interface: Dependency
Returns true if the dependency is available.

Specified by:
isAvailable in interface Dependency
Returns:
true if the dependency is available

isAutoConfig

public boolean isAutoConfig()

getService

public java.lang.Object getService()

getInterface

public java.lang.Class getInterface()

start

public void start(Service service)
Description copied from interface: Dependency
Starts tracking the dependency. This activates some implementation specific mechanism to do the actual tracking. If the tracking discovers that the dependency becomes available, it should call dependencyAvailable() on the service.

Specified by:
start in interface Dependency
Parameters:
service - the service that is associated with this dependency

stop

public void stop(Service service)
Description copied from interface: Dependency
Stops tracking the dependency. This deactivates the tracking. If the dependency was available, the tracker should call dependencyUnavaible() before stopping itself to ensure that dependencies that aren't "active" are unavailable.

Specified by:
stop in interface Dependency

addingService

public java.lang.Object addingService(org.osgi.framework.ServiceReference ref)
Specified by:
addingService in interface ServiceTrackerCustomizer

addedService

public void addedService(org.osgi.framework.ServiceReference ref,
                         java.lang.Object service)
Specified by:
addedService in interface ServiceTrackerCustomizer

invokeAdded

public void invokeAdded()

invokeAdded

public void invokeAdded(org.osgi.framework.ServiceReference reference,
                        java.lang.Object serviceInstance)

modifiedService

public void modifiedService(org.osgi.framework.ServiceReference ref,
                            java.lang.Object service)
Specified by:
modifiedService in interface ServiceTrackerCustomizer

invokeChanged

public void invokeChanged(org.osgi.framework.ServiceReference reference,
                          java.lang.Object serviceInstance)

removedService

public void removedService(org.osgi.framework.ServiceReference ref,
                           java.lang.Object service)
Specified by:
removedService in interface ServiceTrackerCustomizer

invokeRemoved

public void invokeRemoved()

invokeRemoved

public void invokeRemoved(org.osgi.framework.ServiceReference reference,
                          java.lang.Object serviceInstance)

setService

public ServiceDependency setService(java.lang.Class serviceName)
Sets the name of the service that should be tracked.

Parameters:
serviceName - the name of the service
Returns:
this service dependency

setService

public ServiceDependency setService(java.lang.Class serviceName,
                                    java.lang.String serviceFilter)
Sets the name of the service that should be tracked. You can either specify only the name, or the name and a filter. In the latter case, the filter is used to track the service and should only return services of the type that was specified in the name.

Parameters:
serviceName - the name of the service
serviceFilter - the filter condition
Returns:
this service dependency

setService

public ServiceDependency setService(java.lang.Class serviceName,
                                    org.osgi.framework.ServiceReference serviceReference)
Sets the name of the service that should be tracked. You can either specify only the name, or the name and a reference. In the latter case, the service reference is used to track the service and should only return services of the type that was specified in the name.

Parameters:
serviceName - the name of the service
serviceReference - the service reference to track
Returns:
this service dependency

setRequired

public ServiceDependency setRequired(boolean required)
Sets the required flag which determines if this service is required or not.

Parameters:
required - the required flag
Returns:
this service dependency

setAutoConfig

public ServiceDependency setAutoConfig(boolean autoConfig)
Sets auto configuration for this service. Auto configuration allows the dependency to fill in any attributes in the service implementation that are of the same type as this dependency. Default is on.

Parameters:
autoConfig - the value of auto config
Returns:
this service dependency

setCallbacks

public ServiceDependency setCallbacks(java.lang.String added,
                                      java.lang.String removed)
Sets the callbacks for this service. These callbacks can be used as hooks whenever a dependency is added or removed. They are called on the service implementation.

Parameters:
added - the method to call when a service was added
removed - the method to call when a service was removed
Returns:
this service dependency

setCallbacks

public ServiceDependency setCallbacks(java.lang.String added,
                                      java.lang.String changed,
                                      java.lang.String removed)

setCallbacks

public ServiceDependency setCallbacks(java.lang.Object instance,
                                      java.lang.String added,
                                      java.lang.String removed)

setCallbacks

public ServiceDependency setCallbacks(java.lang.Object instance,
                                      java.lang.String added,
                                      java.lang.String changed,
                                      java.lang.String removed)
Sets the callbacks for this service. These callbacks can be used as hooks whenever a dependency is added or removed. They are called on the instance you provide.

Parameters:
instance - the instance to call the callbacks on
added - the method to call when a service was added
changed - the method to call when a service was changed
removed - the method to call when a service was removed
Returns:
this service dependency

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object