public interface ServiceDependency extends Dependency, ComponentDependencyDeclaration
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 this service dependency.
|
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,
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.
|
ServiceDependency |
setService(java.lang.String serviceFilter)
Sets the filter for the services that should be tracked.
|
getAutoConfigName, getProperties, isAutoConfig, isAvailable, isPropagated, isRequired
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 equals 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, org.osgi.framework.ServiceReference serviceReference)
serviceName
- the name of the serviceserviceReference
- the service reference to trackServiceDependency setDefaultImplementation(java.lang.Object implementation)
implementation
- the instance to use or the class to instantiate if you want to lazily
instantiate this implementationServiceDependency setPropagate(boolean propagate)
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 identifier