Class AbstractComponentManager<S>
- java.lang.Object
-
- org.apache.felix.scr.impl.manager.AbstractComponentManager<S>
-
- All Implemented Interfaces:
ComponentManager<S>
- Direct Known Subclasses:
ComponentFactoryImpl,SingleComponentManager
public abstract class AbstractComponentManager<S> extends java.lang.Object implements ComponentManager<S>
The default ComponentManager. Objects of this class are responsible for managing implementation object's lifecycle.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classAbstractComponentManager.State
-
Field Summary
Fields Modifier and Type Field Description private java.lang.StringfailureReasonprotected java.util.concurrent.locks.ReentrantReadWriteLockm_activationLockprivate intm_ceilingprivate longm_componentIdprivate ComponentMethods<S>m_componentMethodsprotected ComponentContainer<S>m_containerprivate java.util.List<DependencyManager<S,?>>m_dependencyManagersprivate booleanm_dependencyManagersInitializedprivate java.util.concurrent.atomic.AtomicReference<org.osgi.util.promise.Deferred<java.lang.Void>>m_enabledLatchRefThis latch prevents concurrent enable, disable, and reconfigure.protected booleanm_factoryInstanceprivate intm_floorprivate java.util.Set<java.lang.Integer>m_missingprivate java.util.concurrent.locks.Conditionm_missingConditionprivate java.util.concurrent.locks.Lockm_missingLockprivate java.util.concurrent.locks.ReentrantLockm_stateLockprivate java.util.concurrent.atomic.AtomicIntegerm_trackingCount(package private) static java.lang.String[]REASONS(package private) RegistrationManager<org.osgi.framework.ServiceRegistration<S>>registrationManagerprivate java.util.concurrent.atomic.AtomicReference<AbstractComponentManager.State>stateprivate static java.util.concurrent.atomic.AtomicLongtaskCounter-
Fields inherited from interface org.apache.felix.scr.impl.manager.ComponentManager
STATE_ACTIVE, STATE_DISPOSED, STATE_SATISFIED, STATE_UNSATISFIED_CONFIGURATION, STATE_UNSATISFIED_REFERENCE
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractComponentManager(ComponentContainer<S> container, ComponentMethods<S> componentMethods)The constructor receives both the container and the methods.protectedAbstractComponentManager(ComponentContainer<S> container, ComponentMethods<S> componentMethods, boolean factoryInstance)The constructor receives both the container and the methods.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description (package private) voidactivateInternal()(package private) voidclear()protected booleancollectDependencies(ComponentContextImpl<S> componentContext)Collect and store in m_dependencies_map all the services for dependencies, outside of any locks.protected static java.util.Dictionary<java.lang.String,java.lang.Object>copyTo(java.util.Dictionary<java.lang.String,java.lang.Object> target, java.util.Map<java.lang.String,?> source, boolean allProps)Copies the properties from thesourceDictionaryinto thetargetDictionaryexcept for private properties (whose name has a leading dot) which are only copied if theallPropsparameter istrue.protected static java.util.Dictionary<java.lang.String,java.lang.Object>copyToDictionary(java.util.Dictionary<java.lang.String,?> source, boolean allProps)protected static java.util.Map<java.lang.String,java.lang.Object>copyToMap(java.util.Dictionary<java.lang.String,?> source, boolean allProps)Copies the properties from thesourceDictionaryinto thetargetDictionaryexcept for private properties (whose name has a leading dot) which are only copied if theallPropsparameter istrue.private voiddeactivateDependencyManagers()(package private) voiddeactivateInternal(int reason, boolean disable, boolean dispose)Handles deactivating, disabling, and disposing a component manager.protected abstract voiddeleteComponent(int reason)org.osgi.util.promise.Promise<java.lang.Void>disable(boolean async)private voiddisableDependencyManagers()(package private) voiddisableInternal()(package private) voiddispose()voiddispose(int reason)Disposes off this component deactivating and disabling it first as required.private voiddoDeactivate(int reason, boolean disable)private booleandoMissingWait()(package private) voiddumpThreads()org.osgi.util.promise.Promise<java.lang.Void>enable(boolean async)(package private) voidenableInternal()(package private) org.osgi.util.promise.Deferred<java.lang.Void>enableLatchWait()Use a CountDownLatch as a non-reentrant "lock" that can be passed between threads.ComponentActivatorgetActivator()org.osgi.framework.BundlegetBundle()Returns theBundleproviding this component.(package private) org.osgi.framework.BundleContextgetBundleContext()abstract voidgetComponentManagers(java.util.List<AbstractComponentManager<S>> cms)ComponentMetadatagetComponentMetadata()(package private) ComponentMethods<S>getComponentMethods()(package private) DependencyManager<S,?>getDependencyManager(java.lang.String name)(package private) java.util.List<DependencyManager<S,?>>getDependencyManagers()Returns an iterator over theDependencyManagerobjects representing the declared references in declaration orderjava.lang.StringgetFailureReason()longgetId()(package private) longgetLockTimeout()ComponentLoggergetLogger()abstract java.util.Map<java.lang.String,java.lang.Object>getProperties()protected java.lang.String[]getProvidedServices()java.util.List<? extends ReferenceManager<S,?>>getReferenceManagers()org.osgi.framework.ServiceReference<S>getRegisteredServiceReference()(package private) java.util.List<DependencyManager<S,?>>getReversedDependencyManagers()Returns an iterator over theDependencyManagerobjects representing the declared references in reversed declaration orderprivate java.lang.ObjectgetService()All ComponentManagers are ServiceFactory instances(package private) booleangetServiceInternal(org.osgi.framework.ServiceRegistration<S> serviceRegistration)java.util.Dictionary<java.lang.String,java.lang.Object>getServiceProperties()Returns the subset of component properties to be used as service properties.protected org.osgi.framework.ServiceRegistration<S>getServiceRegistration()intgetSpecState()(package private) AbstractComponentManager.StategetState()(package private) java.util.concurrent.atomic.AtomicIntegergetTrackingCount()private booleanhasServiceRegistrationPermissions()private voidinitDependencyManagers(ComponentContextImpl<S> componentContext)(package private) abstract <T> voidinvokeBindMethod(DependencyManager<S,T> dependencyManager, RefPair<S,T> refPair, int trackingCount)(package private) abstract <T> voidinvokeUnbindMethod(DependencyManager<S,T> dependencyManager, RefPair<S,T> oldRefPair, int trackingCount)(package private) abstract <T> booleaninvokeUpdatedMethod(DependencyManager<S,T> dependencyManager, RefPair<S,T> refPair, int trackingCount)Invoke updated methodbooleanisFactory()protected booleanisImmediate()(package private) booleanisStateLocked()private java.util.List<DependencyManager<S,?>>loadDependencyManagers(ComponentMetadata metadata)(package private) voidnotifyWaiters()(package private) voidobtainActivationReadLock()(package private) voidobtainActivationWriteLock()private voidobtainLock(java.util.concurrent.locks.Lock lock)(package private) voidobtainStateLock()(package private) abstract voidpostRegister()(package private) abstract voidpreDeregister()abstract voidreconfigure(java.util.Map<java.lang.String,java.lang.Object> configuration, boolean configurationDeleted, TargetedPID factoryPid)(package private) voidregisterComponentId()(package private) <T> voidregisterMissingDependency(DependencyManager<S,T> dm, org.osgi.framework.ServiceReference<T> ref, int trackingCount)protected booleanregisterService()Registers the service on behalf of the component.(package private) voidreleaseActivationReadLock()(package private) voidreleaseActivationWriteeLock()(package private) voidreleaseStateLock()voidsetFailureReason(java.lang.Throwable e)Set the activation failure reasonabstract voidsetServiceProperties(java.util.Dictionary<java.lang.String,?> serviceProperties)voidsetServiceProperties(MethodResult methodResult, java.lang.Integer trackingCount)(package private) voidsetState(AbstractComponentManager.State previousState, AbstractComponentManager.State newState)java.lang.StringtoString()(package private) voidtracked(int trackingCount)(package private) voidunregisterComponentId()protected booleanunregisterService()(package private) voidupdateTargets(java.util.Map<java.lang.String,java.lang.Object> properties)protected booleanverifyDependencyManagers()(package private) voidwaitForTracked(int trackingCount)We effectively maintain the set of completely processed service event tracking counts.
-
-
-
Field Detail
-
REASONS
static final java.lang.String[] REASONS
-
m_container
protected final ComponentContainer<S> m_container
-
m_factoryInstance
protected final boolean m_factoryInstance
-
m_componentId
private volatile long m_componentId
-
m_componentMethods
private final ComponentMethods<S> m_componentMethods
-
m_dependencyManagers
private final java.util.List<DependencyManager<S,?>> m_dependencyManagers
-
m_dependencyManagersInitialized
private volatile boolean m_dependencyManagersInitialized
-
m_trackingCount
private final java.util.concurrent.atomic.AtomicInteger m_trackingCount
-
m_stateLock
private final java.util.concurrent.locks.ReentrantLock m_stateLock
-
m_enabledLatchRef
private final java.util.concurrent.atomic.AtomicReference<org.osgi.util.promise.Deferred<java.lang.Void>> m_enabledLatchRef
This latch prevents concurrent enable, disable, and reconfigure. Since the enable and disable operations may use two threads and the initiating thread does not wait for the operation to complete, we can't use a regular lock.
-
state
private final java.util.concurrent.atomic.AtomicReference<AbstractComponentManager.State> state
-
m_floor
private volatile int m_floor
-
m_ceiling
private volatile int m_ceiling
-
m_missingLock
private final java.util.concurrent.locks.Lock m_missingLock
-
m_missingCondition
private final java.util.concurrent.locks.Condition m_missingCondition
-
m_missing
private final java.util.Set<java.lang.Integer> m_missing
-
m_activationLock
protected final java.util.concurrent.locks.ReentrantReadWriteLock m_activationLock
-
failureReason
private volatile java.lang.String failureReason
-
taskCounter
private static final java.util.concurrent.atomic.AtomicLong taskCounter
-
registrationManager
final RegistrationManager<org.osgi.framework.ServiceRegistration<S>> registrationManager
-
-
Constructor Detail
-
AbstractComponentManager
protected AbstractComponentManager(ComponentContainer<S> container, ComponentMethods<S> componentMethods)
The constructor receives both the container and the methods.- Parameters:
container- The component containercomponentMethods- The component methods
-
AbstractComponentManager
protected AbstractComponentManager(ComponentContainer<S> container, ComponentMethods<S> componentMethods, boolean factoryInstance)
The constructor receives both the container and the methods.- Parameters:
container- The component containercomponentMethods- The component methodsfactoryInstance- Flag whether this is a factory instance
-
-
Method Detail
-
getLockTimeout
final long getLockTimeout()
-
obtainLock
private void obtainLock(java.util.concurrent.locks.Lock lock)
-
obtainActivationReadLock
final void obtainActivationReadLock()
-
releaseActivationReadLock
final void releaseActivationReadLock()
-
obtainActivationWriteLock
final void obtainActivationWriteLock()
-
releaseActivationWriteeLock
final void releaseActivationWriteeLock()
-
obtainStateLock
final void obtainStateLock()
-
releaseStateLock
final void releaseStateLock()
-
isStateLocked
final boolean isStateLocked()
-
dumpThreads
final void dumpThreads()
-
tracked
void tracked(int trackingCount)
-
waitForTracked
void waitForTracked(int trackingCount)
We effectively maintain the set of completely processed service event tracking counts. This method waits for all events prior to the parameter tracking count to complete, then returns. See further documentation in EdgeInfo.- Parameters:
trackingCount-
-
doMissingWait
private boolean doMissingWait() throws java.lang.InterruptedException- Throws:
java.lang.InterruptedException
-
registerComponentId
void registerComponentId()
-
unregisterComponentId
void unregisterComponentId()
-
enable
public final org.osgi.util.promise.Promise<java.lang.Void> enable(boolean async)
-
enableLatchWait
org.osgi.util.promise.Deferred<java.lang.Void> enableLatchWait()
Use a CountDownLatch as a non-reentrant "lock" that can be passed between threads. This lock assures that enable, disable, and reconfigure operations do not overlap.- Returns:
- the latch to count down when the operation is complete (in the calling or another thread)
- Throws:
java.lang.InterruptedException
-
disable
public final org.osgi.util.promise.Promise<java.lang.Void> disable(boolean async)
-
dispose
void dispose()
-
dispose
public void dispose(int reason)
Disposes off this component deactivating and disabling it first as required. After disposing off the component, it may not be used anymore.This method unlike the other state change methods immediately takes action and disposes the component. The reason for this is, that this method has to actually complete before other actions like bundle stopping may continue.
-
registerMissingDependency
<T> void registerMissingDependency(DependencyManager<S,T> dm, org.osgi.framework.ServiceReference<T> ref, int trackingCount)
-
getId
public long getId()
- Specified by:
getIdin interfaceComponentManager<S>
-
getBundle
public org.osgi.framework.Bundle getBundle()
Returns theBundleproviding this component. If the component as already been disposed off, this method returnsnull.
-
getBundleContext
org.osgi.framework.BundleContext getBundleContext()
-
isImmediate
protected boolean isImmediate()
-
isFactory
public boolean isFactory()
-
enableInternal
final void enableInternal()
-
activateInternal
final void activateInternal()
-
deactivateInternal
final void deactivateInternal(int reason, boolean disable, boolean dispose)Handles deactivating, disabling, and disposing a component manager. Deactivating a factory instance always disables and disposes it. Deactivating a factory disposes it.- Parameters:
reason- reason for actiondisable- whether to also disable the managerdispose- whether to also dispose of the manager
-
doDeactivate
private void doDeactivate(int reason, boolean disable)
-
disableInternal
final void disableInternal()
-
deleteComponent
protected abstract void deleteComponent(int reason)
-
getServiceInternal
boolean getServiceInternal(org.osgi.framework.ServiceRegistration<S> serviceRegistration)
-
getService
private java.lang.Object getService()
All ComponentManagers are ServiceFactory instances- Returns:
- this as a ServiceFactory.
-
getComponentMethods
ComponentMethods<S> getComponentMethods()
-
getProvidedServices
protected java.lang.String[] getProvidedServices()
-
registerService
protected boolean registerService()
Registers the service on behalf of the component.
-
unregisterService
protected boolean unregisterService()
-
getServiceRegistration
protected org.osgi.framework.ServiceRegistration<S> getServiceRegistration()
-
getTrackingCount
java.util.concurrent.atomic.AtomicInteger getTrackingCount()
-
initDependencyManagers
private void initDependencyManagers(ComponentContextImpl<S> componentContext)
-
collectDependencies
protected boolean collectDependencies(ComponentContextImpl<S> componentContext)
Collect and store in m_dependencies_map all the services for dependencies, outside of any locks.- Parameters:
componentContext- possible instance key for prototype scope references- Returns:
- true if all references can be collected, false if some dependency is no longer available.
-
invokeUpdatedMethod
abstract <T> boolean invokeUpdatedMethod(DependencyManager<S,T> dependencyManager, RefPair<S,T> refPair, int trackingCount)
Invoke updated method- Returns:
trueif the component needs reactivation,falseotherwise.
-
invokeBindMethod
abstract <T> void invokeBindMethod(DependencyManager<S,T> dependencyManager, RefPair<S,T> refPair, int trackingCount)
-
invokeUnbindMethod
abstract <T> void invokeUnbindMethod(DependencyManager<S,T> dependencyManager, RefPair<S,T> oldRefPair, int trackingCount)
-
notifyWaiters
void notifyWaiters()
-
getActivator
public ComponentActivator getActivator()
-
clear
void clear()
-
getLogger
public ComponentLogger getLogger()
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
hasServiceRegistrationPermissions
private boolean hasServiceRegistrationPermissions()
-
loadDependencyManagers
private java.util.List<DependencyManager<S,?>> loadDependencyManagers(ComponentMetadata metadata)
-
updateTargets
final void updateTargets(java.util.Map<java.lang.String,java.lang.Object> properties)
-
verifyDependencyManagers
protected boolean verifyDependencyManagers()
-
getDependencyManagers
java.util.List<DependencyManager<S,?>> getDependencyManagers()
Returns an iterator over theDependencyManagerobjects representing the declared references in declaration order
-
getReferenceManagers
public java.util.List<? extends ReferenceManager<S,?>> getReferenceManagers()
- Specified by:
getReferenceManagersin interfaceComponentManager<S>
-
getReversedDependencyManagers
java.util.List<DependencyManager<S,?>> getReversedDependencyManagers()
Returns an iterator over theDependencyManagerobjects representing the declared references in reversed declaration order
-
getDependencyManager
DependencyManager<S,?> getDependencyManager(java.lang.String name)
-
deactivateDependencyManagers
private void deactivateDependencyManagers()
-
disableDependencyManagers
private void disableDependencyManagers()
-
getProperties
public abstract java.util.Map<java.lang.String,java.lang.Object> getProperties()
- Specified by:
getPropertiesin interfaceComponentManager<S>
-
setServiceProperties
public abstract void setServiceProperties(java.util.Dictionary<java.lang.String,?> serviceProperties)
-
getServiceProperties
public java.util.Dictionary<java.lang.String,java.lang.Object> getServiceProperties()
Returns the subset of component properties to be used as service properties. These properties are all component properties where property name does not start with dot (.), properties which are considered private.
-
copyTo
protected static java.util.Dictionary<java.lang.String,java.lang.Object> copyTo(java.util.Dictionary<java.lang.String,java.lang.Object> target, java.util.Map<java.lang.String,?> source, boolean allProps)Copies the properties from thesourceDictionaryinto thetargetDictionaryexcept for private properties (whose name has a leading dot) which are only copied if theallPropsparameter istrue.- Parameters:
target- TheDictionaryinto which to copy the properties. Ifnulla newHashtableis created.source- TheDictionaryproviding the properties to copy. Ifnullor empty, nothing is copied.allProps- Whether all properties (true) or only the public properties (false) are to be copied.- Returns:
- The
targetis returned, which may be empty ifsourceisnullor empty andtargetwasnullor all properties are private and had not to be copied
-
copyToMap
protected static java.util.Map<java.lang.String,java.lang.Object> copyToMap(java.util.Dictionary<java.lang.String,?> source, boolean allProps)Copies the properties from thesourceDictionaryinto thetargetDictionaryexcept for private properties (whose name has a leading dot) which are only copied if theallPropsparameter istrue.- Parameters:
source- TheDictionaryproviding the properties to copy. Ifnullor empty, nothing is copied.allProps- Whether all properties (true) or only the public properties (false) are to be copied.- Returns:
- The
targetis returned, which may be empty ifsourceisnullor empty andtargetwasnullor all properties are private and had not to be copied
-
copyToDictionary
protected static java.util.Dictionary<java.lang.String,java.lang.Object> copyToDictionary(java.util.Dictionary<java.lang.String,?> source, boolean allProps)
-
getComponentMetadata
public ComponentMetadata getComponentMetadata()
-
getSpecState
public int getSpecState()
- Specified by:
getSpecStatein interfaceComponentManager<S>
-
getState
AbstractComponentManager.State getState()
-
getFailureReason
public java.lang.String getFailureReason()
- Specified by:
getFailureReasonin interfaceComponentManager<S>
-
setFailureReason
public void setFailureReason(java.lang.Throwable e)
Set the activation failure reason- Parameters:
e- The exception which caused the activation to fail
-
setState
void setState(AbstractComponentManager.State previousState, AbstractComponentManager.State newState)
-
setServiceProperties
public void setServiceProperties(MethodResult methodResult, java.lang.Integer trackingCount)
-
postRegister
abstract void postRegister()
-
preDeregister
abstract void preDeregister()
-
reconfigure
public abstract void reconfigure(java.util.Map<java.lang.String,java.lang.Object> configuration, boolean configurationDeleted, TargetedPID factoryPid)
-
getComponentManagers
public abstract void getComponentManagers(java.util.List<AbstractComponentManager<S>> cms)
-
getRegisteredServiceReference
public final org.osgi.framework.ServiceReference<S> getRegisteredServiceReference()
- Specified by:
getRegisteredServiceReferencein interfaceComponentManager<S>
-
-