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 class
private static interface
private class
private class
private class
private class
private class
static final class
private class
private class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate ReferenceMethods
private final AbstractComponentManager
<S> private DependencyManager.Customizer
<S, T> private final ReferenceMetadata
private final int
private int
private String
private ServiceTracker
<T, RefPair<S, T>, ExtendedServiceEvent> private static final String
private 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) boolean
bind
(ComponentContextImpl<S> componentContext, DependencyManager.OpenStatus<S, T> status) (package private) boolean
bindDependency
(ComponentContextImpl<S> componentContext, ReferenceMethod bindMethod, DependencyManager.OpenStatus<S, T> status) (package private) boolean
canUpdateDynamically
(Map<String, Object> properties) Returnstrue
if theproperties
can be dynamically applied to the component to which the dependency manager belongs.private boolean
cardinalityJustSatisfied
(int serviceCount) boolean
cardinalitySatisfied
(int serviceCount) (package private) void
close
(ComponentContextImpl<S> componentContext, EdgeInfo edgeInfo) Revoke the given bindings.(package private) void
private void
private static int
defaultMinimumCardinality
(ReferenceMetadata dependency) private boolean
doInvokeBindMethod
(ComponentContextImpl<S> componentContext, ReferenceMethod bindMethod, RefPair<S, T> refPair, int trackingCount) Returns aServiceReference
instances 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) int
getIndex()
private int
getMinimumCardinality
(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 ornull
if this is instance is not currently bound to that service.(package private) T
getService
(ComponentContextImpl<S> key) Returns the service instance for the service reference returned by thegetBestRefPair()
method.private T
getService
(ComponentContextImpl<S> key, RefPair<S, T> refPair) (package private) T
getService
(ComponentContextImpl<S> key, org.osgi.framework.ServiceReference<T> serviceReference) Returns the service described by the ServiceReference.private String
(package private) boolean
getServiceObject
(ComponentContextImpl<S> key, ReferenceMethod bindMethod, RefPair<S, T> refPair) List
<org.osgi.framework.ServiceReference<?>> Returns an array ofServiceReference
instances of all services this instance is bound to ornull
if 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 ornull
if this dependency has no target filter set.boolean
Returnstrue
if the component providing bundle has permission to get the service described by this reference.(package private) void
initBindingMethods
(ReferenceMethods bindMethods) Initialize binding methods.(package private) boolean
invokeBindMethod
(ComponentContextImpl<S> componentContext, RefPair<S, T> refPair, int trackingCount, EdgeInfo info) Calls the bind method.void
invokeBindMethodLate
(org.osgi.framework.ServiceReference<T> ref, int trackingCount) (package private) boolean
invokeInitMethod
(ComponentContextImpl<S> componentContext) Calls the optional init reference method.(package private) void
invokeUnbindMethod
(ComponentContextImpl<S> componentContext, RefPair<S, T> refPair, int trackingCount, EdgeInfo info) Calls the unbind method.(package private) boolean
invokeUpdatedMethod
(ComponentContextImpl<S> componentContext, RefPair<S, T> refPair, int trackingCount, EdgeInfo info) Calls the updated method.private boolean
private boolean
(package private) boolean
private boolean
boolean
Returnstrue
if 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 boolean
isStatic()
private DependencyManager.Customizer
<S, T> newRefPair
(org.osgi.framework.ServiceReference<T> serviceReference) (package private) DependencyManager.OpenStatus
<S, T> open
(ComponentContextImpl<S> componentContext, EdgeInfo edgeInfo) initializes a dependency.(package private) boolean
prebind
(ComponentContextImpl<S> key) private void
setTargetFilter
(String target, int minimumCardinality) Sets the target filter of this dependency to the new filter value.(package private) void
setTargetFilter
(Map<String, Object> properties) Sets the target filter from target filter property contained in the properties.(package private) 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.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
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 aServiceReference
instances for a service implementing the interface and complying to the (optional) target filter declared for this dependency. If no matching service can be foundnull
is returned. If the configured target filter is syntactically incorrect an error message is logged with the LogService andnull
is 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-null
service 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 dependencynull
is returned. All services returned by this method will be considered bound after this method returns.- Parameters:
key
- TODO
-
getServiceReferences
Description copied from interface:ReferenceManager
Returns an array ofServiceReference
instances of all services this instance is bound to ornull
if no services are actually bound.- Specified by:
getServiceReferences
in interfaceReferenceManager<S,
T>
-
getRefPair
Returns the RefPair containing the given service reference and the bound service ornull
if 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
null
if 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
null
if no service is registered for the service reference (any more).
-
getService
-
getName
Description copied from interface:ReferenceManager
Returns the name of the service reference.- Specified by:
getName
in interfaceReferenceManager<S,
T>
-
getReferenceMetadata
-
isSatisfied
public boolean isSatisfied()Returnstrue
if 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:
isSatisfied
in interfaceReferenceManager<S,
T>
-
hasGetPermission
public boolean hasGetPermission()Returnstrue
if 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, DependencyManager.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,
true
is returned.false
is 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:
true
if 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
Returnstrue
if theproperties
can 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.target
as 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 benull
if no target filtering is to be used.
-
newCustomizer
-
unregisterServiceListener
-
getTarget
Description copied from interface:ReferenceManager
Returns the target filter of this dependency as a string ornull
if this dependency has no target filter set.- Specified by:
getTarget
in interfaceReferenceManager<S,
T> - Returns:
- The target filter of this dependency or
null
if none is set.
-
toString
-
getServiceObject
boolean getServiceObject(ComponentContextImpl<S> key, ReferenceMethod bindMethod, RefPair<S, T> refPair) -
newRefPair
-
deactivateComponentManager
private void deactivateComponentManager()
-