public interface ServiceDependency extends Dependency, ComponentDependencyDeclaration
(Component comp, ServiceReference ref, Service service)
(Component comp, ServiceReference ref, Object service)
(Component comp, ServiceReference ref)
(Component comp, Service service)
(Component comp, Object service)
(Component comp)
(Component comp, Map properties, Service service)
(ServiceReference ref, Service service)
(ServiceReference ref, Object service)
(ServiceReference ref)
(Service service)
(Service service, Map propeerties)
(Map properties, Service, service)
(Service service, Dictionary properties)
(Dictionary properties, Service service)
(Object service)
(ServiceObjects service)
For "swap" callbacks, the following method signatures are supported:
(Service old, Service replace)
(Object old, Object replace)
(ServiceReference old, Service old, ServiceReference replace, Service replace)
(ServiceReference old, Object old, ServiceReference replace, Object replace)
(Component comp, Service old, Service replace)
(Component comp, Object old, Object replace)
(Component comp, ServiceReference old, Service old, ServiceReference replace, Service replace)
(Component comp, ServiceReference old, Object old, ServiceReference replace, Object replace)
(ServiceReference old, ServiceReference replace)
(Component comp, ServiceReference old, ServiceReference replace)
(ServiceObjects old, ServiceObjects replace)
(Component comp, ServiceObjects old, ServiceObjects replace)
STATE_AVAILABLE_OPTIONAL, STATE_AVAILABLE_REQUIRED, STATE_NAMES, STATE_OPTIONAL, STATE_REQUIRED, STATE_UNAVAILABLE_OPTIONAL, STATE_UNAVAILABLE_REQUIRED
Modifier and Type | Method and Description |
---|---|
ServiceDependency |
setAutoConfig(boolean autoConfig)
Sets auto configuration for this service.
|
ServiceDependency |
setAutoConfig(java.lang.String instanceName)
Sets auto configuration for this service.
|
ServiceDependency |
setCallbacks(java.lang.Object instance,
java.lang.String add,
java.lang.String remove)
Sets the callbacks for this service.
|
ServiceDependency |
setCallbacks(java.lang.Object instance,
java.lang.String add,
java.lang.String change,
java.lang.String remove)
Sets the callbacks for this service.
|
ServiceDependency |
setCallbacks(java.lang.Object instance,
java.lang.String added,
java.lang.String changed,
java.lang.String removed,
java.lang.String swapped)
Sets the callbacks for this service.
|
ServiceDependency |
setCallbacks(java.lang.String add,
java.lang.String remove)
Sets the callbacks for this service.
|
ServiceDependency |
setCallbacks(java.lang.String add,
java.lang.String change,
java.lang.String remove)
Sets the callbacks for this service.
|
ServiceDependency |
setCallbacks(java.lang.String add,
java.lang.String change,
java.lang.String remove,
java.lang.String swap)
Sets the callbacks for this service.
|
ServiceDependency |
setDebug(java.lang.String debugKey)
Enabled debug logging for this dependency instance.
|
ServiceDependency |
setDefaultImplementation(java.lang.Object implementation)
Sets the default implementation for an
optional service dependency. |
ServiceDependency |
setDereference(boolean dereferenceServiceInternally)
Configures whether or not this dependency should internally obtain the service object for all tracked service references.
|
ServiceDependency |
setPropagate(boolean propagate)
Sets propagation of the service dependency properties to the provided service properties.
|
ServiceDependency |
setPropagate(java.lang.Object instance,
java.lang.String method)
Sets an Object instance and a callback method used to propagate some properties to the provided service properties.
|
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,
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.
|
ServiceDependency |
setService(java.lang.String serviceFilter)
Sets the filter for the services that should be tracked.
|
getAutoConfigName, getProperties, isAutoConfig, isAvailable, isPropagated, isRequired, overrideServiceProperties
getFilter, getName, getSimpleName, getState, getType
ServiceDependency setCallbacks(java.lang.String add, java.lang.String remove)
add
- the method to call when a service was addedremove
- the method to call when a service was removedServiceDependency setCallbacks(java.lang.String add, java.lang.String change, java.lang.String remove)
add
- the method to call when a service was addedchange
- the method to call when a service was changedremove
- the method to call when a service was removedServiceDependency setCallbacks(java.lang.String add, java.lang.String change, java.lang.String remove, java.lang.String swap)
add
- the method to call when a service was addedchange
- the method to call when a service was changedremove
- the method to call when a service was removedswap
- the method to call when the service was swapped due to addition or
removal of an aspectServiceDependency setCallbacks(java.lang.Object instance, java.lang.String add, java.lang.String remove)
instance
- the instance to call the callbacks onadd
- the method to call when a service was addedremove
- the method to call when a service was removedServiceDependency setCallbacks(java.lang.Object instance, java.lang.String add, java.lang.String change, java.lang.String remove)
instance
- the instance to call the callbacks onadd
- the method to call when a service was addedchange
- the method to call when a service was changedremove
- the method to call when a service was removedServiceDependency setCallbacks(java.lang.Object instance, java.lang.String added, java.lang.String changed, java.lang.String removed, java.lang.String swapped)
instance
- the instance to call the callbacks onadded
- the method to call when a service was addedchanged
- the method to call when a service was changedremoved
- the method to call when a service was removedswapped
- the method to call when the service was swapped due to addition or
removal of an aspectServiceDependency setRequired(boolean required)
required
- the required flagServiceDependency setAutoConfig(boolean autoConfig)
Iterable<T>
where T must match the dependency type.
In this case, an Iterable will be injected by DependencyManager before the start callback is called.
The Iterable field may then be traversed to inspect the currently available dependency services. The Iterable
can possibly be set to a final value so you can choose the Iterable implementation of your choice
(for example, a CopyOnWrite ArrayList, or a ConcurrentLinkedQueue).
Map<K,V>
where K must match the dependency type and V must exactly be equal to Dictionary
.
In this case, a ConcurrentHashMap will be injected by DependencyManager before the start callback is called.
The Map may then be consulted to lookup current available dependency services, including the dependency service
properties (the map key holds the dependency service, and the map value holds the dependency service properties).
The Map field may be set to a final value so you can choose a Map of your choice (Typically a ConcurrentHashMap).
A ConcurrentHashMap is "weakly consistent", meaning that when traversing
the elements, you may or may not see any concurrent updates made on the map. So, take care to traverse
the map using an iterator on the map entry set, which allows to atomically lookup pairs of Dependency service/Service properties.
Here are some example using an Iterable:
Here are some example using a Map:public class SpellChecker { // can be traversed to inspect currently available dependencies final Iterable<DictionaryService> dictionaries = new ConcurrentLinkedQueue<>(); Or // will be injected by DM automatically and can be traversed any time to inspect all currently available dependencies. volatile Iterable<DictionaryService> dictionaries = null; }
public class SpellChecker { // can be traversed to inspect currently available dependencies final Map<DictionaryService, Dictionary> dictionaries = new ConcurrentLinkedQueue<>(); or // will be injected by DM automatically and can be traversed to inspect currently available dependencies volatile Map<DictionaryService, Dictionary> dictionaries = null; void iterateOnAvailableServices() { for (Map.Entryentry : this.services.entrySet()) { MyService currentService = entry.getKey(); Dictionary currentServiceProperties = entry.getValue(); // ... } } }
autoConfig
- the name of attribute to auto configureServiceDependency setAutoConfig(java.lang.String instanceName)
instanceName
- the name of attribute to auto configsetAutoConfig(boolean)
ServiceDependency setService(java.lang.Class<?> serviceName)
serviceName
- the name of the serviceServiceDependency setService(java.lang.Class<?> serviceName, java.lang.String serviceFilter)
serviceName
- the name of the serviceserviceFilter
- the filter conditionServiceDependency setService(java.lang.String serviceFilter)
serviceFilter
- the filter conditionServiceDependency setService(java.lang.Class<?> serviceName, ServiceReference serviceReference)
serviceName
- the name of the serviceserviceReference
- the service reference to trackServiceDependency setDefaultImplementation(java.lang.Object implementation)
optional
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.
Only use this attribute on an optional service dependency injected on a class field.implementation
- the instance to use or the class to instantiate if you want to lazily
instantiate this implementationServiceDependency setPropagate(boolean propagate)
propagate
- true if the dependency service properties should be propagated to the component service properties.ServiceDependency setPropagate(java.lang.Object instance, java.lang.String method)
instance
- the Object instance which is used to retrieve propagated service propertiesmethod
- the method to invoke for retrieving the properties to be propagated to the service properties.ServiceDependency setDebug(java.lang.String debugKey)
debugKey
- a prefix log identifierServiceDependency setDereference(boolean dereferenceServiceInternally)
BundleContext.getService(ServiceReference ref)
methods.
However, sometimes, your callback only needs the ServiceReference, and sometimes you don't want to dereference the service.
So, in this case you can use the setDereference(false)
method in order to tell to DM
that it should never internally dereference the service dependency internally.