public abstract class ConfigurableComponentHolder<S> extends java.lang.Object implements ComponentHolder<S>, ComponentContainer<S>, SimpleLogger
ConfigurableComponentHolder
class is a
ComponentHolder
for automatically configured components instances
that may or may not be configured through Config Admin.
The holder copes with three situations:
service.pid
or
service.factoryPid
equals the component name.service.pid
equals the component name.service.factoryPid
equals the component name.Modifier and Type | Class and Description |
---|---|
private static class |
ConfigurableComponentHolder.PSFLoader |
Modifier and Type | Field and Description |
---|---|
private java.lang.Object |
enableLock |
private ComponentActivator |
m_activator
The activator owning the per-bundle components
|
private java.lang.Long[] |
m_changeCount |
private ComponentMetadata |
m_componentMetadata
The
ComponentMetadata describing the held component(s) |
private ComponentMethods |
m_componentMethods |
private java.util.Map<java.lang.String,AbstractComponentManager<S>> |
m_components
A map of components configured with factory configuration.
|
private java.util.Dictionary<java.lang.String,java.lang.Object>[] |
m_configurations
the non-factory configurations shared between all instances.
|
private org.osgi.util.promise.Promise<java.lang.Void> |
m_disablePromise |
private boolean |
m_enabled
Whether components have already been enabled by calling the
enableComponents(boolean) method. |
private org.osgi.util.promise.Promise<java.lang.Void> |
m_enablePromise |
private java.util.Map<java.lang.String,java.lang.Long> |
m_factoryChangeCount |
private java.util.Map<java.lang.String,java.util.Dictionary<java.lang.String,java.lang.Object>> |
m_factoryConfigurations
the factory configurations indexed by pid (which cannot be a TargetedPID since it's generated by CA).
|
private java.lang.Integer |
m_factoryPidIndex
the index in metadata.getConfigurationPid() of the base factory pid, if any.
|
private java.util.Map<java.lang.String,TargetedPID> |
m_factoryTargetedPids
Each factory config may be from a different TargetedPID (sharing the same base service pid, but with different level of detail)
|
private AbstractComponentManager<S> |
m_singleComponent
The special component used if there is no configuration or a singleton
configuration.
|
private TargetedPID[] |
m_targetedPids
the targeted pids corresponding to the pids specified in the config metadata, except possibly for the single
factory pid
|
Constructor and Description |
---|
ConfigurableComponentHolder(ComponentActivator activator,
ComponentMetadata metadata) |
Modifier and Type | Method and Description |
---|---|
private void |
checkFactoryPidIndex(TargetedPID factoryPid) |
(package private) void |
clearComponents() |
void |
configurationDeleted(TargetedPID pid,
TargetedPID factoryPid)
The configuration with the given
pid
(service.pid of the configuration object) is deleted. |
boolean |
configurationUpdated(TargetedPID pid,
TargetedPID factoryPid,
java.util.Dictionary<java.lang.String,java.lang.Object> props,
long changeCount)
Configures a component with the given configuration.
|
protected static void |
copyTo(java.util.Map<java.lang.String,java.lang.Object> target,
java.util.Dictionary<java.lang.String,?> source) |
protected AbstractComponentManager<S> |
createComponentManager(boolean factoryConfiguration) |
protected abstract ComponentMethods |
createComponentMethods() |
org.osgi.util.promise.Promise<java.lang.Void> |
disableComponents(boolean async)
Disables all components of this holder.
|
void |
disposeComponents(int reason)
Disposes off all components of this holder.
|
void |
disposed(SingleComponentManager<S> component)
Informs the holder that the component has been disposed as a result of
calling the dispose method.
|
org.osgi.util.promise.Promise<java.lang.Void> |
enableComponents(boolean async)
Enables all components of this holder and if satisfied activates
them.
|
boolean |
equals(java.lang.Object object)
Compares this
ImmediateComponentHolder object to another object. |
ComponentActivator |
getActivator()
Returns the
ComponentActivator owning this component
holder. |
(package private) java.util.List<AbstractComponentManager<S>> |
getComponentManagers()
Returns all component managers from the map and the single component manager, optionally also removing them
from the map.
|
ComponentMetadata |
getComponentMetadata()
Returns the
ComponentMetadata describing and declaring this
component. |
protected ComponentMethods |
getComponentMethods() |
java.util.List<? extends ComponentManager<?>> |
getComponents()
Returns all
Component instances held by this holder. |
TargetedPID |
getConfigurationTargetedPID(TargetedPID pid,
TargetedPID factoryPid)
Returns the targeted PID used to configure this component
|
(package private) java.util.List<AbstractComponentManager<S>> |
getDirectComponentManagers() |
(package private) java.lang.String |
getName() |
private int |
getSingletonPidIndex(TargetedPID pid) |
int |
hashCode()
Returns a hash code value for the object.
|
boolean |
isEnabled()
whether the component is currently enabled
|
boolean |
isLogEnabled(int level) |
private boolean |
isSatisfied()
Determine if the holder is satisfied with configurations
|
void |
log(int level,
java.lang.String message,
java.lang.Object[] arguments,
java.lang.Throwable ex) |
void |
log(int level,
java.lang.String message,
java.lang.Throwable ex) |
private java.util.Map<java.lang.String,java.lang.Object> |
mergeProperties(java.lang.String servicePid) |
java.lang.String |
toString() |
private void |
wait(org.osgi.util.promise.Promise<java.lang.Void> promise) |
private final ComponentActivator m_activator
private final ComponentMetadata m_componentMetadata
ComponentMetadata
describing the held component(s)private final TargetedPID[] m_targetedPids
private final java.lang.Long[] m_changeCount
private final java.util.Map<java.lang.String,java.lang.Long> m_factoryChangeCount
private volatile java.lang.Integer m_factoryPidIndex
private final java.util.Dictionary<java.lang.String,java.lang.Object>[] m_configurations
private final java.util.Map<java.lang.String,java.util.Dictionary<java.lang.String,java.lang.Object>> m_factoryConfigurations
private final java.util.Map<java.lang.String,TargetedPID> m_factoryTargetedPids
private final java.util.Map<java.lang.String,AbstractComponentManager<S>> m_components
service.pid
) of the configuration objects.
The values are the component instances
created on behalf of the configurations.private volatile AbstractComponentManager<S> m_singleComponent
null
once all components
held by this holder have been disposed of by
disposeComponents(int)
and is first created in the constructor.
As factory configurations are provided this instance may be configured
or "deconfigured".
Expected invariants:
null
after disposal of all held
componentsm_components
map is empty or the component pointed to
by this field is also contained in the mapprivate volatile boolean m_enabled
enableComponents(boolean)
method. If this field is true
component instances created per configuration by the
configurationUpdated(TargetedPID, TargetedPID, Dictionary, long)
method are also
enabled. Otherwise they are not enabled immediately.private final java.lang.Object enableLock
private volatile org.osgi.util.promise.Promise<java.lang.Void> m_enablePromise
private volatile org.osgi.util.promise.Promise<java.lang.Void> m_disablePromise
private final ComponentMethods m_componentMethods
public ConfigurableComponentHolder(ComponentActivator activator, ComponentMetadata metadata)
protected abstract ComponentMethods createComponentMethods()
protected ComponentMethods getComponentMethods()
protected AbstractComponentManager<S> createComponentManager(boolean factoryConfiguration)
public final ComponentActivator getActivator()
ComponentHolder
ComponentActivator
owning this component
holder. (overlaps ComponentContaienr)getActivator
in interface ComponentContainer<S>
getActivator
in interface ComponentHolder<S>
public final ComponentMetadata getComponentMetadata()
ComponentHolder
ComponentMetadata
describing and declaring this
component. (overlaps ComponentContaienr)getComponentMetadata
in interface ComponentContainer<S>
getComponentMetadata
in interface ComponentHolder<S>
public void configurationDeleted(TargetedPID pid, TargetedPID factoryPid)
pid
(service.pid
of the configuration object) is deleted.
The following situations are supported:
configurationDeleted
in interface ComponentHolder<S>
pid
- The PID of the deleted configurationfactoryPid
- The factory PID of the deleted configurationpublic boolean configurationUpdated(TargetedPID pid, TargetedPID factoryPid, java.util.Dictionary<java.lang.String,java.lang.Object> props, long changeCount)
pid
equals the component name. Hence we have a
singleton configuration for the single component held by this holderconfigurationUpdated
in interface ComponentHolder<S>
pid
- Targeted PID for the configurationfactoryPid
- the (targeted) factory pid or null for a singleton pidprops
- the property dictionary from the configuration.changeCount
- change count of the configuration, or R4 imitation.private java.util.Map<java.lang.String,java.lang.Object> mergeProperties(java.lang.String servicePid)
private int getSingletonPidIndex(TargetedPID pid)
private void checkFactoryPidIndex(TargetedPID factoryPid)
protected static void copyTo(java.util.Map<java.lang.String,java.lang.Object> target, java.util.Dictionary<java.lang.String,?> source)
private boolean isSatisfied()
public java.util.List<? extends ComponentManager<?>> getComponents()
ComponentHolder
Component
instances held by this holder.getComponents
in interface ComponentHolder<S>
public boolean isEnabled()
ComponentHolder
isEnabled
in interface ComponentHolder<S>
private void wait(org.osgi.util.promise.Promise<java.lang.Void> promise)
public org.osgi.util.promise.Promise<java.lang.Void> enableComponents(boolean async)
ComponentHolder
enableComponents
in interface ComponentHolder<S>
async
- Whether the actual activation should take place
asynchronously or not.public org.osgi.util.promise.Promise<java.lang.Void> disableComponents(boolean async)
ComponentHolder
disableComponents
in interface ComponentHolder<S>
async
- Whether the actual deactivation should take place
asynchronously or not.public void disposeComponents(int reason)
ComponentHolder
disposeComponents
in interface ComponentHolder<S>
public void disposed(SingleComponentManager<S> component)
ComponentContainer
disposed
in interface ComponentContainer<S>
public boolean equals(java.lang.Object object)
ImmediateComponentHolder
object to another object.
A ImmediateComponentHolder is considered to be equal to another
ImmediateComponentHolder if the component names are equal(using
String.equals
) and they have the same bundle activator
equals
in class java.lang.Object
object
- The ImmediateComponentHolder
object to be compared.true
if object
is a
ImmediateComponentHolder
and is equal to this object;
false
otherwise.public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
java.lang.String getName()
java.util.List<AbstractComponentManager<S>> getComponentManagers()
null
is returned. Must be called synchronized on m_components.java.util.List<AbstractComponentManager<S>> getDirectComponentManagers()
void clearComponents()
public boolean isLogEnabled(int level)
isLogEnabled
in interface SimpleLogger
public void log(int level, java.lang.String message, java.lang.Throwable ex)
log
in interface SimpleLogger
public void log(int level, java.lang.String message, java.lang.Object[] arguments, java.lang.Throwable ex)
log
in interface SimpleLogger
public TargetedPID getConfigurationTargetedPID(TargetedPID pid, TargetedPID factoryPid)
ComponentHolder
getConfigurationTargetedPID
in interface ComponentHolder<S>
pid
- a targetedPID containing the service pid for the component desired (the rest of the targeted pid is ignored)factoryPid
- a targetedPID containing the factory pid for the component desired.