Package org.osgi.framework.launch

Examples of org.osgi.framework.launch.Framework


    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

            + "Bundle-Version: 1.1.0\n"
            + "Bundle-ManifestVersion: 2\n"
            + "Export-Package: boot.test";
        File bundle = createBundle(mf);

        Framework f = new Felix(params);
        f.init();
        f.getBundleContext().installBundle(bundle.toURI().toString());
        f.start();

        Bundle[] arr = f.getBundleContext().getBundles();
        assertEquals("Two, system and mine: " + Arrays.toString(arr), 2, arr.length);
        Class c = arr[1].loadClass("boot.test.Test");
        assertNotNull("Class loaded", c);
        assertEquals("One query", 1, queriedFor.size());
        assertEquals("Queried for my bundle", arr[1], queriedFor.get(0));
View Full Code Here

            + "Manifest-Version: 1.0\n"
            + Constants.BUNDLE_ACTIVATOR + ": " + TestURLHandlersActivator.class.getName() + "\n\n";

        File bundleFile = createBundle(mf, TestURLHandlersActivator.class);

        Framework f = createFramework();
        f.init();
        f.start();

        try
        {
            final Bundle bundle = f.getBundleContext().installBundle(bundleFile.toURI().toString());
            bundle.start();
        }
        finally
        {
            try
            {
                f.stop();
            }
            catch (Throwable t)
            {
            }
        }
View Full Code Here

    public void testURLHandlersWithClassLoaderIsolation() throws Exception
    {
        DelegatingClassLoader cl1 = new DelegatingClassLoader(this.getClass().getClassLoader());
        DelegatingClassLoader cl2 = new DelegatingClassLoader(this.getClass().getClassLoader());

        Framework f = createFramework();
        f.init();
        f.start();

        String mf = "Bundle-SymbolicName: url.test\n"
            + "Bundle-Version: 1.0.0\n"
            + "Bundle-ManifestVersion: 2\n"
            + "Import-Package: org.osgi.framework\n"
            + "Manifest-Version: 1.0\n"
            + Constants.BUNDLE_ACTIVATOR + ": " + TestURLHandlersActivator.class.getName();

        File bundleFile = createBundle(mf, TestURLHandlersActivator.class);

        final Bundle bundle = f.getBundleContext().installBundle(bundleFile.toURI().toString());
        bundle.start();

        Class clazz1 = cl1.loadClass(URLHandlersTest.class.getName());

        clazz1.getMethod("testURLHandlers").invoke(clazz1.newInstance());

        bundle.stop();
        bundle.start();
        Class clazz2 = cl2.loadClass(URLHandlersTest.class.getName());

        clazz2.getMethod("testURLHandlers").invoke(clazz2.newInstance());
        bundle.stop();
        bundle.start();
        f.stop();
    }
View Full Code Here

            + "Bundle-Version: 1.1.0\n"
            + "Bundle-ManifestVersion: 2\n"
            + "Import-Package: org.osgi.framework\n";
        File bundleFile = createBundle(mf, cacheDir);

        Framework f = new Felix(params);
        f.init();
        f.start();

        try {
            final Bundle bundle = f.getBundleContext().installBundle(bundleFile.toURI().toString());

            new Thread()
            {
                public void run()
                {
                    try
                    {
                        bundle.start();
                    }
                    catch (BundleException e)
                    {
                        e.printStackTrace();
                    }
                }
            }.start();
            Thread.sleep(DELAY / 4);
            long t0 = System.currentTimeMillis();
            bundle.stop();
            long t1 = System.currentTimeMillis();

            assertEquals(Bundle.RESOLVED, bundle.getState());
            assertTrue((t1 - t0) > DELAY / 2);

            bundle.start();

            new Thread()
            {
                public void run()
                {
                    try
                    {
                        bundle.stop();
                    }
                    catch (BundleException e)
                    {
                        e.printStackTrace();
                    }
                }
            }.start();
            Thread.sleep(DELAY / 4);
            t0 = System.currentTimeMillis();
            bundle.start();
            t1 = System.currentTimeMillis();

            assertEquals(Bundle.ACTIVE, bundle.getState());
            assertTrue((t1 - t0) > DELAY / 2);
        } finally {
            f.stop();
            Thread.sleep(DELAY);
            deleteDir(cacheDir);
        }
    }
View Full Code Here

        ServiceEvent event = new ServiceEvent(ServiceEvent.REGISTERED, sr);

        assertEquals("Precondition failed", 0, fired.size());

        Framework framework = EasyMock.createNiceMock(Framework.class);
        EasyMock.replay(new Object[]
            {
                framework
            });
View Full Code Here

        try {

            // initiate startup handler
            final StartupManager startupManager = new StartupManager(props, logger);

            Framework tmpFramework = createFramework(notifiable, logger, props);
            init(tmpFramework);

            final boolean restart = new BootstrapInstaller(tmpFramework.getBundleContext(), logger,
                    resourceProvider, startupManager.getMode()).install();
            startupManager.markInstalled();

            if (restart) {
                restart(tmpFramework);
                tmpFramework = createFramework(notifiable, logger, props);
                init(tmpFramework);
            }

            new DefaultStartupHandler(tmpFramework.getBundleContext(), logger, startupManager);

            // finally start
            tmpFramework.start();

            // only assign field if start succeeds
            this.framework = tmpFramework;
        } catch (final BundleException be) {
            throw be;
View Full Code Here

     * delegatee servlet if one is set at all.
     */
    public final void destroy() {
        if (framework != null) {
            // get a private copy of the reference and remove the class ref
            Framework myFramework;
            synchronized (this) {
                myFramework = framework;
                framework = null;
            }

            // shutdown the Felix container
            if (myFramework != null) {
                logger.log(Logger.LOG_INFO, "Shutting down Apache Sling");
                try {

                    myFramework.stop();
                    myFramework.waitForStop(0);

                } catch (BundleException be) {

                    // may be thrown by stop, log but continue
                    logger.log(Logger.LOG_ERROR,
View Full Code Here

    for (int i = 0; i < allBundles.length; i++) {
      if (!(allBundles[i] instanceof CompositeBundle))
        continue;
      CompositeBundle composite = (CompositeBundle) allBundles[i];
      try {
        Framework child = composite.getCompositeFramework();
        child.stop();
        // need to wait for each child to stop
        child.waitForStop(30000);
        // TODO need to figure out a way to invalid the child
      } catch (Throwable t) {
        // TODO consider logging
        t.printStackTrace();
      }
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.