Class ComponentFactoryImpl<S>
- java.lang.Object
-
- org.apache.felix.scr.impl.manager.AbstractComponentManager<S>
-
- org.apache.felix.scr.impl.manager.ComponentFactoryImpl<S>
-
- All Implemented Interfaces:
ComponentContainer<S>
,ComponentManager<S>
,org.osgi.service.component.ComponentFactory<S>
public class ComponentFactoryImpl<S> extends AbstractComponentManager<S> implements org.osgi.service.component.ComponentFactory<S>, ComponentContainer<S>
TheComponentFactoryImpl
extends theAbstractComponentManager
class to implement the component factory functionality. As such the OSGi Declarative ServicesComponentFactory
interface is implemented.In addition the
ComponentHolder
interface is implemented to use this class directly as the holder for component instances created by thenewInstance(Dictionary)
method.This class implements spec-compliant component factories and the felix "persistent" component factory, where the factory is always registered whether or not all dependencies are present and the created components also persist whether or not the dependencies are present to allow the component instance to exist.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
ComponentFactoryImpl.ModifyComponentInstance<S>
-
Nested classes/interfaces inherited from class org.apache.felix.scr.impl.manager.AbstractComponentManager
AbstractComponentManager.State
-
-
Field Summary
Fields Modifier and Type Field Description protected long
m_changeCount
Configuration change count (R5) or imitation (R4)private java.util.Map<SingleComponentManager<S>,SingleComponentManager<S>>
m_componentInstances
Contains the component instances created by calling thenewInstance(Dictionary)
method.private java.util.Map<java.lang.String,java.lang.Object>
m_configuration
The configuration for the component factory.private boolean
m_hasConfiguration
Flag telling if our component factory is currently configured from config admin.protected TargetedPID
m_targetedPID
-
Fields inherited from class org.apache.felix.scr.impl.manager.AbstractComponentManager
m_activationLock, m_container, m_factoryInstance, REASONS, registrationManager
-
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 Constructor Description ComponentFactoryImpl(ComponentContainer<S> container, ComponentMethods componentMethods)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected boolean
collectDependencies(ComponentContextImpl<S> componentContext)
Collect and store in m_dependencies_map all the services for dependencies, outside of any locks.private SingleComponentManager<S>
createComponentManager()
Creates anSingleComponentManager
instance with theBundleComponentActivator
andComponentMetadata
of this instance.protected void
deleteComponent(int reason)
The component factory does not have a component to delete.void
dispose(int reason)
Disposes off all components ever created by this component holder.void
disposed(SingleComponentManager<S> component)
Informs the holder that the component has been disposed as a result of calling the dispose method.boolean
equals(java.lang.Object object)
Compares thisComponentFactoryImpl
object to another object.void
getComponentManagers(java.util.List<AbstractComponentManager<S>> cms)
protected void
getComponentManagers(java.util.Map<?,SingleComponentManager<S>> componentMap, java.util.List<AbstractComponentManager<S>> componentManagers)
TargetedPID
getConfigurationTargetedPID(TargetedPID pid, TargetedPID factoryPid)
java.util.Map<java.lang.String,java.lang.Object>
getProperties()
For ComponentFactoryImpl, this is used only for updating targets on the dependency managers, so we don't need any other properties.protected java.lang.String[]
getProvidedServices()
java.util.Dictionary<java.lang.String,java.lang.Object>
getServiceProperties()
Returns the subset of component properties to be used as service properties.boolean
hasConfiguration()
int
hashCode()
Returns a hash code value for the object.(package private) <T> void
invokeBindMethod(DependencyManager<S,T> dependencyManager, RefPair<S,T> reference, int trackingCount)
(package private) <T> void
invokeUnbindMethod(DependencyManager<S,T> dependencyManager, RefPair<S,T> oldRef, int trackingCount)
(package private) <T> boolean
invokeUpdatedMethod(DependencyManager<S,T> dependencyManager, RefPair<S,T> ref, int trackingCount)
Invoke updated methodboolean
isFactory()
org.osgi.service.component.ComponentInstance<S>
newInstance(java.util.Dictionary<java.lang.String,?> dictionary)
(package private) void
postRegister()
(package private) void
preDeregister()
void
reconfigure(java.util.Map<java.lang.String,java.lang.Object> configuration, boolean configurationDeleted, TargetedPID factoryPid)
void
setServiceProperties(java.util.Dictionary<java.lang.String,?> serviceProperties)
protected boolean
verifyDependencyManagers()
-
Methods inherited from class org.apache.felix.scr.impl.manager.AbstractComponentManager
activateInternal, clear, copyTo, copyToDictionary, copyToMap, deactivateInternal, disable, disableInternal, dispose, dumpThreads, enable, enableInternal, enableLatchWait, getActivator, getBundle, getBundleContext, getComponentMetadata, getComponentMethods, getDependencyManager, getDependencyManagers, getFailureReason, getId, getLockTimeout, getLogger, getReferenceManagers, getRegisteredServiceReference, getReversedDependencyManagers, getServiceInternal, getServiceRegistration, getSpecState, getState, getTrackingCount, isImmediate, isStateLocked, notifyWaiters, obtainActivationReadLock, obtainActivationWriteLock, obtainStateLock, registerComponentId, registerMissingDependency, registerService, releaseActivationReadLock, releaseActivationWriteeLock, releaseStateLock, setFailureReason, setServiceProperties, setState, toString, tracked, unregisterComponentId, unregisterService, updateTargets, waitForTracked
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.felix.scr.impl.manager.ComponentContainer
getActivator, getComponentMetadata, getLogger
-
-
-
-
Field Detail
-
m_componentInstances
private final java.util.Map<SingleComponentManager<S>,SingleComponentManager<S>> m_componentInstances
Contains the component instances created by calling thenewInstance(Dictionary)
method. These component instances are provided with updated configuration (or deleted configuration) if such modifications for the component factory takes place.The map is keyed by the component manager instances. The value of each entry is the same as the entry's key. This is an IdentityHashMap for speed, thus not a Set.
-
m_configuration
private volatile java.util.Map<java.lang.String,java.lang.Object> m_configuration
The configuration for the component factory. This configuration is supplied as the base configuration for each component instance created by thenewInstance(Dictionary)
method.
-
m_hasConfiguration
private volatile boolean m_hasConfiguration
Flag telling if our component factory is currently configured from config admin. We are configured when configuration policy is required and we have received the config admin properties, or when configuration policy is optional or ignored.
-
m_changeCount
protected volatile long m_changeCount
Configuration change count (R5) or imitation (R4)
-
m_targetedPID
protected TargetedPID m_targetedPID
-
-
Constructor Detail
-
ComponentFactoryImpl
public ComponentFactoryImpl(ComponentContainer<S> container, ComponentMethods componentMethods)
-
-
Method Detail
-
verifyDependencyManagers
protected boolean verifyDependencyManagers()
- Overrides:
verifyDependencyManagers
in classAbstractComponentManager<S>
-
isFactory
public boolean isFactory()
- Overrides:
isFactory
in classAbstractComponentManager<S>
-
newInstance
public org.osgi.service.component.ComponentInstance<S> newInstance(java.util.Dictionary<java.lang.String,?> dictionary)
- Specified by:
newInstance
in interfaceorg.osgi.service.component.ComponentFactory<S>
-
equals
public boolean equals(java.lang.Object object)
Compares thisComponentFactoryImpl
object to another object.A component factory impl is considered to be equal to another component factory impl if the component names are equal(using
String.equals
).- Overrides:
equals
in classjava.lang.Object
- Parameters:
object
- TheComponentFactoryImpl
object to be compared.- Returns:
true
ifobject
is aComponentFactoryImpl
and is equal to this object;false
otherwise.
-
hashCode
public int hashCode()
Returns a hash code value for the object.- Overrides:
hashCode
in classjava.lang.Object
- Returns:
- An integer which is a hash code value for this object.
-
deleteComponent
protected void deleteComponent(int reason)
The component factory does not have a component to delete.But in the backwards compatible case any instances created for factory configuration instances are to disabled as a consequence of deactivating the component factory.
- Specified by:
deleteComponent
in classAbstractComponentManager<S>
-
getProvidedServices
protected java.lang.String[] getProvidedServices()
- Overrides:
getProvidedServices
in classAbstractComponentManager<S>
-
hasConfiguration
public boolean hasConfiguration()
-
getProperties
public java.util.Map<java.lang.String,java.lang.Object> getProperties()
For ComponentFactoryImpl, this is used only for updating targets on the dependency managers, so we don't need any other properties.- Specified by:
getProperties
in interfaceComponentManager<S>
- Specified by:
getProperties
in classAbstractComponentManager<S>
-
setServiceProperties
public void setServiceProperties(java.util.Dictionary<java.lang.String,?> serviceProperties)
- Specified by:
setServiceProperties
in classAbstractComponentManager<S>
-
postRegister
void postRegister()
- Specified by:
postRegister
in classAbstractComponentManager<S>
-
preDeregister
void preDeregister()
- Specified by:
preDeregister
in classAbstractComponentManager<S>
-
getServiceProperties
public java.util.Dictionary<java.lang.String,java.lang.Object> getServiceProperties()
Description copied from class:AbstractComponentManager
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.- Overrides:
getServiceProperties
in classAbstractComponentManager<S>
-
collectDependencies
protected boolean collectDependencies(ComponentContextImpl<S> componentContext)
Description copied from class:AbstractComponentManager
Collect and store in m_dependencies_map all the services for dependencies, outside of any locks.- Overrides:
collectDependencies
in classAbstractComponentManager<S>
- 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
<T> boolean invokeUpdatedMethod(DependencyManager<S,T> dependencyManager, RefPair<S,T> ref, int trackingCount)
Description copied from class:AbstractComponentManager
Invoke updated method- Specified by:
invokeUpdatedMethod
in classAbstractComponentManager<S>
- Returns:
true
if the component needs reactivation,false
otherwise.
-
invokeBindMethod
<T> void invokeBindMethod(DependencyManager<S,T> dependencyManager, RefPair<S,T> reference, int trackingCount)
- Specified by:
invokeBindMethod
in classAbstractComponentManager<S>
-
invokeUnbindMethod
<T> void invokeUnbindMethod(DependencyManager<S,T> dependencyManager, RefPair<S,T> oldRef, int trackingCount)
- Specified by:
invokeUnbindMethod
in classAbstractComponentManager<S>
-
dispose
public void dispose(int reason)
Disposes off all components ever created by this component holder. This method is called if either the Declarative Services runtime is stopping or if the owning bundle is stopped. In both cases all components created by this holder must be disposed off.- Overrides:
dispose
in classAbstractComponentManager<S>
-
disposed
public void disposed(SingleComponentManager<S> component)
Description copied from interface:ComponentContainer
Informs the holder that the component has been disposed as a result of calling the dispose method.- Specified by:
disposed
in interfaceComponentContainer<S>
-
createComponentManager
private SingleComponentManager<S> createComponentManager()
Creates anSingleComponentManager
instance with theBundleComponentActivator
andComponentMetadata
of this instance. The component manager is kept in the internal set of created components. The component is neither configured nor enabled.
-
getComponentManagers
protected void getComponentManagers(java.util.Map<?,SingleComponentManager<S>> componentMap, java.util.List<AbstractComponentManager<S>> componentManagers)
-
getConfigurationTargetedPID
public TargetedPID getConfigurationTargetedPID(TargetedPID pid, TargetedPID factoryPid)
-
reconfigure
public void reconfigure(java.util.Map<java.lang.String,java.lang.Object> configuration, boolean configurationDeleted, TargetedPID factoryPid)
- Specified by:
reconfigure
in classAbstractComponentManager<S>
-
getComponentManagers
public void getComponentManagers(java.util.List<AbstractComponentManager<S>> cms)
- Specified by:
getComponentManagers
in classAbstractComponentManager<S>
-
-