Search in sources :

Example 16 with Framework

use of org.osgi.framework.launch.Framework in project Payara by payara.

the class BundleProvisioner method main.

/**
 * A simple main method to test this class
 *
 * @param args
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
public static void main(String[] args) throws Exception {
    logger.log(INFO, STARTING_BUNDLEPROVISIONER);
    Properties props = new Properties();
    props.load(new FileInputStream(args[0]));
    Util.substVars(props);
    PrintStream out = new PrintStream(new FileOutputStream(args[1], true));
    long t0 = System.currentTimeMillis();
    Framework framework = null;
    for (FrameworkFactory frameworkFactory : ServiceLoader.load(FrameworkFactory.class)) {
        framework = frameworkFactory.newFramework((Hashtable) props);
        System.out.println("framework = " + framework);
        break;
    }
    if (framework == null) {
        throw new RuntimeException("no OSGi framework in classpath");
    }
    long t1 = System.currentTimeMillis();
    logger.log(Level.INFO, LogFacade.OSGI_LOCATE_TIME, (t1 - t0));
    framework.init();
    long t2 = System.currentTimeMillis();
    logger.log(Level.INFO, LogFacade.OSGI_INIT_TIME, (t2 - t1));
    BundleProvisioner bundleProvisioner = createBundleProvisioner(framework.getBundleContext(), props);
    bundleProvisioner.installBundles();
    long t3 = System.currentTimeMillis();
    logger.log(Level.INFO, LogFacade.BUNDLE_INSTALLATION_TIME, (t3 - t2));
    int installed = bundleProvisioner.getNoOfInstalledBundles();
    int updated = bundleProvisioner.getNoOfUpdatedBundles();
    int uninstalled = bundleProvisioner.getNoOfUninstalledBundles();
    System.out.printf("installed = %d, updated = %d, uninstalled = %d\n", installed, updated, uninstalled);
    if (bundleProvisioner.hasAnyThingChanged()) {
        System.out.println("Refreshing framework");
        bundleProvisioner.refresh();
    }
    bundleProvisioner.startBundles();
    framework.start();
    long t4 = System.currentTimeMillis();
    logger.log(Level.INFO, LogFacade.BUNDLE_STARTING_TIME, (t4 - t3));
    logger.log(Level.INFO, LogFacade.TOTAL_START_TIME, (t4 - t0));
    if (args.length == 3 && args[2].equalsIgnoreCase("wait-before-stopping")) {
        System.out.println("Hit enter to continue");
        // 
        System.in.read();
    }
    framework.stop();
    framework.waitForStop(0);
    long t5 = System.currentTimeMillis();
    logger.log(Level.INFO, LogFacade.BUNDLE_STOP_TIME, (t5 - t4));
    logger.log(Level.INFO, LogFacade.TOTAL_TIME, (t5 - t0));
    out.printf("%d,%d,%d,%d,%d,%d,%d\n", t1 - t0, t2 - t1, t3 - t2, t4 - t3, t4 - t0, t5 - t4, t5 - t0);
}
Also used : PrintStream(java.io.PrintStream) Hashtable(java.util.Hashtable) FileOutputStream(java.io.FileOutputStream) Properties(java.util.Properties) FileInputStream(java.io.FileInputStream) Framework(org.osgi.framework.launch.Framework) FrameworkFactory(org.osgi.framework.launch.FrameworkFactory)

Aggregations

Framework (org.osgi.framework.launch.Framework)16 FrameworkFactory (org.osgi.framework.launch.FrameworkFactory)9 File (java.io.File)8 HashMap (java.util.HashMap)5 IOException (java.io.IOException)4 Properties (java.util.Properties)4 Bundle (org.osgi.framework.Bundle)4 BundleContext (org.osgi.framework.BundleContext)4 BundleException (org.osgi.framework.BundleException)4 Test (org.junit.Test)3 FrameworkListener (org.osgi.framework.FrameworkListener)3 PojoServiceRegistryFactoryImpl (de.kalpatec.pojosr.framework.PojoServiceRegistryFactoryImpl)2 ClasspathScanner (de.kalpatec.pojosr.framework.launch.ClasspathScanner)2 FileInputStream (java.io.FileInputStream)2 FileOutputStream (java.io.FileOutputStream)2 OutputStream (java.io.OutputStream)2 LinkedHashMap (java.util.LinkedHashMap)2 LinkedHashSet (java.util.LinkedHashSet)2 FrameworkEvent (org.osgi.framework.FrameworkEvent)2 ResourceIndexer (org.osgi.service.indexer.ResourceIndexer)2