Package org.apache.felix.utils.extender
Class AbstractExtender
java.lang.Object
org.apache.felix.utils.extender.AbstractExtender
- All Implemented Interfaces:
EventListener,org.osgi.framework.BundleActivator,org.osgi.framework.BundleListener,org.osgi.framework.SynchronousBundleListener,org.osgi.util.tracker.BundleTrackerCustomizer
public abstract class AbstractExtender
extends Object
implements org.osgi.framework.BundleActivator, org.osgi.util.tracker.BundleTrackerCustomizer, org.osgi.framework.SynchronousBundleListener
Base class to write bundle extenders.
This extender tracks started bundles (or starting if they have a lazy activation
policy) and will create an
Extension for each of them to manage it.
The extender will handle all concurrency and synchronization issues, see
Extension for more information about the additional constraints.
The extender guarantee that all extensions will be stopped synchronously with
the STOPPING event of a given bundle and that all extensions will be stopped
before the extender bundle is stopped.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate org.osgi.framework.BundleContextprivate final ConcurrentMap<org.osgi.framework.Bundle,FutureTask> private ExecutorServiceprivate final ConcurrentMap<org.osgi.framework.Bundle,Extension> private booleanprivate booleanprivate booleanprivate booleanprivate org.osgi.util.tracker.BundleTracker -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddingBundle(org.osgi.framework.Bundle bundle, org.osgi.framework.BundleEvent event) voidbundleChanged(org.osgi.framework.BundleEvent event) protected Collection<org.osgi.framework.Bundle>chooseBundlesToDestroy(Set<org.osgi.framework.Bundle> bundles) protected ExecutorServiceCreate the executor used to start extensions asynchronously.private voidcreateExtension(org.osgi.framework.Bundle bundle) protected abstract voidprivate voiddestroyExtension(org.osgi.framework.Bundle bundle) protected abstract ExtensiondoCreateExtension(org.osgi.framework.Bundle bundle) Create the extension for the given bundle, or null if the bundle is not to be extended.protected voiddoStart()protected voiddoStop()protected abstract voidorg.osgi.framework.BundleContextbooleanCheck if the extender performs a preemptive shutdown of all extensions when the framework is being stopped.booleanbooleanCheck if the extender is synchronous or not.voidmodifiedBundle(org.osgi.framework.Bundle bundle, org.osgi.framework.BundleEvent event, Object object) voidremovedBundle(org.osgi.framework.Bundle bundle, org.osgi.framework.BundleEvent event, Object object) voidsetPreemptiveShutdown(boolean preemptiveShutdown) voidsetSynchronous(boolean synchronous) voidstart(org.osgi.framework.BundleContext context) protected voidvoidstop(org.osgi.framework.BundleContext context) protected voidprotected abstract void
-
Field Details
-
extensions
-
destroying
-
stopping
private volatile boolean stopping -
stopped
private volatile boolean stopped -
synchronous
private boolean synchronous -
preemptiveShutdown
private boolean preemptiveShutdown -
context
private org.osgi.framework.BundleContext context -
executors
-
tracker
private org.osgi.util.tracker.BundleTracker tracker
-
-
Constructor Details
-
AbstractExtender
public AbstractExtender()
-
-
Method Details
-
isSynchronous
public boolean isSynchronous()Check if the extender is synchronous or not. If the flag is set, the extender will start the extension synchronously with the bundle being tracked or started. Else, the starting of the extension will be delegated to a thread pool.- Returns:
- if the extender is synchronous
-
isPreemptiveShutdown
public boolean isPreemptiveShutdown()Check if the extender performs a preemptive shutdown of all extensions when the framework is being stopped. The default behavior is to wait for the framework to stop the bundles and stop the extension at that time.- Returns:
- if the extender use a preemptive shutdown
-
getBundleContext
public org.osgi.framework.BundleContext getBundleContext() -
getExecutors
-
setSynchronous
public void setSynchronous(boolean synchronous) -
setPreemptiveShutdown
public void setPreemptiveShutdown(boolean preemptiveShutdown) -
isStopping
public boolean isStopping() -
start
- Specified by:
startin interfaceorg.osgi.framework.BundleActivator- Throws:
Exception
-
stop
- Specified by:
stopin interfaceorg.osgi.framework.BundleActivator- Throws:
Exception
-
doStart
- Throws:
Exception
-
doStop
- Throws:
Exception
-
startTracking
protected void startTracking() -
stopTracking
protected void stopTracking() -
createExecutor
Create the executor used to start extensions asynchronously.- Returns:
- an
-
chooseBundlesToDestroy
protected Collection<org.osgi.framework.Bundle> chooseBundlesToDestroy(Set<org.osgi.framework.Bundle> bundles) -
bundleChanged
public void bundleChanged(org.osgi.framework.BundleEvent event) - Specified by:
bundleChangedin interfaceorg.osgi.framework.BundleListener
-
addingBundle
- Specified by:
addingBundlein interfaceorg.osgi.util.tracker.BundleTrackerCustomizer
-
modifiedBundle
public void modifiedBundle(org.osgi.framework.Bundle bundle, org.osgi.framework.BundleEvent event, Object object) - Specified by:
modifiedBundlein interfaceorg.osgi.util.tracker.BundleTrackerCustomizer
-
removedBundle
public void removedBundle(org.osgi.framework.Bundle bundle, org.osgi.framework.BundleEvent event, Object object) - Specified by:
removedBundlein interfaceorg.osgi.util.tracker.BundleTrackerCustomizer
-
createExtension
private void createExtension(org.osgi.framework.Bundle bundle) -
destroyExtension
private void destroyExtension(org.osgi.framework.Bundle bundle) -
doCreateExtension
Create the extension for the given bundle, or null if the bundle is not to be extended.- Parameters:
bundle- the bundle to extend- Returns:
- The extension
- Throws:
Exception- If something goes wrong
-
debug
-
warn
-
error
-