Package org.apache.felix.scr.impl
Class BundleComponentActivator
- java.lang.Object
-
- org.apache.felix.scr.impl.BundleComponentActivator
-
- All Implemented Interfaces:
ComponentActivator
,ExtendedServiceListenerContext<ExtendedServiceEvent>
public class BundleComponentActivator extends java.lang.Object implements ComponentActivator
The BundleComponentActivator is helper class to load and unload Components of a single bundle. It will read information from the metadata.xml file descriptors and create the corresponding managers.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
BundleComponentActivator.ListenerInfo
-
Field Summary
Fields Modifier and Type Field Description private ConfigAdminTracker
configAdminTracker
private java.util.Map<java.lang.String,BundleComponentActivator.ListenerInfo>
listenerMap
private BundleLogger
logger
private java.util.concurrent.atomic.AtomicBoolean
m_active
private org.osgi.framework.Bundle
m_bundle
private java.util.concurrent.CountDownLatch
m_closeLatch
private ComponentActorThread
m_componentActor
private ComponentRegistry
m_componentRegistry
private ScrConfiguration
m_configuration
private org.osgi.framework.BundleContext
m_context
private java.util.List<ComponentHolder<?>>
m_holders
-
Constructor Summary
Constructors Constructor Description BundleComponentActivator(ScrLogger scrLogger, ComponentRegistry componentRegistry, ComponentActorThread componentActor, org.osgi.framework.BundleContext context, ScrConfiguration configuration)
Called upon starting of the bundle.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addServiceListener(java.lang.String classNameFilter, org.osgi.framework.Filter eventFilter, ExtendedServiceListener<ExtendedServiceEvent> listener)
void
disableComponent(java.lang.String name)
Implements theComponentContext.disableComponent(String)
method by first finding the component(s) for thename
and disabling them.(package private) void
dispose(int reason)
Dispose of this component activator instance and all the component managers.void
enableComponent(java.lang.String name)
Implements theComponentContext.enableComponent(String)
method by first finding the component(s) for thename
and enabling them.<T> boolean
enterCreate(org.osgi.framework.ServiceReference<T> serviceReference)
(package private) static java.net.URL[]
findDescriptors(org.osgi.framework.Bundle bundle, java.lang.String descriptorLocation)
Finds component descriptors based on descriptor location.org.osgi.framework.BundleContext
getBundleContext()
Returns the BundleContextScrConfiguration
getConfiguration()
BundleLogger
getLogger()
private java.util.List<ComponentHolder<?>>
getSelectedComponents(java.lang.String name)
Returns an array ofComponentHolder
instances which match thename
.(package private) void
initialEnable()
Called outside the constructor so that the m_managers field is completely initialized.protected void
initialize(java.lang.String descriptorLocations)
Gets the MetaData location, parses the meta data and requests the processing of binder instancesboolean
isActive()
Returnsif this instance is active, that is if components may be activated for this component. <T> void
leaveCreate(org.osgi.framework.ServiceReference<T> serviceReference)
private void
loadDescriptor(java.net.URL descriptorURL)
<T> void
missingServicePresent(org.osgi.framework.ServiceReference<T> serviceReference)
long
registerComponentId(AbstractComponentManager<?> componentManager)
<S,T>
voidregisterMissingDependency(DependencyManager<S,T> dependencyManager, org.osgi.framework.ServiceReference<T> serviceReference, int trackingCount)
void
removeServiceListener(java.lang.String className, org.osgi.framework.Filter filter, ExtendedServiceListener<ExtendedServiceEvent> listener)
void
schedule(java.lang.Runnable task)
Schedules the giventask
for asynchrounous execution or synchronously runs the task if the thread is not running.RegionConfigurationSupport
setRegionConfigurationSupport(org.osgi.framework.ServiceReference<org.osgi.service.cm.ConfigurationAdmin> reference)
void
unregisterComponentId(AbstractComponentManager<?> componentManager)
void
unsetRegionConfigurationSupport(RegionConfigurationSupport rcs)
void
updateChangeCount()
Inform about any change in the state of the components.
-
-
-
Field Detail
-
m_componentRegistry
private final ComponentRegistry m_componentRegistry
-
m_bundle
private final org.osgi.framework.Bundle m_bundle
-
m_context
private final org.osgi.framework.BundleContext m_context
-
m_holders
private final java.util.List<ComponentHolder<?>> m_holders
-
m_componentActor
private final ComponentActorThread m_componentActor
-
m_active
private final java.util.concurrent.atomic.AtomicBoolean m_active
-
m_closeLatch
private final java.util.concurrent.CountDownLatch m_closeLatch
-
m_configuration
private final ScrConfiguration m_configuration
-
configAdminTracker
private final ConfigAdminTracker configAdminTracker
-
listenerMap
private final java.util.Map<java.lang.String,BundleComponentActivator.ListenerInfo> listenerMap
-
logger
private final BundleLogger logger
-
-
Constructor Detail
-
BundleComponentActivator
public BundleComponentActivator(ScrLogger scrLogger, ComponentRegistry componentRegistry, ComponentActorThread componentActor, org.osgi.framework.BundleContext context, ScrConfiguration configuration) throws org.osgi.service.component.ComponentException
Called upon starting of the bundle. This method invokes initialize() which parses the metadata and creates the holders- Parameters:
componentRegistry
- TheComponentRegistry
used to register components with to ensure uniqueness of component names and to ensure configuration updates.context
- The bundle context owning the components- Throws:
org.osgi.service.component.ComponentException
- if any error occurrs initializing this class
-
-
Method Detail
-
addServiceListener
public void addServiceListener(java.lang.String classNameFilter, org.osgi.framework.Filter eventFilter, ExtendedServiceListener<ExtendedServiceEvent> listener)
- Specified by:
addServiceListener
in interfaceExtendedServiceListenerContext<ExtendedServiceEvent>
-
removeServiceListener
public void removeServiceListener(java.lang.String className, org.osgi.framework.Filter filter, ExtendedServiceListener<ExtendedServiceEvent> listener)
- Specified by:
removeServiceListener
in interfaceExtendedServiceListenerContext<ExtendedServiceEvent>
-
initialize
protected void initialize(java.lang.String descriptorLocations)
Gets the MetaData location, parses the meta data and requests the processing of binder instances- Parameters:
descriptorLocations
- A comma separated list of locations of component descriptors. This must not benull
.- Throws:
java.lang.IllegalStateException
- If the bundle has already been uninstalled.
-
initialEnable
void initialEnable()
Called outside the constructor so that the m_managers field is completely initialized. A component might possibly start a thread to enable other components, which could access m_managers
-
findDescriptors
static java.net.URL[] findDescriptors(org.osgi.framework.Bundle bundle, java.lang.String descriptorLocation)
Finds component descriptors based on descriptor location.- Parameters:
bundle
- bundle to search for descriptor filesdescriptorLocation
- descriptor location- Returns:
- array of descriptors or empty array if none found
-
loadDescriptor
private void loadDescriptor(java.net.URL descriptorURL)
-
dispose
void dispose(int reason)
Dispose of this component activator instance and all the component managers.
-
isActive
public boolean isActive()
Returnsif this instance is active, that is if components may be activated for this component. The active flag is set early in the constructor indicating the activator is basically active (not fully setup, though) and reset early in the process of disposing
this instance.- Specified by:
isActive
in interfaceComponentActivator
-
getBundleContext
public org.osgi.framework.BundleContext getBundleContext()
Returns the BundleContext- Specified by:
getBundleContext
in interfaceComponentActivator
- Returns:
- the BundleContext
-
getConfiguration
public ScrConfiguration getConfiguration()
- Specified by:
getConfiguration
in interfaceComponentActivator
-
enableComponent
public void enableComponent(java.lang.String name)
Implements theComponentContext.enableComponent(String)
method by first finding the component(s) for thename
and enabling them. The enable method will schedule activation.- Specified by:
enableComponent
in interfaceComponentActivator
- Parameters:
name
- The name of the component to enable ornull
to enable all components.
-
disableComponent
public void disableComponent(java.lang.String name)
Implements theComponentContext.disableComponent(String)
method by first finding the component(s) for thename
and disabling them. The disable method will schedule deactivation- Specified by:
disableComponent
in interfaceComponentActivator
- Parameters:
name
- The name of the component to disable ornull
to disable all components.
-
getSelectedComponents
private java.util.List<ComponentHolder<?>> getSelectedComponents(java.lang.String name)
Returns an array ofComponentHolder
instances which match thename
. If thename
isnull
an array of all currently known component managers is returned. Otherwise an array containing a single component manager matching the name is returned if one is registered. Finally, if no component manager with the given name is registered,null
is returned.- Parameters:
name
- The name of the component manager to return ornull
to return an array of all component managers.- Returns:
- An array containing one or more component managers according
to the
name
parameter ornull
if no component manager with the given name is currently registered.
-
registerComponentId
public long registerComponentId(AbstractComponentManager<?> componentManager)
- Specified by:
registerComponentId
in interfaceComponentActivator
-
unregisterComponentId
public void unregisterComponentId(AbstractComponentManager<?> componentManager)
- Specified by:
unregisterComponentId
in interfaceComponentActivator
-
schedule
public void schedule(java.lang.Runnable task)
Schedules the giventask
for asynchrounous execution or synchronously runs the task if the thread is not running. If this instance isnot active
, the task is not executed.- Specified by:
schedule
in interfaceComponentActivator
- Parameters:
task
- The component task to execute
-
getLogger
public BundleLogger getLogger()
- Specified by:
getLogger
in interfaceComponentActivator
-
enterCreate
public <T> boolean enterCreate(org.osgi.framework.ServiceReference<T> serviceReference)
- Specified by:
enterCreate
in interfaceComponentActivator
-
leaveCreate
public <T> void leaveCreate(org.osgi.framework.ServiceReference<T> serviceReference)
- Specified by:
leaveCreate
in interfaceComponentActivator
-
missingServicePresent
public <T> void missingServicePresent(org.osgi.framework.ServiceReference<T> serviceReference)
- Specified by:
missingServicePresent
in interfaceComponentActivator
-
registerMissingDependency
public <S,T> void registerMissingDependency(DependencyManager<S,T> dependencyManager, org.osgi.framework.ServiceReference<T> serviceReference, int trackingCount)
- Specified by:
registerMissingDependency
in interfaceComponentActivator
-
setRegionConfigurationSupport
public RegionConfigurationSupport setRegionConfigurationSupport(org.osgi.framework.ServiceReference<org.osgi.service.cm.ConfigurationAdmin> reference)
- Specified by:
setRegionConfigurationSupport
in interfaceComponentActivator
-
unsetRegionConfigurationSupport
public void unsetRegionConfigurationSupport(RegionConfigurationSupport rcs)
- Specified by:
unsetRegionConfigurationSupport
in interfaceComponentActivator
-
updateChangeCount
public void updateChangeCount()
Description copied from interface:ComponentActivator
Inform about any change in the state of the components.- Specified by:
updateChangeCount
in interfaceComponentActivator
-
-