Class AbstractComponentManager<S>
java.lang.Object
org.apache.felix.scr.impl.manager.AbstractComponentManager<S>
- All Implemented Interfaces:
ComponentManager<S>
- Direct Known Subclasses:
ComponentFactoryImpl, SingleComponentManager
The default ComponentManager. Objects of this class are responsible for managing
implementation object's lifecycle.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Stringprotected final ReentrantReadWriteLockprivate intprivate longprivate final ComponentMethods<S> protected final ComponentContainer<S> private final List<DependencyManager<S, ?>> private booleanprivate final AtomicReference<org.osgi.util.promise.Deferred<Void>> This latch prevents concurrent enable, disable, and reconfigure.protected final booleanprivate intprivate final Conditionprivate final Lockprivate final ReentrantLockprivate final AtomicInteger(package private) static final String[](package private) final RegistrationManager<org.osgi.framework.ServiceRegistration<S>> private final AtomicReference<AbstractComponentManager.State> private static final AtomicLongFields inherited from interface ComponentManager
STATE_ACTIVE, STATE_DISPOSED, STATE_SATISFIED, STATE_UNSATISFIED_CONFIGURATION, STATE_UNSATISFIED_REFERENCE -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractComponentManager(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
Modifier and TypeMethodDescription(package private) final void(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 Dictionary<String, Object> Copies the properties from thesourceDictionaryinto thetargetDictionaryexcept for private properties (whose name has a leading dot) which are only copied if theallPropsparameter istrue.protected static Dictionary<String, Object> copyToDictionary(Dictionary<String, ?> source, boolean allProps) copyToMap(Dictionary<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 void(package private) final voiddeactivateInternal(int reason, boolean disable, boolean dispose) Handles deactivating, disabling, and disposing a component manager.protected abstract voiddeleteComponent(int reason) final org.osgi.util.promise.Promise<Void> disable(boolean async) private void(package private) final void(package private) voiddispose()voiddispose(int reason) Disposes off this component deactivating and disabling it first as required.private voiddoDeactivate(int reason, boolean disable) private boolean(package private) final voidfinal org.osgi.util.promise.Promise<Void> enable(boolean async) (package private) final void(package private) org.osgi.util.promise.Deferred<Void> Use a CountDownLatch as a non-reentrant "lock" that can be passed between threads.org.osgi.framework.BundleReturns theBundleproviding this component.(package private) org.osgi.framework.BundleContextabstract void(package private) ComponentMethods<S> (package private) DependencyManager<S, ?> getDependencyManager(String name) (package private) List<DependencyManager<S, ?>> Returns an iterator over theDependencyManagerobjects representing the declared references in declaration orderlonggetId()(package private) final longprotected String[]List<? extends ReferenceManager<S, ?>> final org.osgi.framework.ServiceReference<S> (package private) List<DependencyManager<S, ?>> Returns an iterator over theDependencyManagerobjects representing the declared references in reversed declaration orderprivate ObjectAll ComponentManagers are ServiceFactory instances(package private) booleangetServiceInternal(org.osgi.framework.ServiceRegistration<S> serviceRegistration) Returns the subset of component properties to be used as service properties.protected org.osgi.framework.ServiceRegistration<S> int(package private) AbstractComponentManager.StategetState()(package private) AtomicIntegerprivate booleanprivate 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 methodbooleanprotected boolean(package private) final booleanprivate List<DependencyManager<S, ?>> loadDependencyManagers(ComponentMetadata metadata) (package private) void(package private) final void(package private) final voidprivate voidobtainLock(Lock lock) (package private) final void(package private) abstract void(package private) abstract voidabstract voidreconfigure(Map<String, Object> configuration, boolean configurationDeleted, TargetedPID factoryPid) (package private) void(package private) <T> voidregisterMissingDependency(DependencyManager<S, T> dm, org.osgi.framework.ServiceReference<T> ref, int trackingCount) protected booleanRegisters the service on behalf of the component.(package private) final void(package private) final void(package private) final voidvoidSet the activation failure reasonabstract voidsetServiceProperties(Dictionary<String, ?> serviceProperties) voidsetServiceProperties(MethodResult methodResult, Integer trackingCount) (package private) voidsetState(AbstractComponentManager.State previousState, AbstractComponentManager.State newState) toString()(package private) voidtracked(int trackingCount) (package private) voidprotected boolean(package private) final voidupdateTargets(Map<String, Object> properties) protected boolean(package private) voidwaitForTracked(int trackingCount) We effectively maintain the set of completely processed service event tracking counts.
-
Field Details
-
REASONS
-
m_container
-
m_factoryInstance
protected final boolean m_factoryInstance -
m_componentId
private volatile long m_componentId -
m_componentMethods
-
m_dependencyManagers
-
m_dependencyManagersInitialized
private volatile boolean m_dependencyManagersInitialized -
m_trackingCount
-
m_stateLock
-
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
-
m_floor
private volatile int m_floor -
m_ceiling
private volatile int m_ceiling -
m_missingLock
-
m_missingCondition
-
m_missing
-
m_activationLock
-
failureReason
-
taskCounter
-
registrationManager
-
-
Constructor Details
-
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 Details
-
getLockTimeout
final long getLockTimeout() -
obtainLock
-
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
- Throws:
InterruptedException
-
registerComponentId
void registerComponentId() -
unregisterComponentId
void unregisterComponentId() -
enable
-
enableLatchWait
org.osgi.util.promise.Deferred<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:
InterruptedException
-
disable
-
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
-
getService
All ComponentManagers are ServiceFactory instances- Returns:
- this as a ServiceFactory.
-
getComponentMethods
ComponentMethods<S> getComponentMethods() -
getProvidedServices
-
registerService
protected boolean registerService()Registers the service on behalf of the component. -
unregisterService
protected boolean unregisterService() -
getServiceRegistration
-
getTrackingCount
AtomicInteger getTrackingCount() -
initDependencyManagers
-
collectDependencies
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
-
clear
void clear() -
getLogger
-
toString
-
hasServiceRegistrationPermissions
private boolean hasServiceRegistrationPermissions() -
loadDependencyManagers
-
updateTargets
-
verifyDependencyManagers
protected boolean verifyDependencyManagers() -
getDependencyManagers
List<DependencyManager<S,?>> getDependencyManagers()Returns an iterator over theDependencyManagerobjects representing the declared references in declaration order -
getReferenceManagers
- Specified by:
getReferenceManagersin interfaceComponentManager<S>
-
getReversedDependencyManagers
List<DependencyManager<S,?>> getReversedDependencyManagers()Returns an iterator over theDependencyManagerobjects representing the declared references in reversed declaration order -
getDependencyManager
-
deactivateDependencyManagers
private void deactivateDependencyManagers() -
disableDependencyManagers
private void disableDependencyManagers() -
getProperties
- Specified by:
getPropertiesin interfaceComponentManager<S>
-
setServiceProperties
-
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 Dictionary<String,Object> copyTo(Dictionary<String, Object> target, Map<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
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 Dictionary<String,Object> copyToDictionary(Dictionary<String, ?> source, boolean allProps) -
getComponentMetadata
-
getSpecState
public int getSpecState()- Specified by:
getSpecStatein interfaceComponentManager<S>
-
getState
AbstractComponentManager.State getState() -
getFailureReason
- Specified by:
getFailureReasonin interfaceComponentManager<S>
-
setFailureReason
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
-
postRegister
abstract void postRegister() -
preDeregister
abstract void preDeregister() -
reconfigure
public abstract void reconfigure(Map<String, Object> configuration, boolean configurationDeleted, TargetedPID factoryPid) -
getComponentManagers
-
getRegisteredServiceReference
- Specified by:
getRegisteredServiceReferencein interfaceComponentManager<S>
-