Examples of FrameworkStartLevel


Examples of org.osgi.framework.startlevel.FrameworkStartLevel

        };
    }

    protected void awaitKarafBeginningStartLevel(final BundleContext syscontext, final Integer beginningStartLevel, long timeout, TimeUnit unit) {
        final CountDownLatch latch = new CountDownLatch(1);
        final FrameworkStartLevel fwrkStartLevel = syscontext.getBundle().adapt(FrameworkStartLevel.class);
        FrameworkListener listener = new FrameworkListener() {
            @Override
            public void frameworkEvent(FrameworkEvent event) {
                if (event.getType() == FrameworkEvent.STARTLEVEL_CHANGED) {
                    int startLevel = fwrkStartLevel.getStartLevel();
                    if (startLevel == beginningStartLevel) {
                        latch.countDown();
                    }
                }
            }
        };
        syscontext.addFrameworkListener(listener);
        try {
            int startLevel = fwrkStartLevel.getStartLevel();
            if (startLevel < beginningStartLevel) {
                try {
                    if (!latch.await(timeout, unit))
                        throw new IllegalStateException("Giving up waiting to reach start level: " + beginningStartLevel);
                } catch (InterruptedException e) {
View Full Code Here

Examples of org.osgi.framework.startlevel.FrameworkStartLevel

       
        bundle.start();      
       
        Thread.sleep(2000);
       
        FrameworkStartLevel sl = framework.adapt(FrameworkStartLevel.class);
       
        MockLock lock = (MockLock) main.getLockManager().getLock();       

        Assert.assertEquals(100, sl.getStartLevel());      

        // simulate losing a lock
        lock.setIsAlive(false);
        lock.setLock(false);
       
        // lets wait until the start level change is complete
        lock.waitForLock();
        Assert.assertEquals(1, sl.getStartLevel());

        Thread.sleep(1000);
       
        // get lock back
        lock.setIsAlive(true);
View Full Code Here

Examples of org.osgi.framework.startlevel.FrameworkStartLevel

        framework = factory.newFramework(new StringMap(config.props, false));
        framework.init();
        framework.getBundleContext().addFrameworkListener(lockCallback);
        framework.start();

        FrameworkStartLevel sl = framework.adapt(FrameworkStartLevel.class);
        sl.setInitialBundleStartLevel(config.defaultBundleStartlevel);

        // If we have a clean state, install everything
        if (framework.getBundleContext().getBundles().length == 1) {

            LOG.info("Installing and starting initial bundles");
View Full Code Here

Examples of org.osgi.framework.startlevel.FrameworkStartLevel

        }

        determineBundleLevelThreshold();
       
        // Display active start level.
        FrameworkStartLevel fsl = getBundleContext().getBundle(0).adapt(FrameworkStartLevel.class);
        if (fsl != null) {
            System.out.println("START LEVEL " + fsl.getStartLevel() + " , List Threshold: " + bundleLevelThreshold);
        }

        if (!newLayout) {
        // Print column headers.
        System.out.println("   ID   State         Level " + getNameHeader());
View Full Code Here

Examples of org.osgi.framework.startlevel.FrameworkStartLevel

    @Test
    @Ignore
    public void testStartLevel() throws Exception {

        FrameworkStartLevel fwStartLevel = context.getBundle().adapt(FrameworkStartLevel.class);
        int initialStartLevel = fwStartLevel.getInitialBundleStartLevel();
        assertEquals("Initial bundle start level", 1, initialStartLevel);

        assertEquals("Bundle RESOLVED", Bundle.RESOLVED, bundle.getState());
        assertEquals("start-level-bundle", bundle.getSymbolicName());

        BundleStartLevel bStartLevel = bundle.adapt(BundleStartLevel.class);
        int bundleStartLevel = bStartLevel.getStartLevel();
        assertEquals("Bundle start level", 3, bundleStartLevel);

        try {
            bundle.start(Bundle.START_TRANSIENT);
            fail("Bundle cannot be started due to the Framework's current start level");
        } catch (BundleException ex) {
            // expected
        }
        assertEquals("Bundle RESOLVED", Bundle.RESOLVED, bundle.getState());

        // The bundle should not be started
        bundle.start();
        assertEquals("Bundle RESOLVED", Bundle.RESOLVED, bundle.getState());

        // Change the frameworkj start level and wait for the changed event
        final CountDownLatch latch = new CountDownLatch(1);
        context.addFrameworkListener(new FrameworkListener() {
            @Override
            public void frameworkEvent(FrameworkEvent event) {
                if (event.getType() == FrameworkEvent.STARTLEVEL_CHANGED)
                    latch.countDown();
            }
        });
        fwStartLevel.setStartLevel(3);
        latch.await(3, TimeUnit.SECONDS);

        // The bundle should now be started
        assertEquals("Bundle ACTIVE", Bundle.ACTIVE, bundle.getState());
View Full Code Here

Examples of org.osgi.framework.startlevel.FrameworkStartLevel

      logManager.configure();

      application = lookup(NxApplication.class);
      log.debug("Application: {}", application);

      FrameworkStartLevel fsl = bundleContext.getBundle(0).adapt(FrameworkStartLevel.class);

      // assign higher start level to hold back plugin activation
      fsl.setInitialBundleStartLevel(NEXUS_PLUGIN_START_LEVEL);

      installNexusFeatures();

      // raise framework start level to activate plugins
      fsl.setStartLevel(NEXUS_PLUGIN_START_LEVEL, this);
    }
    catch (final Exception e) {
      log.error("Failed to lookup application", e);
      Throwables.propagate(e);
    }
View Full Code Here

Examples of org.osgi.framework.startlevel.FrameworkStartLevel

            fileInstall.lock.readLock().unlock();
        }

        while (!interrupted()) {
            try {
                FrameworkStartLevel startLevelSvc = context.getBundle(0).adapt(FrameworkStartLevel.class);
                // Don't access the disk when the framework is still in a startup phase.
                if (startLevelSvc.getStartLevel() >= activeLevel
                        && context.getBundle(0).getState() == Bundle.ACTIVE) {
                    Set<File> files = scanner.scan(false);
                    // Check that there is a result.  If not, this means that the directory can not be listed,
                    // so it's presumably not a valid directory (it may have been deleted by someone).
                    // In such case, just sleep
View Full Code Here

Examples of org.osgi.framework.startlevel.FrameworkStartLevel

     * is set to true or when a bundle is persistently started. Persistently stopped bundles
     * are ignored.
     */
    private void startAllBundles()
    {
        FrameworkStartLevel startLevelSvc = context.getBundle(0).adapt(FrameworkStartLevel.class);
        List<Bundle> bundles = new ArrayList<Bundle>();
        for (Artifact artifact : getArtifacts()) {
            if (artifact.getBundleId() > 0) {
                Bundle bundle = context.getBundle(artifact.getBundleId());
                if (bundle != null) {
                    if (bundle.getState() != Bundle.STARTING && bundle.getState() != Bundle.ACTIVE
                            && (useStartTransient || bundle.adapt(BundleStartLevel.class).isPersistentlyStarted())
                            && startLevelSvc.getStartLevel() >= bundle.adapt(BundleStartLevel.class).getStartLevel()) {
                        bundles.add(bundle);
                    }
                }
            }
        }
View Full Code Here

Examples of org.osgi.framework.startlevel.FrameworkStartLevel

      * @param bundle the bundle to start.
      * @return whether the bundle was started.
      */
    private boolean startBundle(Bundle bundle)
    {
        FrameworkStartLevel startLevelSvc = context.getBundle(0).adapt(FrameworkStartLevel.class);
        // Fragments can never be started.
        // Bundles can only be started transient when the start level of the framework is high
        // enough. Persistent (i.e. non-transient) starts will simply make the framework start the
        // bundle when the start level is high enough.
        if (startBundles
                && bundle.getState() != Bundle.UNINSTALLED
                && !isFragment(bundle)
                && startLevelSvc.getStartLevel() >= bundle.adapt(BundleStartLevel.class).getStartLevel())
        {
            try
            {
                int options = useStartTransient ? Bundle.START_TRANSIENT : 0;
                options |= useStartActivationPolicy ? Bundle.START_ACTIVATION_POLICY : 0;
View Full Code Here

Examples of org.osgi.framework.startlevel.FrameworkStartLevel

    public static void awaitFrameworkBeginningStartLevel(BundleContext syscontext) {
        String beginningStartLevelProp = syscontext.getProperty(Constants.FRAMEWORK_BEGINNING_STARTLEVEL);
        if (beginningStartLevelProp != null) {
            final CountDownLatch latch = new CountDownLatch(1);
            final Integer beginningStartLevel = Integer.parseInt(beginningStartLevelProp);
            final FrameworkStartLevel fwrkStartLevel = syscontext.getBundle().adapt(FrameworkStartLevel.class);
            FrameworkListener listener = new FrameworkListener() {
                @Override
                public void frameworkEvent(FrameworkEvent event) {
                    if (event.getType() == FrameworkEvent.STARTLEVEL_CHANGED) {
                        int startLevel = fwrkStartLevel.getStartLevel();
                        if (startLevel == beginningStartLevel) {
                            latch.countDown();
                        }
                    }
                }
            };
            syscontext.addFrameworkListener(listener);
            try {
                int startLevel = fwrkStartLevel.getStartLevel();
                if (startLevel < beginningStartLevel) {
                    try {
                        if (!latch.await(30, TimeUnit.SECONDS))
                            throw new IllegalStateException("Giving up waiting to reach start level: " + beginningStartLevel);
                    } catch (InterruptedException e) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.