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 String
protected final ReentrantReadWriteLock
private int
private long
private final ComponentMethods
<S> protected final ComponentContainer
<S> private final List
<DependencyManager<S, ?>> private boolean
private final AtomicReference
<org.osgi.util.promise.Deferred<Void>> This latch prevents concurrent enable, disable, and reconfigure.protected final boolean
private int
private final Condition
private final Lock
private final ReentrantLock
private final AtomicInteger
(package private) static final String[]
(package private) final RegistrationManager
<org.osgi.framework.ServiceRegistration<S>> private final AtomicReference
<AbstractComponentManager.State> private static final AtomicLong
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
ConstructorsModifierConstructorDescriptionprotected
AbstractComponentManager
(ComponentContainer<S> container, ComponentMethods<S> componentMethods) The constructor receives both the container and the methods.protected
AbstractComponentManager
(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) void
clear()
protected boolean
collectDependencies
(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 thesource
Dictionary
into thetarget
Dictionary
except for private properties (whose name has a leading dot) which are only copied if theallProps
parameter istrue
.protected static Dictionary
<String, Object> copyToDictionary
(Dictionary<String, ?> source, boolean allProps) copyToMap
(Dictionary<String, ?> source, boolean allProps) Copies the properties from thesource
Dictionary
into thetarget
Dictionary
except for private properties (whose name has a leading dot) which are only copied if theallProps
parameter istrue
.private void
(package private) final void
deactivateInternal
(int reason, boolean disable, boolean dispose) Handles deactivating, disabling, and disposing a component manager.protected abstract void
deleteComponent
(int reason) final org.osgi.util.promise.Promise
<Void> disable
(boolean async) private void
(package private) final void
(package private) void
dispose()
void
dispose
(int reason) Disposes off this component deactivating and disabling it first as required.private void
doDeactivate
(int reason, boolean disable) private boolean
(package private) final void
final 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.Bundle
Returns theBundle
providing this component.(package private) org.osgi.framework.BundleContext
abstract void
(package private) ComponentMethods
<S> (package private) DependencyManager
<S, ?> getDependencyManager
(String name) (package private) List
<DependencyManager<S, ?>> Returns an iterator over theDependencyManager
objects representing the declared references in declaration orderlong
getId()
(package private) final long
protected String[]
List
<? extends ReferenceManager<S, ?>> final org.osgi.framework.ServiceReference
<S> (package private) List
<DependencyManager<S, ?>> Returns an iterator over theDependencyManager
objects representing the declared references in reversed declaration orderprivate Object
All ComponentManagers are ServiceFactory instances(package private) boolean
getServiceInternal
(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.State
getState()
(package private) AtomicInteger
private boolean
private void
initDependencyManagers
(ComponentContextImpl<S> componentContext) (package private) abstract <T> void
invokeBindMethod
(DependencyManager<S, T> dependencyManager, RefPair<S, T> refPair, int trackingCount) (package private) abstract <T> void
invokeUnbindMethod
(DependencyManager<S, T> dependencyManager, RefPair<S, T> oldRefPair, int trackingCount) (package private) abstract <T> boolean
invokeUpdatedMethod
(DependencyManager<S, T> dependencyManager, RefPair<S, T> refPair, int trackingCount) Invoke updated methodboolean
protected boolean
(package private) final boolean
private List
<DependencyManager<S, ?>> loadDependencyManagers
(ComponentMetadata metadata) (package private) void
(package private) final void
(package private) final void
private void
obtainLock
(Lock lock) (package private) final void
(package private) abstract void
(package private) abstract void
abstract void
reconfigure
(Map<String, Object> configuration, boolean configurationDeleted, TargetedPID factoryPid) (package private) void
(package private) <T> void
registerMissingDependency
(DependencyManager<S, T> dm, org.osgi.framework.ServiceReference<T> ref, int trackingCount) protected boolean
Registers the service on behalf of the component.(package private) final void
(package private) final void
(package private) final void
void
Set the activation failure reasonabstract void
setServiceProperties
(Dictionary<String, ?> serviceProperties) void
setServiceProperties
(MethodResult methodResult, Integer trackingCount) (package private) void
setState
(AbstractComponentManager.State previousState, AbstractComponentManager.State newState) toString()
(package private) void
tracked
(int trackingCount) (package private) void
protected boolean
(package private) final void
updateTargets
(Map<String, Object> properties) protected boolean
(package private) void
waitForTracked
(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:
getId
in interfaceComponentManager<S>
-
getBundle
public org.osgi.framework.Bundle getBundle()Returns theBundle
providing 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:
true
if the component needs reactivation,false
otherwise.
-
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 theDependencyManager
objects representing the declared references in declaration order -
getReferenceManagers
- Specified by:
getReferenceManagers
in interfaceComponentManager<S>
-
getReversedDependencyManagers
List<DependencyManager<S,?>> getReversedDependencyManagers()Returns an iterator over theDependencyManager
objects representing the declared references in reversed declaration order -
getDependencyManager
-
deactivateDependencyManagers
private void deactivateDependencyManagers() -
disableDependencyManagers
private void disableDependencyManagers() -
getProperties
- Specified by:
getProperties
in 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 thesource
Dictionary
into thetarget
Dictionary
except for private properties (whose name has a leading dot) which are only copied if theallProps
parameter istrue
.- Parameters:
target
- TheDictionary
into which to copy the properties. Ifnull
a newHashtable
is created.source
- TheDictionary
providing the properties to copy. Ifnull
or empty, nothing is copied.allProps
- Whether all properties (true
) or only the public properties (false
) are to be copied.- Returns:
- The
target
is returned, which may be empty ifsource
isnull
or empty andtarget
wasnull
or all properties are private and had not to be copied
-
copyToMap
Copies the properties from thesource
Dictionary
into thetarget
Dictionary
except for private properties (whose name has a leading dot) which are only copied if theallProps
parameter istrue
.- Parameters:
source
- TheDictionary
providing the properties to copy. Ifnull
or empty, nothing is copied.allProps
- Whether all properties (true
) or only the public properties (false
) are to be copied.- Returns:
- The
target
is returned, which may be empty ifsource
isnull
or empty andtarget
wasnull
or 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:
getSpecState
in interfaceComponentManager<S>
-
getState
AbstractComponentManager.State getState() -
getFailureReason
- Specified by:
getFailureReason
in 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:
getRegisteredServiceReference
in interfaceComponentManager<S>
-