Package org.osgi.framework.launch

Examples of org.osgi.framework.launch.Framework


        boot.setBuildDir(outputDirectory);
        boot.setCarFile(getArtifactInRepositoryDir());
        boot.setLocalRepo(repository);
        boot.setPlan(planFile);
        Framework framework = getFramework(",org.apache.geronimo.deployment,org.apache.geronimo.deployment.service");
        BundleContext bundleContext = framework.getBundleContext();
        boot.setBundleContext(bundleContext);

        // Generate expanded so we can use Maven to generate the archive
        boot.setExpanded(true);

        boot.bootstrap();

        framework.stop();
        getLog().debug("Waiting for shutdown (up to 5 minutes)...");
        framework.waitForStop(60 * 5 * 1000);
    }
View Full Code Here


        AbstractName deployer = locateDeployer(kernel);
        invokeDeployer(kernel, deployer, targetConfigStoreAName.toString());
        //use a fresh kernel for each module
        kernel.shutdown();
        kernel = null;
        Framework framework = (Framework) bundleContext.getBundle();
        framework.stop();
        getLog().debug("Waiting for shutdown (up to 5 minutes)...");
        framework.waitForStop(60 * 5 * 1000);
        bundleContext = null;
    }
View Full Code Here

        Map<String, String> configuration = new HashMap<String, String>();
        configuration.put(Constants.FRAMEWORK_STORAGE, "target/papoose");

        final FrameworkFactory factory = new PapooseFrameworkFactory();
        Framework framework = factory.newFramework(configuration);

        framework.init();

        Bundle systemBundle = framework.getBundleContext().getBundle(0);
        BundleContext context = systemBundle.getBundleContext();

        Bundle testBundle = context.installBundle(location);

        long testBundleId = testBundle.getBundleId();

        assertTrue(testBundleId > 0);

        try
        {
            framework.uninstall();
            fail("Should have thrown an exception");
        }
        catch (BundleException e)
        {
        }

        framework.stop();

        framework = factory.newFramework(configuration);
        framework.init();

        systemBundle = framework.getBundleContext().getBundle(0);
        context = systemBundle.getBundleContext();

        testBundle = context.getBundle(testBundleId);
        assertNotNull(testBundleId);

        framework.start();
        testBundle.start();

        assertEquals(Bundle.ACTIVE, framework.getState());
        assertEquals(Bundle.ACTIVE, testBundle.getState());

        testBundle.uninstall();

        Dictionary headers = testBundle.getHeaders("en");
        Assert.assertEquals("org.papoose.test-support.bundle", headers.get("Bundle-SymbOLicName"));

        headers = testBundle.getHeaders("en");
        Assert.assertEquals("bundle_en", headers.get("L10N-Bundle"));

        headers = testBundle.getHeaders();
        Assert.assertEquals("bundle_en", headers.get("L10N-Bundle"));

        headers = testBundle.getHeaders(null);
        Assert.assertEquals("bundle_en", headers.get("L10N-Bundle"));

        headers = testBundle.getHeaders("en_US");
        Assert.assertEquals("bundle_en", headers.get("L10N-Bundle"));

        headers = testBundle.getHeaders("fr");
        Assert.assertEquals("bundle_fr", headers.get("L10N-Bundle"));

        headers = testBundle.getHeaders("fr_FR");
        Assert.assertEquals("bundle_fr_FR", headers.get("L10N-Bundle"));

        headers = testBundle.getHeaders("");
        Assert.assertEquals("%bundle", headers.get("L10N-Bundle"));

        headers = testBundle.getHeaders("en");
        Assert.assertEquals("no translation for this entry", headers.get("L10N-NoTranslation"));

        try
        {
            testBundle.start();
            fail("Cannot start an uninstalled bundle");
        }
        catch (IllegalStateException e)
        {
        }

        testBundle = context.getBundle(testBundleId);
        assertNull(testBundle);

        framework.stop();

        framework.init();

        systemBundle = framework.getBundleContext().getBundle(0);
        context = systemBundle.getBundleContext();

        testBundle = context.getBundle(testBundleId);
        assertNull(testBundle);

        framework.stop();
    }
View Full Code Here

    {
        Map<String, String> configuration = new HashMap<String, String>();
        configuration.put(Constants.FRAMEWORK_STORAGE, "target/papoose");

        FrameworkFactory factory = new PapooseFrameworkFactory();
        final Framework framework = factory.newFramework(configuration);

        FrameworkEvent frameworkEvent = framework.waitForStop(0);

        assertNotNull(frameworkEvent);
        assertEquals(FrameworkEvent.STOPPED, frameworkEvent.getType());
        assertSame(framework, frameworkEvent.getBundle());

        framework.init();

        Bundle systemBundle = framework.getBundleContext().getBundle(0);

        assertEquals(Bundle.STARTING, framework.getState());
        assertEquals(Bundle.STARTING, systemBundle.getState());

        ThreadPoolExecutor pool = new ThreadPoolExecutor(1, 1, 60, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());

        try
        {
            Future<FrameworkEvent> result = pool.submit(new Callable<FrameworkEvent>()
            {
                public FrameworkEvent call() throws Exception
                {
                    return framework.waitForStop(0);
                }
            });

            framework.stop();

            frameworkEvent = result.get();

            assertNotNull(frameworkEvent);
            assertEquals(FrameworkEvent.STOPPED, frameworkEvent.getType());
            assertSame(systemBundle, frameworkEvent.getBundle());

            framework.waitForStop(0);
        }
        finally
        {
            pool.shutdown();
        }

        try
        {
            framework.waitForStop(-1);
            Assert.fail("Should never accept negative wait timeouts");
        }
        catch (IllegalArgumentException iae)
        {
        }

        frameworkEvent = framework.waitForStop(Long.MAX_VALUE);

        assertNotNull(frameworkEvent);
        assertEquals(FrameworkEvent.STOPPED, frameworkEvent.getType());
        assertSame(systemBundle, frameworkEvent.getBundle());

        framework.start();

        framework.stop();

        Thread.sleep(1);

        frameworkEvent = framework.waitForStop(0);

        assertNotNull(frameworkEvent);
        assertEquals(FrameworkEvent.STOPPED, frameworkEvent.getType());
        assertSame(systemBundle, frameworkEvent.getBundle());
    }
