Package org.osgi.framework.launch

Examples of org.osgi.framework.launch.Framework


   public void start() throws LifecycleException
   {
      try
      {
         Framework framework = frameworkInst.get();
         framework.start();
         bundleContextInst.set(framework.getBundleContext());
        
         Bundle[] bundles = framework.getBundleContext().getBundles();
         if (getInstalledBundle(bundles, "osgi.cmpn") == null)
            installBundle("org.osgi.compendium", false);
        
         if (getInstalledBundle(bundles, "arquillian-protocol-jmx-osgi-bundle") == null)
            installBundle("arquillian-protocol-jmx-osgi-bundle", true);
View Full Code Here


   public void stop() throws LifecycleException
   {
      try
      {
         Framework framework = frameworkInst.get();
         framework.stop();
         framework.waitForStop(3000);
      }
      catch (RuntimeException rte)
      {
         throw rte;
      }
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 = createBundleProvisioner(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

    System.setProperty("karaf.maven.convert", "false");

    Main main = new Main(args);
    main.launch();
    Thread.sleep(1000);
    Framework framework = main.getFramework();
    Bundle[] bundles = framework.getBundleContext().getBundles();
    Assert.assertEquals(3, bundles.length);
    Assert.assertEquals(fileMVNbundle, bundles[1].getLocation());
    Assert.assertEquals(mvnUrl, bundles[2].getLocation());
    Assert.assertEquals(Bundle.ACTIVE, bundles[1].getState());
    Assert.assertEquals(Bundle.ACTIVE, bundles[2].getState());
View Full Code Here


        Main main = new Main(args);
        main.launch();
        Thread.sleep(1000);
        Framework framework = main.getFramework();
        String activatorName = TimeoutShutdownActivator.class.getName().replace('.', '/') + ".class";
        Bundle bundle = framework.getBundleContext().installBundle("foo",
                TinyBundles.newBundle()
                    .set( Constants.BUNDLE_ACTIVATOR, TimeoutShutdownActivator.class.getName() )
                    .add( activatorName, getClass().getClassLoader().getResourceAsStream( activatorName ) )
                    .build( withBnd() )
        );
View Full Code Here

        return karaf.getFramework();
    }

    @Override
    protected BundleContext startFramework() throws BundleException {
        Framework framework = karaf.getFramework();
        return framework.getBundleContext();
    }
View Full Code Here

        mbeanServerInst.set(mbeanServer);
    }

    public void start() throws LifecycleException {
        try {
            Framework framework = frameworkInst.get();
            framework.start();
            bundleContextInst.set(framework.getBundleContext());

            Bundle[] bundles = framework.getBundleContext().getBundles();
            if (getInstalledBundle(bundles, "arquillian-osgi-bundle") == null) {
                // Note, the bundle does not have an ImplementationVersion, we use the one of the container.
                String arqVersion = EmbeddedDeployableContainer.class.getPackage().getImplementationVersion();
                installBundle("org.jboss.arquillian.osgi", "arquillian-osgi-bundle", arqVersion, true);
            }
View Full Code Here

        }
    }

    public void stop() throws LifecycleException {
        try {
            Framework framework = frameworkInst.get();
            framework.stop();
            framework.waitForStop(3000);
        } catch (RuntimeException rte) {
            throw rte;
        } catch (Exception ex) {
            throw new LifecycleException("Cannot stop embedded OSGi Framework", ex);
        }
View Full Code Here

        properties.setProperty("org.osgi.framework.system.packages.extra", "org.apache.karaf.jaas.boot;version=\"2.4.0.SNAPSHOT\",org.apache.karaf.jaas.boot.principal;version=\"2.4.0.SNAPSHOT\",org.apache.karaf.management.boot;version=\"2.4.0.SNAPSHOT\"");
        properties.setProperty("org.osgi.framework.system.capabilities.extra",
                        "osgi.service;effective:=active;objectClass=org.osgi.service.packageadmin.PackageAdmin," +
                        "osgi.service;effective:=active;objectClass=org.osgi.service.startlevel.StartLevel," +
                        "osgi.service;effective:=active;objectClass=org.osgi.service.url.URLHandlers");
        Framework felix = new Felix(properties);
        Collection<Resource> resources = builder.resolve(felix.adapt(BundleRevision.class), false);

        for (Resource resource : resources) {
            System.out.println("Resource: " + getUri(resource));
        }
View Full Code Here

        return karaf.getFramework();
    }

    @Override
    protected BundleContext startFramework() throws BundleException {
        Framework framework = karaf.getFramework();
        return framework.getBundleContext();
    }
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.