Search in sources :

Example 1 with BundleState

use of org.apache.karaf.bundle.core.BundleState in project karaf by apache.

the class SpringStateService method getState.

public BundleState getState(Bundle bundle) {
    OsgiBundleApplicationContextEvent event = states.get(bundle.getBundleId());
    BundleState state = mapEventToState(event);
    return (bundle.getState() != Bundle.ACTIVE) ? BundleState.Unknown : state;
}
Also used : OsgiBundleApplicationContextEvent(org.springframework.osgi.context.event.OsgiBundleApplicationContextEvent) BundleState(org.apache.karaf.bundle.core.BundleState)

Example 2 with BundleState

use of org.apache.karaf.bundle.core.BundleState in project karaf by apache.

the class SpringStateService method onOsgiApplicationEvent.

public void onOsgiApplicationEvent(OsgiBundleApplicationContextEvent event) {
    if (LOG.isDebugEnabled()) {
        BundleState state = mapEventToState(event);
        LOG.debug("Spring app state changed to " + state + " for bundle " + event.getBundle().getBundleId());
    }
    states.put(event.getBundle().getBundleId(), event);
}
Also used : BundleState(org.apache.karaf.bundle.core.BundleState)

Example 3 with BundleState

use of org.apache.karaf.bundle.core.BundleState in project karaf by apache.

the class BlueprintStateService method blueprintEvent.

@Override
public void blueprintEvent(BlueprintEvent blueprintEvent) {
    if (LOG.isDebugEnabled()) {
        BundleState state = getState(blueprintEvent);
        LOG.debug("Blueprint app state changed to " + state + " for bundle " + blueprintEvent.getBundle().getBundleId());
    }
    states.put(blueprintEvent.getBundle().getBundleId(), blueprintEvent);
}
Also used : BundleState(org.apache.karaf.bundle.core.BundleState)

Example 4 with BundleState

use of org.apache.karaf.bundle.core.BundleState in project karaf by apache.

the class BlueprintStateService method getState.

@Override
public BundleState getState(Bundle bundle) {
    BlueprintEvent event = states.get(bundle.getBundleId());
    BundleState state = getState(event);
    return (bundle.getState() != Bundle.ACTIVE) ? BundleState.Unknown : state;
}
Also used : BundleState(org.apache.karaf.bundle.core.BundleState) BlueprintEvent(org.osgi.service.blueprint.container.BlueprintEvent)

Example 5 with BundleState

use of org.apache.karaf.bundle.core.BundleState in project karaf by apache.

the class JavaSecurityTest method testJavaSecurity.

@Test
public void testJavaSecurity() throws Exception {
    assertNotNull("Karaf should run under a security manager", System.getSecurityManager());
    BundleService service = getOsgiService(BundleService.class);
    long tried = 0;
    while (true) {
        Map<Bundle, BundleState> incorrect = new HashMap<>();
        for (Bundle bundle : bundleContext.getBundles()) {
            BundleInfo info = service.getInfo(bundle);
            BundleState state = info.getState();
            if (state != BundleState.Active && state != BundleState.Resolved) {
                incorrect.put(bundle, state);
            }
        }
        if (incorrect.isEmpty()) {
            break;
        } else {
            if (++tried >= 10) {
                fail("Unable to start bundles correctly: " + incorrect);
            }
            Thread.sleep(100);
        }
    }
}
Also used : BundleInfo(org.apache.karaf.bundle.core.BundleInfo) Bundle(org.osgi.framework.Bundle) BundleState(org.apache.karaf.bundle.core.BundleState) BundleService(org.apache.karaf.bundle.core.BundleService) Test(org.junit.Test)

Aggregations

BundleState (org.apache.karaf.bundle.core.BundleState)7 Bundle (org.osgi.framework.Bundle)3 BundleInfo (org.apache.karaf.bundle.core.BundleInfo)2 BundleService (org.apache.karaf.bundle.core.BundleService)2 BundleStateService (org.apache.karaf.bundle.core.BundleStateService)1 BundleInfo (org.apache.karaf.features.BundleInfo)1 Feature (org.apache.karaf.features.Feature)1 Test (org.junit.Test)1 BundleRevision (org.osgi.framework.wiring.BundleRevision)1 BlueprintEvent (org.osgi.service.blueprint.container.BlueprintEvent)1 OsgiBundleApplicationContextEvent (org.springframework.osgi.context.event.OsgiBundleApplicationContextEvent)1