View Full Code Here

        else
        {
            papoose = new Papoose(store, executorService, properties);
        }

        Framework framework = new PapooseFramework(papoose);

        LOGGER.exiting(CLASS_NAME, "newFramework", framework);

        return framework;
    }
View Full Code Here

        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 f = null;
        for (FrameworkFactory ff : ServiceLoader.load(FrameworkFactory.class)) {
            f = ff.newFramework(props);
            System.out.println("framework = " + f);
            break;
        }
        if (f == null) {
            throw new RuntimeException("no OSGi framework in classpath");
        }
        long t1 = System.currentTimeMillis();
        logger.log(Level.INFO, LogFacade.OSGI_LOCATE_TIME, (t1-t0));
        f.init();
        long t2 = System.currentTimeMillis();
        logger.log(Level.INFO, LogFacade.OSGI_INIT_TIME, (t2-t1));
        BundleProvisioner bundleProvisioner = createBundleProvisioner(f.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();
        f.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(); //
        }
        f.stop();
        f.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);
    }
View Full Code Here

        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 f = null;
        for (FrameworkFactory ff : ServiceLoader.load(FrameworkFactory.class)) {
            f = ff.newFramework(props);
            System.out.println("framework = " + f);
            break;
        }
        if (f == null) {
            throw new RuntimeException("no OSGi framework in classpath");
        }
        long t1 = System.currentTimeMillis();
        logger.logp(Level.INFO, "BundleProvisioner", "main", "timeTaken to locate OSGi framework = {0} ms",
                new Object[]{t1 - t0});
        f.init();
        long t2 = System.currentTimeMillis();
        logger.logp(Level.INFO, "BundleProvisioner", "main", "timeTaken to initialize OSGi framework = {0} ms",
                new Object[]{t2 - t1});
        BundleProvisioner bundleProvisioner = new BundleProvisioner(f.getBundleContext(), props);
        bundleProvisioner.installBundles();
        long t3 = System.currentTimeMillis();
        logger.logp(Level.INFO, "BundleProvisioner", "main", "timeTaken to finish installation of bundles = {0} ms",
                new Object[]{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();
        f.start();
        long t4 = System.currentTimeMillis();
        logger.logp(Level.INFO, "BundleProvisioner", "main", "time taken to finish starting bundles = {0} ms",
                new Object[]{t4 - t3});
        logger.logp(Level.INFO, "BundleProvisioner", "main", "total time taken to start = {0}", new Object[]{t4-t0});
        if (args.length == 3 && args[2].equalsIgnoreCase("wait-before-stopping")) {
            System.out.println("Hit enter to continue");
            System.in.read(); //
        }
        f.stop();
        f.waitForStop(0);
        long t5 = System.currentTimeMillis();
        logger.logp(Level.INFO, "BundleProvisioner", "main", "time taken to stop = {0} ms", new Object[]{t5 - t4});
        logger.logp(Level.INFO, "BundleProvisioner", "main", "Total time taken = {0}", new Object[]{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);
    }
View Full Code Here

    };

    public void start(BundleContext context) throws Exception {
        this.context = context;
        if (nonEmbedded()) {
            Framework framework = (Framework) context.getBundle(0);
            gfr = new OSGiGlassFishRuntime(framework);
            context.registerService(GlassFishRuntime.class.getName(), gfr, null);
        } else {
            Properties properties = prepareStartupContext(context);
            final BootstrapProperties bsProperties = new BootstrapProperties(properties);
View Full Code Here

        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 f = null;
        for (FrameworkFactory ff : ServiceLoader.load(FrameworkFactory.class)) {
            f = ff.newFramework(props);
            System.out.println("framework = " + f);
            break;
        }
        if (f == null) {
            throw new RuntimeException("no OSGi framework in classpath");
        }
        long t1 = System.currentTimeMillis();
        logger.log(Level.INFO, LogFacade.OSGI_LOCATE_TIME, (t1-t0));
        f.init();
        long t2 = System.currentTimeMillis();
        logger.log(Level.INFO, LogFacade.OSGI_INIT_TIME, (t2-t1));
        BundleProvisioner bundleProvisioner = createBundleProvisioner(f.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();
        f.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(); //
        }
        f.stop();
        f.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);
    }
View Full Code Here

         * That will result in ClassCastException.
         */
        resetFrameworkProperties();

        ServiceLoader<FrameworkFactory> loader = ServiceLoader.load(FrameworkFactory.class);
        Framework framework = loader.iterator().next().newFramework(properties);
        framework.start();
        //enable mvn url handling
//        new org.ops4j.pax.url.mvn.internal.Activator().start(framework.getBundleContext());
        //don't allow mvn urls
        System.setProperty("geronimo.build.car", "true");

View Full Code Here

TOP

Related Classes of org.osgi.framework.launch.Framework

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.