Beispiel #1
1
  /**
   * Enables the bundle to run as a stand-alone application. When this static <tt>main()</tt> method
   * is invoked, the application creates its own embedded Felix framework instance and interacts
   * with the internal services to provide drawing functionality. To successfully launch as a
   * stand-alone application, this method should be invoked from the bundle's installation directory
   * using "<tt>java -jar</tt>".
   *
   * @param argv The command-line arguments.
   * @throws Exception If anything goes wrong.
   */
  public static void main(String[] argv) throws Exception {
    // Create a temporary bundle cache directory and
    // make sure to clean it up on exit.
    final File cachedir = File.createTempFile("felix.example.servicebased", null);
    cachedir.delete();
    Runtime.getRuntime()
        .addShutdownHook(
            new Thread() {
              public void run() {
                deleteFileOrDir(cachedir);
              }
            });

    Map configMap = new StringMap(false);
    configMap.put(
        Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA,
        "org.apache.felix.example.servicebased.host.service; version=1.0.0");
    configMap.put(
        AutoActivator.AUTO_START_PROP + ".1",
        "file:../servicebased.circle/target/servicebased.circle-1.0.0.jar "
            + "file:../servicebased.square/target/servicebased.square-1.0.0.jar "
            + "file:../servicebased.triangle/target/servicebased.triangle-1.0.0.jar");
    configMap.put(FelixConstants.LOG_LEVEL_PROP, "4");
    configMap.put(Constants.FRAMEWORK_STORAGE, cachedir.getAbsolutePath());

    // Create list to hold custom framework activators.
    List list = new ArrayList();
    // Add activator to process auto-start/install properties.
    list.add(new AutoActivator(configMap));
    // Add our own activator.
    list.add(new Activator());
    // Add our custom framework activators to the configuration map.
    configMap.put(FelixConstants.SYSTEMBUNDLE_ACTIVATORS_PROP, list);

    try {
      // Now create an instance of the framework.
      Felix felix = new Felix(configMap);
      felix.start();
    } catch (Exception ex) {
      System.err.println("Could not create framework: " + ex);
      ex.printStackTrace();
      System.exit(-1);
    }
  }
Beispiel #2
0
  /**
   * Runs "main" program loop until it gets killed or stopped by shutdown hook
   *
   * @param component XMPP component instance to run in this session(optional)
   * @param bundleConfig OSGi bundles configuration that describes the system
   */
  public void runMainProgramLoop(ComponentBase component, OSGiBundleConfig bundleConfig) {
    // Make sure that passwords are not printed by ConfigurationService
    // on startup by setting password regExpr and cmd line args list
    ConfigurationServiceImpl.PASSWORD_SYS_PROPS = "pass";
    ConfigurationServiceImpl.PASSWORD_CMD_LINE_ARGS = "secret,user_password";

    OSGi.setBundleConfig(bundleConfig);

    bundleConfig.setSystemPropertyDefaults();

    /*
     * Start OSGi. It will invoke the application programming interfaces
     * (APIs) of Jitsi Videobridge. Each of them will keep the application
     * alive.
     */
    BundleActivator activator =
        new BundleActivator() {
          @Override
          public void start(BundleContext bundleContext) throws Exception {
            registerShutdownService(bundleContext);

            // Log config properties(hide password values)
            ServiceUtils.getService(bundleContext, ConfigurationService.class)
                .logConfigurationProperties("(pass)|(secret)");
          }

          @Override
          public void stop(BundleContext bundleContext) throws Exception {
            // We're doing nothing
          }
        };

    // Register shutdown hook to perform cleanup before exit
    Runtime.getRuntime()
        .addShutdownHook(
            new Thread() {
              public void run() {
                synchronized (exitSyncRoot) {
                  exitSyncRoot.notifyAll();
                }
              }
            });

    // Start OSGi
    OSGi.start(activator);

    // FIXME: implement startComponent retries in case Prosody is not
    // available yet(currently we'll stop on the exception thrown by
    // startComponent)
    if (component == null || startComponent(component)) {
      try {
        synchronized (exitSyncRoot) {
          exitSyncRoot.wait();
        }
      } catch (Exception e) {
        logger.error(e, e);
      }
    }

    stopComponent();

    OSGi.stop(activator);
  }