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 class
AbstractComponentManager.State
-
Field Summary
Fields Modifier and Type Field Description private java.lang.String
failureReason
protected java.util.concurrent.locks.ReentrantReadWriteLock
m_activationLock
private int
m_ceiling
private long
m_componentId
private ComponentMethods<S>
m_componentMethods
protected ComponentContainer<S>
m_container
private java.util.List<DependencyManager<S,?>>
m_dependencyManagers
private boolean
m_dependencyManagersInitialized
private java.util.concurrent.atomic.AtomicReference<org.osgi.util.promise.Deferred<java.lang.Void>>
m_enabledLatchRef
This latch prevents concurrent enable, disable, and reconfigure.protected boolean
m_factoryInstance
private int
m_floor
private java.util.Set<java.lang.Integer>
m_missing
private java.util.concurrent.locks.Condition
m_missingCondition
private java.util.concurrent.locks.Lock
m_missingLock
private java.util.concurrent.locks.ReentrantLock
m_stateLock
private java.util.concurrent.atomic.AtomicInteger
m_trackingCount
(package private) static java.lang.String[]
REASONS
(package private) RegistrationManager<org.osgi.framework.ServiceRegistration<S>>
registrationManager
private java.util.concurrent.atomic.AtomicReference<AbstractComponentManager.State>
state
private static java.util.concurrent.atomic.AtomicLong
taskCounter
-
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 protected
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
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description (package private) void
activateInternal()
(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 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 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 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 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
deactivateDependencyManagers()
(package private) void
deactivateInternal(int reason, boolean disable, boolean dispose)
Handles deactivating, disabling, and disposing a component manager.protected abstract void
deleteComponent(int reason)
org.osgi.util.promise.Promise<java.lang.Void>
disable(boolean async)
private void
disableDependencyManagers()
(package private) void
disableInternal()
(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
doMissingWait()
(package private) void
dumpThreads()
org.osgi.util.promise.Promise<java.lang.Void>
enable(boolean async)
(package private) void
enableInternal()
(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.ComponentActivator
getActivator()
org.osgi.framework.Bundle
getBundle()
Returns theBundle
providing this component.(package private) org.osgi.framework.BundleContext
getBundleContext()
abstract void
getComponentManagers(java.util.List<AbstractComponentManager<S>> cms)
ComponentMetadata
getComponentMetadata()
(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 theDependencyManager
objects representing the declared references in declaration orderjava.lang.String
getFailureReason()
long
getId()
(package private) long
getLockTimeout()
ComponentLogger
getLogger()
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 theDependencyManager
objects representing the declared references in reversed declaration orderprivate java.lang.Object
getService()
All ComponentManagers are ServiceFactory instances(package private) boolean
getServiceInternal(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()
int
getSpecState()
(package private) AbstractComponentManager.State
getState()
(package private) java.util.concurrent.atomic.AtomicInteger
getTrackingCount()
private boolean
hasServiceRegistrationPermissions()
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
isFactory()
protected boolean
isImmediate()
(package private) boolean
isStateLocked()
private java.util.List<DependencyManager<S,?>>
loadDependencyManagers(ComponentMetadata metadata)
(package private) void
notifyWaiters()
(package private) void
obtainActivationReadLock()
(package private) void
obtainActivationWriteLock()
private void
obtainLock(java.util.concurrent.locks.Lock lock)
(package private) void
obtainStateLock()
(package private) abstract void
postRegister()
(package private) abstract void
preDeregister()
abstract void
reconfigure(java.util.Map<java.lang.String,java.lang.Object> configuration, boolean configurationDeleted, TargetedPID factoryPid)
(package private) void
registerComponentId()
(package private) <T> void
registerMissingDependency(DependencyManager<S,T> dm, org.osgi.framework.ServiceReference<T> ref, int trackingCount)
protected boolean
registerService()
Registers the service on behalf of the component.(package private) void
releaseActivationReadLock()
(package private) void
releaseActivationWriteeLock()
(package private) void
releaseStateLock()
void
setFailureReason(java.lang.Throwable e)
Set the activation failure reasonabstract void
setServiceProperties(java.util.Dictionary<java.lang.String,?> serviceProperties)
void
setServiceProperties(MethodResult methodResult, java.lang.Integer trackingCount)
(package private) void
setState(AbstractComponentManager.State previousState, AbstractComponentManager.State newState)
java.lang.String
toString()
(package private) void
tracked(int trackingCount)
(package private) void
unregisterComponentId()
protected boolean
unregisterService()
(package private) void
updateTargets(java.util.Map<java.lang.String,java.lang.Object> properties)
protected boolean
verifyDependencyManagers()
(package private) void
waitForTracked(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:
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
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:
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
public ComponentActivator getActivator()
-
clear
void clear()
-
getLogger
public ComponentLogger getLogger()
-
toString
public java.lang.String toString()
- Overrides:
toString
in 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 theDependencyManager
objects representing the declared references in declaration order
-
getReferenceManagers
public java.util.List<? extends ReferenceManager<S,?>> getReferenceManagers()
- Specified by:
getReferenceManagers
in interfaceComponentManager<S>
-
getReversedDependencyManagers
java.util.List<DependencyManager<S,?>> getReversedDependencyManagers()
Returns an iterator over theDependencyManager
objects 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:
getProperties
in 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 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
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 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 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:
getSpecState
in interfaceComponentManager<S>
-
getState
AbstractComponentManager.State getState()
-
getFailureReason
public java.lang.String getFailureReason()
- Specified by:
getFailureReason
in 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:
getRegisteredServiceReference
in interfaceComponentManager<S>
-
-