org.apache.felix.dependencymanager
Class ServiceDependency

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

public class ServiceDependency
extends Object
implements Dependency, ServiceTrackerCustomizer, ServiceComponentDependency

Service dependency that can track an OSGi service.

Author:
Felix Project Team

Field Summary
 
Fields inherited from interface org.apache.felix.dependencymanager.ServiceComponentDependency
STATE_AVAILABLE_OPTIONAL, STATE_AVAILABLE_REQUIRED, STATE_NAMES, STATE_UNAVAILABLE_OPTIONAL, STATE_UNAVAILABLE_REQUIRED
 
Constructor Summary
ServiceDependency(BundleContext context, Logger logger)
          Creates a new service dependency.
 
Method Summary
 void addedService(ServiceReference ref, Object service)
           
 Object addingService(ServiceReference ref)
           
 String getAutoConfigName()
           
 Class getInterface()
           
 String getName()
          Returns the name of this dependency.
 Object getService()
           
 int getState()
          Returns the state of this dependency.
 String getType()
          Returns the name of the type of this dependency.
 void invokeAdded()
           
 void invokeAdded(ServiceReference reference, Object serviceInstance)
           
 void invokeChanged(ServiceReference reference, Object serviceInstance)
           
 void invokeRemoved()
           
 void invokeRemoved(ServiceReference reference, Object serviceInstance)
           
 boolean isAutoConfig()
           
 boolean isAvailable()
          Returns true if the dependency is available.
 boolean isRequired()
          Returns true if this a required dependency.
 Object lookupService()
           
 void modifiedService(ServiceReference ref, Object service)
           
 void removedService(ServiceReference ref, Object service)
           
 ServiceDependency setAutoConfig(boolean autoConfig)
          Sets auto configuration for this service.
 ServiceDependency setAutoConfig(String instanceName)
          Sets auto configuration for this service.
 ServiceDependency setCallbacks(Object instance, String added, String removed)
           
 ServiceDependency setCallbacks(Object instance, String added, String changed, String removed)
          Sets the callbacks for this service.
 ServiceDependency setCallbacks(String added, String removed)
          Sets the callbacks for this service.
 ServiceDependency setCallbacks(String added, String changed, String removed)
           
 ServiceDependency setDefaultImplementation(Object implementation)
          Sets the default implementation for this service dependency.
 ServiceDependency setRequired(boolean required)
          Sets the required flag which determines if this service is required or not.
 ServiceDependency setService(Class serviceName)
          Sets the name of the service that should be tracked.
 ServiceDependency setService(Class serviceName, ServiceReference serviceReference)
          Sets the name of the service that should be tracked.
 ServiceDependency setService(Class serviceName, 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.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ServiceDependency

public ServiceDependency(BundleContext context,
                         Logger logger)
Creates a new service dependency.

Parameters:
context - the bundle context
logger -
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 Object getService()

lookupService

public Object lookupService()

getInterface

public 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 Object addingService(ServiceReference ref)
Specified by:
addingService in interface ServiceTrackerCustomizer

addedService

public void addedService(ServiceReference ref,
                         Object service)
Specified by:
addedService in interface ServiceTrackerCustomizer

invokeAdded

public void invokeAdded()

invokeAdded

public void invokeAdded(ServiceReference reference,
                        Object serviceInstance)

modifiedService

public void modifiedService(ServiceReference ref,
                            Object service)
Specified by:
modifiedService in interface ServiceTrackerCustomizer

invokeChanged

public void invokeChanged(ServiceReference reference,
                          Object serviceInstance)

removedService

public void removedService(ServiceReference ref,
                           Object service)
Specified by:
removedService in interface ServiceTrackerCustomizer

invokeRemoved

public void invokeRemoved()

invokeRemoved

public void invokeRemoved(ServiceReference reference,
                          Object serviceInstance)

setService

public ServiceDependency setService(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(Class serviceName,
                                    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(Class serviceName,
                                    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

setDefaultImplementation

public ServiceDependency setDefaultImplementation(Object implementation)
Sets the default implementation for this service dependency. You can use this to supply your own implementation that will be used instead of a Null Object when the dependency is not available. This is also convenient if the service dependency is not an interface (which would cause the Null Object creation to fail) but a class.

Parameters:
implementation - the instance to use or the class to instantiate if you want to lazily instantiate this implementation
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

setAutoConfig

public ServiceDependency setAutoConfig(String instanceName)
Sets auto configuration for this service. Auto configuration allows the dependency to fill in the attribute in the service implementation that has the same type and instance name.

Parameters:
instanceName - the name of attribute to auto config
Returns:
this service dependency

setCallbacks

public ServiceDependency setCallbacks(String added,
                                      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(String added,
                                      String changed,
                                      String removed)

setCallbacks

public ServiceDependency setCallbacks(Object instance,
                                      String added,
                                      String removed)

setCallbacks

public ServiceDependency setCallbacks(Object instance,
                                      String added,
                                      String changed,
                                      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 String toString()
Overrides:
toString in class Object

getAutoConfigName

public String getAutoConfigName()

getName

public String getName()
Description copied from interface: ServiceComponentDependency
Returns the name of this dependency.

Specified by:
getName in interface ServiceComponentDependency

getState

public int getState()
Description copied from interface: ServiceComponentDependency
Returns the state of this dependency.

Specified by:
getState in interface ServiceComponentDependency

getType

public String getType()
Description copied from interface: ServiceComponentDependency
Returns the name of the type of this dependency.

Specified by:
getType in interface ServiceComponentDependency


Copyright © 2006-2011 Apache Software Foundation. All Rights Reserved.