Class DependencyManager<S,T>
java.lang.Object
org.apache.felix.scr.impl.manager.DependencyManager<S,T>
- All Implemented Interfaces:
ReferenceManager<S,T>
The
DependencyManager manages the references to services
declared by a single <reference>invalid input: '<'/code element in component
descriptor.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate classprivate static interfaceprivate classprivate classprivate classprivate classprivate classstatic final classprivate classprivate class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate ReferenceMethodsprivate final AbstractComponentManager<S> private DependencyManager.Customizer<S, T> private final ReferenceMetadataprivate final intprivate intprivate Stringprivate ServiceTracker<T, RefPair<S, T>, ExtendedServiceEvent> private static final Stringprivate static final String -
Constructor Summary
ConstructorsConstructorDescriptionDependencyManager(AbstractComponentManager<S> componentManager, ReferenceMetadata dependency, int index) Constructor that receives several parameters. -
Method Summary
Modifier and TypeMethodDescription(package private) booleanbind(ComponentContextImpl<S> componentContext, OpenStatus<S, T> status) (package private) booleanbindDependency(ComponentContextImpl<S> componentContext, ReferenceMethod bindMethod, OpenStatus<S, T> status) (package private) booleancanUpdateDynamically(Map<String, Object> properties) Returnstrueif thepropertiescan be dynamically applied to the component to which the dependency manager belongs.private booleancardinalityJustSatisfied(int serviceCount) (package private) booleanbooleancardinalitySatisfied(int serviceCount) (package private) voidclose(ComponentContextImpl<S> componentContext, EdgeInfo edgeInfo) Revoke the given bindings.(package private) voidprivate voidprivate static intdefaultMinimumCardinality(ReferenceMetadata dependency) private booleandoInvokeBindMethod(ComponentContextImpl<S> componentContext, ReferenceMethod bindMethod, RefPair<S, T> refPair, int trackingCount) Returns aServiceReferenceinstances for a service implementing the interface and complying to the (optional) target filter declared for this dependency.private org.osgi.framework.ServiceReference<T>[]getFrameworkServiceReferences(String targetFilter) (package private) intgetIndex()private intgetMinimumCardinality(Map<String, Object> properties) getName()Returns the name of the service reference.getRefPair(org.osgi.framework.ServiceReference<T> serviceReference) Returns the RefPair containing the given service reference and the bound service ornullif this is instance is not currently bound to that service.(package private) TgetService(ComponentContextImpl<S> key) Returns the service instance for the service reference returned by thegetBestRefPair()method.private TgetService(ComponentContextImpl<S> key, RefPair<S, T> refPair) (package private) TgetService(ComponentContextImpl<S> key, org.osgi.framework.ServiceReference<T> serviceReference) Returns the service described by the ServiceReference.private String(package private) booleangetServiceObject(ComponentContextImpl<S> key, ReferenceMethod bindMethod, RefPair<S, T> refPair) List<org.osgi.framework.ServiceReference<?>> Returns an array ofServiceReferenceinstances of all services this instance is bound to ornullif no services are actually bound.(package private) T[]getServices(ComponentContextImpl<S> key) Returns an array of service instances for the service references returned by the customizer.Returns the target filter of this dependency as a string ornullif this dependency has no target filter set.booleanReturnstrueif the component providing bundle has permission to get the service described by this reference.(package private) voidinitBindingMethods(ReferenceMethods bindMethods) Initialize binding methods.(package private) booleaninvokeBindMethod(ComponentContextImpl<S> componentContext, RefPair<S, T> refPair, int trackingCount, EdgeInfo info) Calls the bind method.voidinvokeBindMethodLate(org.osgi.framework.ServiceReference<T> ref, int trackingCount) (package private) booleaninvokeInitMethod(ComponentContextImpl<S> componentContext) Calls the optional init reference method.(package private) voidinvokeUnbindMethod(ComponentContextImpl<S> componentContext, RefPair<S, T> refPair, int trackingCount, EdgeInfo info) Calls the unbind method.(package private) booleaninvokeUpdatedMethod(ComponentContextImpl<S> componentContext, RefPair<S, T> refPair, int trackingCount, EdgeInfo info) Calls the updated method.private booleanprivate boolean(package private) booleanprivate booleanbooleanReturnstrueif this dependency manager is satisfied, that is if either the dependency is optional or the number of services registered in the framework and available to this dependency manager is not zero.private booleanisStatic()private DependencyManager.Customizer<S, T> newRefPair(org.osgi.framework.ServiceReference<T> serviceReference) (package private) OpenStatus<S, T> open(ComponentContextImpl<S> componentContext, EdgeInfo edgeInfo) initializes a dependency.(package private) booleanprebind(ComponentContextImpl<S> key) private voidsetTargetFilter(String target, int minimumCardinality) Sets the target filter of this dependency to the new filter value.(package private) voidsetTargetFilter(Map<String, Object> properties) Sets the target filter from target filter property contained in the properties.(package private) intsize()Returns the number of services currently registered in the system, which match the service criteria (interface and optional target filter) configured for this dependency.toString()unregisterServiceListener(AtomicInteger trackingCount)
-
Field Details
-
m_componentManager
-
m_dependencyMetadata
-
m_index
private final int m_index -
m_customizer
-
m_bindMethods
-
m_tracker
-
m_target
-
m_minCardinality
private volatile int m_minCardinality -
OBJECTCLASS_CLAUSE
- See Also:
-
PROTOTYPE_SCOPE_CLAUSE
- See Also:
-
-
Constructor Details
-
DependencyManager
DependencyManager(AbstractComponentManager<S> componentManager, ReferenceMetadata dependency, int index) Constructor that receives several parameters.- Parameters:
dependency- An object that contains data about the dependencyindex- index of the dependency manager in the metadata
-
-
Method Details
-
defaultMinimumCardinality
-
getIndex
int getIndex() -
initBindingMethods
Initialize binding methods. -
getServiceName
-
isOptional
boolean isOptional() -
isEffectivelyOptional
private boolean isEffectivelyOptional() -
cardinalitySatisfied
boolean cardinalitySatisfied() -
cardinalitySatisfied
public boolean cardinalitySatisfied(int serviceCount) -
cardinalityJustSatisfied
private boolean cardinalityJustSatisfied(int serviceCount) -
isMultiple
private boolean isMultiple() -
isStatic
private boolean isStatic() -
isReluctant
private boolean isReluctant() -
deactivate
void deactivate() -
size
int size()Returns the number of services currently registered in the system, which match the service criteria (interface and optional target filter) configured for this dependency. The number returned by this method has no correlation to the number of services bound to this dependency manager. It is actually the maximum number of services which may be bound to this dependency manager.- See Also:
-
getFrameworkServiceReferences
-
getBestRefPair
Returns aServiceReferenceinstances for a service implementing the interface and complying to the (optional) target filter declared for this dependency. If no matching service can be foundnullis returned. If the configured target filter is syntactically incorrect an error message is logged with the LogService andnullis returned. If multiple matching services are registered the service with the highest service.ranking value is returned. If multiple matching services have the same service.ranking value, the service with the lowest service.id is returned. -
getService
Returns the service instance for the service reference returned by thegetBestRefPair()method. If this returns a non-nullservice instance the service is then considered bound to this instance.- Parameters:
key- TODO
-
getServices
Returns an array of service instances for the service references returned by the customizer. If no services match the criteria configured for this dependencynullis returned. All services returned by this method will be considered bound after this method returns.- Parameters:
key- TODO
-
getServiceReferences
Description copied from interface:ReferenceManagerReturns an array ofServiceReferenceinstances of all services this instance is bound to ornullif no services are actually bound.- Specified by:
getServiceReferencesin interfaceReferenceManager<S,T>
-
getRefPair
Returns the RefPair containing the given service reference and the bound service ornullif this is instance is not currently bound to that service.- Parameters:
serviceReference- The reference to the bound service- Returns:
- RefPair the reference and service for the reference
if the service is bound or
nullif the service is not bound.
-
getService
Returns the service described by the ServiceReference. If this instance is already bound the given service, that bound service instance is returned. Otherwise the service retrieved from the service registry and kept as a bound service for future use.- Parameters:
key- TODOserviceReference- The reference to the service to be returned- Returns:
- The requested service or
nullif no service is registered for the service reference (any more).
-
getService
-
getName
Description copied from interface:ReferenceManagerReturns the name of the service reference.- Specified by:
getNamein interfaceReferenceManager<S,T>
-
getReferenceMetadata
-
isSatisfied
public boolean isSatisfied()Returnstrueif this dependency manager is satisfied, that is if either the dependency is optional or the number of services registered in the framework and available to this dependency manager is not zero.- Specified by:
isSatisfiedin interfaceReferenceManager<S,T>
-
hasGetPermission
public boolean hasGetPermission()Returnstrueif the component providing bundle has permission to get the service described by this reference. -
prebind
-
open
initializes a dependency. This method binds all of the service occurrences to the instance object- Parameters:
edgeInfo- Edge info for the combination of this component instance and this dependency manager.- Returns:
- true if the dependency is satisfied and at least the minimum number of services could be bound. Otherwise false is returned.
-
bind
-
bindDependency
boolean bindDependency(ComponentContextImpl<S> componentContext, ReferenceMethod bindMethod, OpenStatus<S, T> status) -
close
Revoke the given bindings. This method cannot throw an exception since it must try to complete all that it can- Parameters:
componentContext- instance we are unbinding from.edgeInfo- EdgeInfo for the combination of this component instance and this dependency manager.
-
invokeBindMethodLate
-
invokeInitMethod
Calls the optional init reference method. -
invokeBindMethod
boolean invokeBindMethod(ComponentContextImpl<S> componentContext, RefPair<S, T> refPair, int trackingCount, EdgeInfo info) Calls the bind method. In case there is an exception while calling the bind method, the service is not considered to be bound to the instance objectIf the reference is singular and a service has already been bound to the component this method has no effect and just returns
true.- Parameters:
componentContext- instance we are binding torefPair- the service reference, service object tuple.trackingCount- service event counter for this service.edgeInfo- EdgeInfo for the combination of this instance and this dependency manager.- Returns:
- true if the service should be considered bound. If no bind
method is found or the method call fails,
trueis returned.falseis only returned if the service must be handed over to the bind method but the service cannot be retrieved using the service reference.
-
doInvokeBindMethod
private boolean doInvokeBindMethod(ComponentContextImpl<S> componentContext, ReferenceMethod bindMethod, RefPair<S, T> refPair, int trackingCount) -
invokeUpdatedMethod
boolean invokeUpdatedMethod(ComponentContextImpl<S> componentContext, RefPair<S, T> refPair, int trackingCount, EdgeInfo info) Calls the updated method.- Parameters:
componentContext- instance we are calling updated on.refPair- A service reference corresponding to the service whose serviceedgeInfo- EdgeInfo for the combination of this instance and this dependency manager.- Returns:
trueif reactivation is required.
-
invokeUnbindMethod
void invokeUnbindMethod(ComponentContextImpl<S> componentContext, RefPair<S, T> refPair, int trackingCount, EdgeInfo info) Calls the unbind method.If the reference is singular and the given service is not the one bound to the component this method has no effect and just returns
true.- Parameters:
componentContext- instance we are unbinding fromrefPair- A service reference, service pair that will be unboundtrackingCount- service event count for this referenceinfo- EdgeInfo for the combination of this instance and this dependency manager
-
canUpdateDynamically
Returnstrueif thepropertiescan be dynamically applied to the component to which the dependency manager belongs.This method applies the following heuristics (in the given order):
- If there is no change in the target filter for this dependency, the properties can be applied
- If the dependency is static and there are changes in the target filter we cannot dynamically apply the configuration because the filter may (assume they do for simplicity here) cause the bindings to change.
- If there is still at least one service matching the new target filter we can apply the configuration because the depdency is dynamic.
- If there are no more services matching the filter, we can still apply the configuration if the dependency is optional.
- Ultimately, if all other checks do not apply we cannot dynamically apply.
-
setTargetFilter
Sets the target filter from target filter property contained in the properties. The filter is taken from a property whose name is derived from the dependency name and the suffix.targetas defined for target properties on page 302 of the Declarative Services Specification, section 112.6.- Parameters:
properties- The properties containing the optional target service filter property
-
getMinimumCardinality
-
setTargetFilter
Sets the target filter of this dependency to the new filter value. If the new target filter is the same as the old target filter, this method has not effect. Otherwise any services currently bound but not matching the new filter are unbound. Likewise any registered services not currently bound but matching the new filter are bound.- Parameters:
target- The new target filter to be set. This may benullif no target filtering is to be used.
-
newCustomizer
-
unregisterServiceListener
-
getTarget
Description copied from interface:ReferenceManagerReturns the target filter of this dependency as a string ornullif this dependency has no target filter set.- Specified by:
getTargetin interfaceReferenceManager<S,T> - Returns:
- The target filter of this dependency or
nullif none is set.
-
toString
-
getServiceObject
boolean getServiceObject(ComponentContextImpl<S> key, ReferenceMethod bindMethod, RefPair<S, T> refPair) -
newRefPair
-
deactivateComponentManager
private void deactivateComponentManager()
-