Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Wiki Markup
_\[This document describes APIframework launching introduced in Felix 12.40.0 and is incompatible with older versions of the Felix framework.\]_

...

Code Block
public static void main(String[] argvargs) throws Exception
{
    // (1) Check for proper command line arguments and verify usage.
    if (args.length > 1)String bundleDir = null;
    {
String cacheDir = null;
    boolean  System.out.println("Usage: [<bundle-cache-dir>]")expectBundleDir = false;
    for (int i = System.exit(0);
 i <  }

args.length; i++)
    // (2) Load system properties.
{
        if Main.loadSystemProperties();

(args[i].equals(BUNDLE_DIR_SWITCH))
    // (3) Read configuration properties.{
      Properties configProps      expectBundleDir = Main.loadConfigProperties()true;

      // (4) Copy}
 framework properties from the system properties.
  else if Main.copySystemProperties(configPropsexpectBundleDir);

    // (5) If specified, use{
 command-line argument as path to bundle cache.
    if (args.length > 0)bundleDir = args[i];
    {
        configProps.setProperty(Constants.FRAMEWORK_STORAGE, args[0])expectBundleDir = false;
    }

    // (6) Create a list for custom framework activators and
    // add an instance of the auto-activator it for processing
}
        else
        {
       // auto-install and auto-start properties. AddcacheDir this list= args[i];
    // to the configuration properties.}
    List}
  list = newif ArrayList();
    list.add(new AutoActivator(configProps));((args.length > 3) || (expectBundleDir && bundleDir == null))
    configProps.put(FelixConstants.SYSTEMBUNDLE_ACTIVATORS_PROP, list);

    // Print welcome banner.
{
        System.out.println("\nWelcome to Felix.Usage: [-b <bundle-deploy-dir>] [<bundle-cache-dir>]");
        System.out.println("=================\n");

    try
    {exit(0);
    }

    // (2) Load system properties.
    Main.loadSystemProperties();

    // (3) Read configuration properties.
    Properties configProps = Main.loadConfigProperties();
    if (configProps == null)
    {
        System.err.println("No " + CONFIG_PROPERTIES_FILE_VALUE + " found.");
        configProps = new Properties();
    }

    // (4) Copy framework properties from the system properties.
    Main.copySystemProperties(configProps);
        
    // (5) Use the specified auto-deploy directory over default.
    if (bundleDir != null)
    {
        configProps.setProperty(AutoProcessor.AUTO_DEPLOY_DIR_PROPERY, bundleDir);
    }

    // (6) Use the specified bundle cache directory over default.
    if (cacheDir != null)
    {
        configProps.setProperty(Constants.FRAMEWORK_STORAGE, cacheDir);
    }

    // (7) Add a shutdown hook to clean stop the framework.
    String enableHook = configProps.getProperty(SHUTDOWN_HOOK_PROP);
    if ((enableHook == null) || !enableHook.equalsIgnoreCase("false"))
    {
        Runtime.getRuntime().addShutdownHook(new Thread() {
            public void run()
            {
                try
                {
                    if (m_fwk != null)
                    {
                        m_fwk.stop();
                        m_fwk.waitForStop(0);
                    }
                }
                catch (Exception ex)
                {
                    System.err.println("Error stopping framework: " + ex);
                }
            }
        });
    }

    // Print welcome banner.
    System.out.println("\nWelcome to Felix");
    System.out.println("================\n");

    try
    {
        // (8) Create an instance and initialize the framework.
        FrameworkFactory factory = getFrameworkFactory();
        m_fwk = factory.newFramework(configProps);
        m_fwk.init();
        // (9) Use the system bundle context to process the auto-deploy
        // (7) Create an instance and auto-install/auto-start the frameworkproperties.

        AutoProcessor.process(configProps, m_felix = new Felix(configProps);fwk.getBundleContext());
        // (10) Start the framework.
        m_felixfwk.start();
        // (811) Wait for framework to stop to exit the VM.
        m_felixfwk.waitForStop(0);
        System.exit(0);
    }
    catch (Exception ex)
    {
        System.err.println("Could not create framework: " + ex);
        ex.printStackTrace();
        System.exit(-1);
    }
}

The general steps of the standard launcher are quite straightforward:

  1. The launcher only supports a single, optional command-line argument, which is the path to the bundle cachesupports setting the auto-deploy directory (with the -b switch) and setting the bundle cache path with a single argument, so check for this and issue a usage message it there are more than one arguments.
  2. Load any system properties specified in the system.properties file; this file is typically located in the conf/ directory of the Felix installation directory, but it can be specified directly using the felix.system.properties system property. This file is not needed to launch Felix and is provided merely for convenience when system properties must be specified. The file is a standard Java properties file, but it also supports property substitution using ${<property-name} syntax. Property substitution can be nested; only system properties will be used for substitution.
  3. Load any configuration properties specified in the config.properties file; this file is typically located in the conf/ directory of the Felix installation directory, but it can be specified directly using the felix.config.properties system property. This file is used to configure the Felix instance created by the launcher. The file is a standard Java properties file, but it also supports property substitution using "${<property-name}" syntax. Property substitution can be nested; configuration and system properties will be used for substitution with configuration properties having precedence.
  4. For convenience, any configuration properties that are set as system properties are copied into the set of configuration properties. This provide an easy way to add to or override configuration properties specified in the config.properties file, since the Felix instance will never look at system properties for configuration.
  5. If the -b switch was used to specify an auto-deploy directory, then use that to set the value of felix.auto.deploy.dir.
  6. If there is a single command-line argument is specified, then use that to set the value of org.osgi.framework.storage; relative paths are relative to the current directory unless the felix.cache.rootdir property is set.
  7. Create a framework instance using the FrameworkFactory passing in the configuration properties, then initialize the factory instance.
  8. Use list to hold custom framework activators and add an instance of org.apache.felix.main.AutoActivatorAutoProcessor, which will process automatically deploy any bundles in the auto-deploy directory as well as bundles specified in the felix.auto.install and felix.auto.start configuration properties during framework startup to automatically install and/or start bundles; see the usage document for more information configuration properties.Create the Felix instance passing in the configuration properties, then call start().
  9. Invoke waitForStop() to wait for the framework to stop to force the VM to exit; this is necessary because the framework never calls System.exit() and some libraries (e.g., Swing) create threads that will not allow the VM to exit.

...