public abstract class DependencyModel
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
DependencyModel.DependencyEventType |
class |
DependencyModel.ServiceBindingHolder
Service binding structure.
|
Modifier and Type | Field and Description |
---|---|
static int |
BROKEN
Dependency state : BROKEN.
|
static int |
DYNAMIC_BINDING_POLICY
Binding policy : Dynamic.
|
static int |
DYNAMIC_PRIORITY_BINDING_POLICY
Binding policy : Dynamic-Priority.
|
protected ServiceReferenceManager |
m_serviceReferenceManager
The service reference manager.
|
static int |
RESOLVED
Dependency state : RESOLVED.
|
static int |
STATIC_BINDING_POLICY
Binding policy : Static.
|
static int |
UNRESOLVED
Dependency state : UNRESOLVED.
|
Constructor and Description |
---|
DependencyModel(java.lang.Class specification,
boolean aggregate,
boolean optional,
org.osgi.framework.Filter filter,
java.util.Comparator<org.osgi.framework.ServiceReference> comparator,
int policy,
org.osgi.framework.BundleContext context,
DependencyStateListener listener,
ComponentInstance ci)
Creates a DependencyModel.
|
Modifier and Type | Method and Description |
---|---|
boolean |
acquireReadLockIfNotHeld()
Acquires the read lock only and only if no read lock is already held by the current thread.
|
boolean |
acquireWriteLockIfNotHeld()
Acquires the write lock only and only if the write lock is not already held by the current thread.
|
void |
addListener(DependencyModelListener listener)
Add the given listener to the dependency model's list of listeners.
|
void |
applyReconfiguration(ServiceReferenceManager.ChangeSet changeSet)
Applies the given reconfiguration.
|
void |
cleanup()
Removes all the listeners from this dependency before it gets disposed.
|
int |
getBindingPolicy()
Gets the used binding policy.
|
org.osgi.framework.BundleContext |
getBundleContext()
Gets the bundle context used by the dependency.
|
java.lang.String |
getComparator()
Gets the used comparator name.
|
ComponentInstance |
getComponentInstance() |
ContextSourceManager |
getContextSourceManager() |
java.lang.String |
getFilter()
Returns the dependency filter (String form).
|
java.lang.String |
getId()
Gets the dependency id.
|
java.lang.Object |
getService(org.osgi.framework.ServiceReference ref)
Gets a service object for the given reference.
|
java.lang.Object |
getService(org.osgi.framework.ServiceReference ref,
boolean store)
Gets a service object for the given reference.
|
org.osgi.framework.ServiceReference |
getServiceReference()
Gets the first bound service reference.
|
ServiceReferenceManager |
getServiceReferenceManager() |
org.osgi.framework.ServiceReference[] |
getServiceReferences()
Gets bound service references.
|
int |
getSize()
Gets the number of actual matching references.
|
java.lang.Class |
getSpecification()
Gets the tracked specification.
|
int |
getState()
Gets the actual state of the dependency.
|
Tracker |
getTracker() |
java.util.List<org.osgi.framework.ServiceReference> |
getUsedServiceReferences()
Gets the list of currently used service references.
|
void |
invalidateMatchingServices() |
void |
invalidateSelectedServices()
This callback is called by ranking interceptor to notify the dependency that the selected service set has
changed and must be recomputed.
|
boolean |
isAggregate() |
boolean |
isFrozen()
Is the reference set frozen (cannot change anymore)?
This method must be override by concrete dependency to support
the static binding policy.
|
boolean |
isOptional() |
boolean |
match(org.osgi.framework.ServiceReference ref)
Does the service reference match ? This method must be overridden by
concrete dependencies if they need advanced testing on service reference
(that cannot be expressed in the LDAP filter).
|
void |
notifyListeners(DependencyModel.DependencyEventType type,
org.osgi.framework.ServiceReference<?> service,
java.lang.Object object)
Notify all listeners that a change has occurred in this dependency model.
|
void |
onChange(ServiceReferenceManager.ChangeSet set)
Callbacks call by the ServiceReferenceManager when the selected service set has changed.
|
abstract void |
onDependencyReconfiguration(org.osgi.framework.ServiceReference[] departs,
org.osgi.framework.ServiceReference[] arrivals)
Concrete dependency callback.
|
abstract void |
onServiceArrival(org.osgi.framework.ServiceReference ref)
Concrete dependency callback.
|
abstract void |
onServiceDeparture(org.osgi.framework.ServiceReference ref)
Concrete dependency callback.
|
abstract void |
onServiceModification(org.osgi.framework.ServiceReference ref)
Concrete dependency callback.
|
boolean |
releaseReadLockIfHeld()
Releases the read lock only and only if the read lock is held by the current thread.
|
boolean |
releaseWriteLockIfHeld()
Releases the write lock only and only if the write lock is held by the current thread.
|
void |
removeListener(DependencyModelListener listener)
Remove the given listener from the dependency model's list of listeners.
|
void |
setAggregate(boolean isAggregate)
Sets the aggregate attribute of the current dependency.
|
void |
setBundleContext(org.osgi.framework.BundleContext context)
Sets the bundle context used by this dependency.
|
void |
setComparator(java.util.Comparator<org.osgi.framework.ServiceReference> cmp) |
void |
setFilter(org.osgi.framework.Filter filter)
Sets the filter of the dependency.
|
void |
setOptionality(boolean isOptional)
Sets the optionality attribute of the current dependency.
|
void |
setSpecification(java.lang.Class specification)
Sets the required specification of this service dependency.
|
void |
start()
Opens the tracking.
|
void |
stop()
Closes the tracking.
|
void |
unfreeze()
Unfreezes the dependency.
|
void |
ungetService(org.osgi.framework.ServiceReference ref)
Ungets a used service reference.
|
public static final int BROKEN
public static final int UNRESOLVED
public static final int RESOLVED
public static final int DYNAMIC_BINDING_POLICY
public static final int STATIC_BINDING_POLICY
BROKEN
. The instance needs to be recreated.public static final int DYNAMIC_PRIORITY_BINDING_POLICY
protected final ServiceReferenceManager m_serviceReferenceManager
public DependencyModel(java.lang.Class specification, boolean aggregate, boolean optional, org.osgi.framework.Filter filter, java.util.Comparator<org.osgi.framework.ServiceReference> comparator, int policy, org.osgi.framework.BundleContext context, DependencyStateListener listener, ComponentInstance ci)
DYNAMIC_PRIORITY_BINDING_POLICY
policy
the OSGi Service Reference Comparator is used.specification
- the required specificationaggregate
- is the dependency aggregate ?optional
- is the dependency optional ?filter
- the LDAP filtercomparator
- the comparator object to sort referencespolicy
- the binding policycontext
- the bundle context (or service context)listener
- the dependency lifecycle listener to notify from dependencyci
- instance managing the dependency
state changes.public void start()
computeAndSetDependencyState()
public org.osgi.framework.BundleContext getBundleContext()
public void invalidateSelectedServices()
public void invalidateMatchingServices()
public void stop()
UNRESOLVED
at the end of this method.public boolean isFrozen()
false
by default.
The method must always return false
for non-static dependencies.true
if the reference set is frozen.public void unfreeze()
public boolean match(org.osgi.framework.ServiceReference ref)
true
.ref
- the tested reference.true
if the service reference matches.public org.osgi.framework.ServiceReference getServiceReference()
null
if no more provider is available,
else returns the first reference from the matching set.public org.osgi.framework.ServiceReference[] getServiceReferences()
null
if no references are available.public java.util.List<org.osgi.framework.ServiceReference> getUsedServiceReferences()
null
public ComponentInstance getComponentInstance()
public int getSize()
public abstract void onServiceArrival(org.osgi.framework.ServiceReference ref)
ref
- the service reference to inject.public abstract void onServiceDeparture(org.osgi.framework.ServiceReference ref)
ref
- the leaving service reference.public abstract void onServiceModification(org.osgi.framework.ServiceReference ref)
ref
- the modified service reference.public abstract void onDependencyReconfiguration(org.osgi.framework.ServiceReference[] departs, org.osgi.framework.ServiceReference[] arrivals)
departs
- the service leaving the matching set.arrivals
- the service arriving in the matching set.public int getState()
public java.lang.Class getSpecification()
public void setSpecification(java.lang.Class specification)
specification
- the required specification.public boolean acquireWriteLockIfNotHeld()
public boolean releaseWriteLockIfHeld()
public boolean acquireReadLockIfNotHeld()
public boolean releaseReadLockIfHeld()
public java.lang.String getFilter()
null
if not set.public void setFilter(org.osgi.framework.Filter filter)
filter
- the new LDAP filter.public void applyReconfiguration(ServiceReferenceManager.ChangeSet changeSet)
changeSet
- the reconfiguration changespublic boolean isAggregate()
public void setAggregate(boolean isAggregate)
isAggregate
- the new aggregate attribute value.public void setOptionality(boolean isOptional)
isOptional
- the new optional attribute value.public boolean isOptional()
public int getBindingPolicy()
public java.lang.String getComparator()
null
if no comparator (i.e. the OSGi one is used).null
if the dependency doesn't use a comparator.public void setComparator(java.util.Comparator<org.osgi.framework.ServiceReference> cmp)
public void setBundleContext(org.osgi.framework.BundleContext context)
context
- the bundle context or service context to usepublic java.lang.Object getService(org.osgi.framework.ServiceReference ref)
ref
- the wanted service referencepublic java.lang.Object getService(org.osgi.framework.ServiceReference ref, boolean store)
ref
- the wanted service referencestore
- enables / disables the storing of the reference.public void ungetService(org.osgi.framework.ServiceReference ref)
ref
- the reference to unget.public ContextSourceManager getContextSourceManager()
public java.lang.String getId()
public void onChange(ServiceReferenceManager.ChangeSet set)
set
- the change set.public ServiceReferenceManager getServiceReferenceManager()
public Tracker getTracker()
public void addListener(DependencyModelListener listener)
listener
- the DependencyModelListener
object to be addedjava.lang.NullPointerException
- if listener
is null
public void removeListener(DependencyModelListener listener)
listener
- the DependencyModelListener
object to be removedjava.lang.NullPointerException
- if listener
is null
java.util.NoSuchElementException
- if listener
wasn't present in the dependency model's list of listenerspublic void notifyListeners(DependencyModel.DependencyEventType type, org.osgi.framework.ServiceReference<?> service, java.lang.Object object)
type
- the type of eventservice
- the reference of the concerned service (may be null)object
- the concerned service object (may be null)public void cleanup()
Copyright © 2006-2014 The Apache Software Foundation. All Rights Reserved.