public class DependencyManager<S,T> extends java.lang.Object implements ReferenceManager<S,T>
DependencyManager
manages the references to services
declared by a single <reference>
Modifier and Type | Class and Description |
---|---|
private class |
DependencyManager.AbstractCustomizer |
private static interface |
DependencyManager.Customizer<S,T> |
private class |
DependencyManager.FactoryCustomizer |
private class |
DependencyManager.MultipleDynamicCustomizer |
private class |
DependencyManager.MultipleStaticGreedyCustomizer |
private class |
DependencyManager.MultipleStaticReluctantCustomizer |
private class |
DependencyManager.NoPermissionsCustomizer |
static class |
DependencyManager.OpenStatus<S,T> |
private class |
DependencyManager.SingleDynamicCustomizer |
private class |
DependencyManager.SingleStaticCustomizer |
Modifier and Type | Field and Description |
---|---|
private ReferenceMethods |
m_bindMethods |
private AbstractComponentManager<S> |
m_componentManager |
private DependencyManager.Customizer<S,T> |
m_customizer |
private ReferenceMetadata |
m_dependencyMetadata |
private int |
m_index |
private int |
m_minCardinality |
private java.lang.String |
m_target |
private ServiceTracker<T,RefPair<S,T>,ExtendedServiceEvent> |
m_tracker |
private static java.lang.String |
OBJECTCLASS_CLAUSE |
private static java.lang.String |
PROTOTYPE_SCOPE_CLAUSE |
Constructor and Description |
---|
DependencyManager(AbstractComponentManager<S> componentManager,
ReferenceMetadata dependency,
int index)
Constructor that receives several parameters.
|
Modifier and Type | Method and Description |
---|---|
(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(java.util.Map<java.lang.String,java.lang.Object> properties)
Returns
true if the properties 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 |
deactivate() |
private void |
deactivateComponentManager() |
private static int |
defaultMinimumCardinality(ReferenceMetadata dependency) |
private boolean |
doInvokeBindMethod(ComponentContextImpl<S> componentContext,
ReferenceMethod bindMethod,
RefPair<S,T> refPair,
int trackingCount) |
private RefPair<S,T> |
getBestRefPair()
Returns a
ServiceReference 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(java.lang.String targetFilter) |
(package private) int |
getIndex() |
private int |
getMinimumCardinality(java.util.Map<java.lang.String,java.lang.Object> properties) |
java.lang.String |
getName()
Returns the name of the service reference.
|
ReferenceMetadata |
getReferenceMetadata() |
private RefPair<S,T> |
getRefPair(org.osgi.framework.ServiceReference<T> serviceReference)
Returns the RefPair containing the given service reference and the bound service
or
null 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 the
getBestRefPair() 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 java.lang.String |
getServiceName() |
(package private) boolean |
getServiceObject(ComponentContextImpl<S> key,
ReferenceMethod bindMethod,
RefPair<S,T> refPair) |
java.util.List<org.osgi.framework.ServiceReference<?>> |
getServiceReferences()
Returns an array of
ServiceReference instances of all
services this instance is bound to or null 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.
|
java.lang.String |
getTarget()
Returns the target filter of this dependency as a string or
null if this dependency has no target filter set. |
boolean |
hasGetPermission()
Returns
true 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 |
isEffectivelyOptional() |
private boolean |
isMultiple() |
(package private) boolean |
isOptional() |
private boolean |
isReluctant() |
boolean |
isSatisfied()
Returns
true 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> |
newCustomizer() |
(package private) RefPair<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) |
(package private) void |
setTargetFilter(java.util.Map<java.lang.String,java.lang.Object> properties)
Sets the target filter from target filter property contained in the
properties.
|
private void |
setTargetFilter(java.lang.String target,
int minimumCardinality)
Sets the target filter of this dependency to the new filter value.
|
(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.
|
java.lang.String |
toString() |
(package private) java.util.SortedMap<org.osgi.framework.ServiceReference<T>,RefPair<S,T>> |
unregisterServiceListener(java.util.concurrent.atomic.AtomicInteger trackingCount) |
private final AbstractComponentManager<S> m_componentManager
private final ReferenceMetadata m_dependencyMetadata
private final int m_index
private volatile DependencyManager.Customizer<S,T> m_customizer
private volatile ReferenceMethods m_bindMethods
private volatile ServiceTracker<T,RefPair<S,T>,ExtendedServiceEvent> m_tracker
private volatile java.lang.String m_target
private volatile int m_minCardinality
private static final java.lang.String OBJECTCLASS_CLAUSE
private static final java.lang.String PROTOTYPE_SCOPE_CLAUSE
DependencyManager(AbstractComponentManager<S> componentManager, ReferenceMetadata dependency, int index)
dependency
- An object that contains data about the dependencyindex
- index of the dependency manager in the metadataprivate static int defaultMinimumCardinality(ReferenceMetadata dependency)
int getIndex()
void initBindingMethods(ReferenceMethods bindMethods)
private java.lang.String getServiceName()
boolean isOptional()
private boolean isEffectivelyOptional()
public boolean cardinalitySatisfied(int serviceCount)
private boolean cardinalityJustSatisfied(int serviceCount)
private boolean isMultiple()
private boolean isStatic()
private boolean isReluctant()
void deactivate()
int size()
isSatisfied()
private org.osgi.framework.ServiceReference<T>[] getFrameworkServiceReferences(java.lang.String targetFilter)
private RefPair<S,T> getBestRefPair()
ServiceReference
instances for a service
implementing the interface and complying to the (optional) target filter
declared for this dependency. If no matching service can be found
null
is returned. If the configured target filter is
syntactically incorrect an error message is logged with the LogService
and null
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.
T getService(ComponentContextImpl<S> key)
getBestRefPair()
method. If this returns a
non-null
service instance the service is then considered
bound to this instance.key
- TODOT[] getServices(ComponentContextImpl<S> key)
null
is
returned. All services returned by this method will be considered bound
after this method returns.key
- TODOpublic java.util.List<org.osgi.framework.ServiceReference<?>> getServiceReferences()
ReferenceManager
ServiceReference
instances of all
services this instance is bound to or null
if no services
are actually bound.getServiceReferences
in interface ReferenceManager<S,T>
private RefPair<S,T> getRefPair(org.osgi.framework.ServiceReference<T> serviceReference)
null
if this is instance is not currently bound to that
service.serviceReference
- The reference to the bound servicenull
if the service is not
bound.T getService(ComponentContextImpl<S> key, org.osgi.framework.ServiceReference<T> serviceReference)
key
- TODOserviceReference
- The reference to the service to be returnednull
if no service is
registered for the service reference (any more).public java.lang.String getName()
ReferenceManager
getName
in interface ReferenceManager<S,T>
public ReferenceMetadata getReferenceMetadata()
public boolean isSatisfied()
true
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.isSatisfied
in interface ReferenceManager<S,T>
public boolean hasGetPermission()
true
if the component providing bundle has permission
to get the service described by this reference.boolean prebind(ComponentContextImpl<S> key)
DependencyManager.OpenStatus<S,T> open(ComponentContextImpl<S> componentContext, EdgeInfo edgeInfo)
edgeInfo
- Edge info for the combination of this component instance and this dependency manager.boolean bind(ComponentContextImpl<S> componentContext, DependencyManager.OpenStatus<S,T> status)
boolean bindDependency(ComponentContextImpl<S> componentContext, ReferenceMethod bindMethod, DependencyManager.OpenStatus<S,T> status)
void close(ComponentContextImpl<S> componentContext, EdgeInfo edgeInfo)
componentContext
- instance we are unbinding from.edgeInfo
- EdgeInfo for the combination of this component instance and this dependency manager.public void invokeBindMethodLate(org.osgi.framework.ServiceReference<T> ref, int trackingCount)
boolean invokeInitMethod(ComponentContextImpl<S> componentContext)
boolean invokeBindMethod(ComponentContextImpl<S> componentContext, RefPair<S,T> refPair, int trackingCount, EdgeInfo info)
If the reference is singular and a service has already been bound to the
component this method has no effect and just returns true
.
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.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.private boolean doInvokeBindMethod(ComponentContextImpl<S> componentContext, ReferenceMethod bindMethod, RefPair<S,T> refPair, int trackingCount)
boolean invokeUpdatedMethod(ComponentContextImpl<S> componentContext, RefPair<S,T> refPair, int trackingCount, EdgeInfo info)
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.true
if reactivation is required.void invokeUnbindMethod(ComponentContextImpl<S> componentContext, RefPair<S,T> refPair, int trackingCount, EdgeInfo info)
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
.
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 managerboolean canUpdateDynamically(java.util.Map<java.lang.String,java.lang.Object> properties)
true
if the properties
can be
dynamically applied to the component to which the dependency manager
belongs.
This method applies the following heuristics (in the given order):
void setTargetFilter(java.util.Map<java.lang.String,java.lang.Object> properties)
.target
as defined
for target properties on page 302 of the Declarative Services
Specification, section 112.6.properties
- The properties containing the optional target service
filter propertyprivate int getMinimumCardinality(java.util.Map<java.lang.String,java.lang.Object> properties)
private void setTargetFilter(java.lang.String target, int minimumCardinality)
target
- The new target filter to be set. This may be
null
if no target filtering is to be used.private DependencyManager.Customizer<S,T> newCustomizer()
java.util.SortedMap<org.osgi.framework.ServiceReference<T>,RefPair<S,T>> unregisterServiceListener(java.util.concurrent.atomic.AtomicInteger trackingCount)
public java.lang.String getTarget()
ReferenceManager
null
if this dependency has no target filter set.getTarget
in interface ReferenceManager<S,T>
null
if
none is set.public java.lang.String toString()
toString
in class java.lang.Object
boolean getServiceObject(ComponentContextImpl<S> key, ReferenceMethod bindMethod, RefPair<S,T> refPair)
private void deactivateComponentManager()