Class AbstractExtender

  • All Implemented Interfaces:
    java.util.EventListener, org.osgi.framework.BundleActivator, org.osgi.framework.BundleListener, org.osgi.framework.SynchronousBundleListener, org.osgi.util.tracker.BundleTrackerCustomizer

    public abstract class AbstractExtender
    extends java.lang.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

      Fields 
      Modifier and Type Field Description
      private org.osgi.framework.BundleContext context  
      private java.util.concurrent.ConcurrentMap<org.osgi.framework.Bundle,​java.util.concurrent.FutureTask> destroying  
      private java.util.concurrent.ExecutorService executors  
      private java.util.concurrent.ConcurrentMap<org.osgi.framework.Bundle,​Extension> extensions  
      private boolean preemptiveShutdown  
      private boolean stopped  
      private boolean stopping  
      private boolean synchronous  
      private org.osgi.util.tracker.BundleTracker tracker  
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.Object addingBundle​(org.osgi.framework.Bundle bundle, org.osgi.framework.BundleEvent event)  
      void bundleChanged​(org.osgi.framework.BundleEvent event)  
      protected java.util.Collection<org.osgi.framework.Bundle> chooseBundlesToDestroy​(java.util.Set<org.osgi.framework.Bundle> bundles)  
      protected java.util.concurrent.ExecutorService createExecutor()
      Create the executor used to start extensions asynchronously.
      private void createExtension​(org.osgi.framework.Bundle bundle)  
      protected abstract void debug​(org.osgi.framework.Bundle bundle, java.lang.String msg)  
      private void destroyExtension​(org.osgi.framework.Bundle bundle)  
      protected abstract Extension doCreateExtension​(org.osgi.framework.Bundle bundle)
      Create the extension for the given bundle, or null if the bundle is not to be extended.
      protected void doStart()  
      protected void doStop()  
      protected abstract void error​(java.lang.String msg, java.lang.Throwable t)  
      org.osgi.framework.BundleContext getBundleContext()  
      java.util.concurrent.ExecutorService getExecutors()  
      boolean isPreemptiveShutdown()
      Check if the extender performs a preemptive shutdown of all extensions when the framework is being stopped.
      boolean isStopping()  
      boolean isSynchronous()
      Check if the extender is synchronous or not.
      void modifiedBundle​(org.osgi.framework.Bundle bundle, org.osgi.framework.BundleEvent event, java.lang.Object object)  
      void removedBundle​(org.osgi.framework.Bundle bundle, org.osgi.framework.BundleEvent event, java.lang.Object object)  
      void setPreemptiveShutdown​(boolean preemptiveShutdown)  
      void setSynchronous​(boolean synchronous)  
      void start​(org.osgi.framework.BundleContext context)  
      protected void startTracking()  
      void stop​(org.osgi.framework.BundleContext context)  
      protected void stopTracking()  
      protected abstract void warn​(org.osgi.framework.Bundle bundle, java.lang.String msg, java.lang.Throwable t)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • extensions

        private final java.util.concurrent.ConcurrentMap<org.osgi.framework.Bundle,​Extension> extensions
      • destroying

        private final java.util.concurrent.ConcurrentMap<org.osgi.framework.Bundle,​java.util.concurrent.FutureTask> 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

        private java.util.concurrent.ExecutorService executors
      • tracker

        private org.osgi.util.tracker.BundleTracker tracker
    • Constructor Detail

      • AbstractExtender

        public AbstractExtender()
    • Method Detail

      • 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

        public java.util.concurrent.ExecutorService getExecutors()
      • setSynchronous

        public void setSynchronous​(boolean synchronous)
      • setPreemptiveShutdown

        public void setPreemptiveShutdown​(boolean preemptiveShutdown)
      • isStopping

        public boolean isStopping()
      • start

        public void start​(org.osgi.framework.BundleContext context)
                   throws java.lang.Exception
        Specified by:
        start in interface org.osgi.framework.BundleActivator
        Throws:
        java.lang.Exception
      • stop

        public void stop​(org.osgi.framework.BundleContext context)
                  throws java.lang.Exception
        Specified by:
        stop in interface org.osgi.framework.BundleActivator
        Throws:
        java.lang.Exception
      • doStart

        protected void doStart()
                        throws java.lang.Exception
        Throws:
        java.lang.Exception
      • doStop

        protected void doStop()
                       throws java.lang.Exception
        Throws:
        java.lang.Exception
      • startTracking

        protected void startTracking()
      • stopTracking

        protected void stopTracking()
      • createExecutor

        protected java.util.concurrent.ExecutorService createExecutor()
        Create the executor used to start extensions asynchronously.
        Returns:
        an
      • chooseBundlesToDestroy

        protected java.util.Collection<org.osgi.framework.Bundle> chooseBundlesToDestroy​(java.util.Set<org.osgi.framework.Bundle> bundles)
      • bundleChanged

        public void bundleChanged​(org.osgi.framework.BundleEvent event)
        Specified by:
        bundleChanged in interface org.osgi.framework.BundleListener
      • addingBundle

        public java.lang.Object addingBundle​(org.osgi.framework.Bundle bundle,
                                             org.osgi.framework.BundleEvent event)
        Specified by:
        addingBundle in interface org.osgi.util.tracker.BundleTrackerCustomizer
      • modifiedBundle

        public void modifiedBundle​(org.osgi.framework.Bundle bundle,
                                   org.osgi.framework.BundleEvent event,
                                   java.lang.Object object)
        Specified by:
        modifiedBundle in interface org.osgi.util.tracker.BundleTrackerCustomizer
      • removedBundle

        public void removedBundle​(org.osgi.framework.Bundle bundle,
                                  org.osgi.framework.BundleEvent event,
                                  java.lang.Object object)
        Specified by:
        removedBundle in interface org.osgi.util.tracker.BundleTrackerCustomizer
      • createExtension

        private void createExtension​(org.osgi.framework.Bundle bundle)
      • destroyExtension

        private void destroyExtension​(org.osgi.framework.Bundle bundle)
      • doCreateExtension

        protected abstract Extension doCreateExtension​(org.osgi.framework.Bundle bundle)
                                                throws java.lang.Exception
        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:
        java.lang.Exception - If something goes wrong
      • debug

        protected abstract void debug​(org.osgi.framework.Bundle bundle,
                                      java.lang.String msg)
      • warn

        protected abstract void warn​(org.osgi.framework.Bundle bundle,
                                     java.lang.String msg,
                                     java.lang.Throwable t)
      • error

        protected abstract void error​(java.lang.String msg,
                                      java.lang.Throwable t)