Class StartLevelRuntimeHandler

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    public class StartLevelRuntimeHandler
    extends java.lang.Object
    implements java.io.Closeable
    Support to handle start levels in a launcher. This code is related to code in the Project Launcher. It is in aQute.lib so it can be included easily in the Launcher, the Remote launcher, and Launchpad.

    This class is not threadsafe!

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String LAUNCH_RUNBUNDLES_ATTRS  
      static java.lang.String LAUNCH_STARTLEVEL_DEFAULT
      If this property is set we take on start levels, if this property is not set we ignore the startlevels completely.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static StartLevelRuntimeHandler absent()  
      void afterStart()
      Called after the framework is started and the launcher is ready
      void beforeStart​(org.osgi.framework.launch.Framework systemBundle)
      Must be called before the framework is started.
      void close()
      Close this object
      static StartLevelRuntimeHandler create​(Trace logger, java.util.Map<java.lang.String,​java.lang.String> outerConfiguration)
      Create a start level handler.
      static StartLevelRuntimeHandler create​(Trace reporter, java.util.Properties properties)  
      int getBundleStartLevel​(org.osgi.framework.Bundle bundle)
      Get a bundle's start level
      int getFrameworkStartLevel​(org.osgi.framework.launch.Framework framework)
      Answer the current framework start level
      boolean hasStartLevels()
      Indicate if this class supports start levels or not.
      void setBundleStartLevel​(org.osgi.framework.Bundle bundle, int startlevel)
      Set a bundle's start level
      void setDefaultStartlevel​(org.osgi.framework.launch.Framework framework, int level)
      Set the default start level of newly installed bundles
      int setFrameworkStartLevel​(org.osgi.framework.launch.Framework framework, int startlevel, org.osgi.framework.FrameworkListener... ls)
      Set the framework start level and return previous
      void setStartLevel​(org.osgi.framework.Bundle b)
      Set the start level of a bundle
      void sync()
      Wait for the framework to reach its start level.
      (package private) static int toInt​(java.lang.Object object, int defltValue)  
      void updateConfiguration​(java.util.Map<java.lang.String,​?> configuration)
      When the configuration properties have been updated
      • Methods inherited from class java.lang.Object

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

      • LAUNCH_STARTLEVEL_DEFAULT

        public static java.lang.String LAUNCH_STARTLEVEL_DEFAULT
        If this property is set we take on start levels, if this property is not set we ignore the startlevels completely. This is defined in aQute.bnd.osgi.Constants
      • LAUNCH_RUNBUNDLES_ATTRS

        public static java.lang.String LAUNCH_RUNBUNDLES_ATTRS
    • Constructor Detail

      • StartLevelRuntimeHandler

        public StartLevelRuntimeHandler()
    • Method Detail

      • hasStartLevels

        public boolean hasStartLevels()
        Indicate if this class supports start levels or not.
        Returns:
        true if this class supports startlevels
      • setStartLevel

        public void setStartLevel​(org.osgi.framework.Bundle b)
        Set the start level of a bundle
        Parameters:
        b - the bundle
      • getFrameworkStartLevel

        public int getFrameworkStartLevel​(org.osgi.framework.launch.Framework framework)
        Answer the current framework start level
        Parameters:
        framework - the framework
        Returns:
        the current start level of the framework
      • setDefaultStartlevel

        public void setDefaultStartlevel​(org.osgi.framework.launch.Framework framework,
                                         int level)
        Set the default start level of newly installed bundles
        Parameters:
        framework - the framework
        level - the default start level
      • setFrameworkStartLevel

        public int setFrameworkStartLevel​(org.osgi.framework.launch.Framework framework,
                                          int startlevel,
                                          org.osgi.framework.FrameworkListener... ls)
        Set the framework start level and return previous
        Parameters:
        framework - the framework
        startlevel - the start level to set
        ls - listeners
        Returns:
        the previous start level of the framework
      • getBundleStartLevel

        public int getBundleStartLevel​(org.osgi.framework.Bundle bundle)
        Get a bundle's start level
        Parameters:
        bundle - the bundle to query
        Returns:
        the start level > 0
      • setBundleStartLevel

        public void setBundleStartLevel​(org.osgi.framework.Bundle bundle,
                                        int startlevel)
        Set a bundle's start level
        Parameters:
        bundle - the bundle to query
        startlevel - start level to set, > 0
      • beforeStart

        public void beforeStart​(org.osgi.framework.launch.Framework systemBundle)
        Must be called before the framework is started.

        ensure systemBundle.getState() == INIT and startlevel systemBundle == 0

        Parameters:
        systemBundle - the framework
      • updateConfiguration

        public void updateConfiguration​(java.util.Map<java.lang.String,​?> configuration)
        When the configuration properties have been updated
        Parameters:
        configuration - the configuration properties
      • afterStart

        public void afterStart()
        Called after the framework is started and the launcher is ready
      • sync

        public void sync()
        Wait for the framework to reach its start level. Must be called after the afterStart() method. Will return when the framework has traversed all start levels.
      • close

        public void close()
        Close this object
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
      • create

        public static StartLevelRuntimeHandler create​(Trace logger,
                                                      java.util.Map<java.lang.String,​java.lang.String> outerConfiguration)
        Create a start level handler. If the LAUNCH_STARTLEVEL_DEFAULT property is set we create an active handler that will direct the framework properly according to the settings in Project Launcher. If not set, a dummy is returned that does not do anything
        Parameters:
        outerConfiguration - the properties as set by the Project Launcher
        Returns:
        an active or dummy StartLevelRuntimeHandler
      • toInt

        static int toInt​(java.lang.Object object,
                         int defltValue)