Search in sources :

Example 1 with FrameworkEvent

use of org.osgi.framework.FrameworkEvent in project aries by apache.

the class Aries1429Test method testMissingParentChildEdgeTolerated.

@Test
public void testMissingParentChildEdgeTolerated() throws Exception {
    final AtomicBoolean weavingHookCalled = new AtomicBoolean();
    final AtomicReference<FrameworkEvent> frameworkEvent = new AtomicReference<FrameworkEvent>();
    bundleContext.registerService(WeavingHook.class, new WeavingHook() {

        @Override
        public void weave(WovenClass wovenClass) {
            Bundle bundle = wovenClass.getBundleWiring().getBundle();
            if (BUNDLE_A.equals(bundle.getSymbolicName())) {
                wovenClass.getDynamicImports().add("com.acme.tnt");
                weavingHookCalled.set(true);
            }
        }
    }, null);
    Subsystem applicationA = installSubsystemFromFile(APPLICATION_A);
    try {
        removeConnectionWithParent(applicationA);
        BundleContext context = applicationA.getBundleContext();
        Bundle bundleA = context.installBundle(BUNDLE_A, TinyBundles.bundle().add(getClass().getClassLoader().loadClass("a.A"), InnerClassStrategy.NONE).set(Constants.BUNDLE_SYMBOLICNAME, BUNDLE_A).build(TinyBundles.withBnd()));
        bundleContext.addFrameworkListener(new FrameworkListener() {

            @Override
            public void frameworkEvent(FrameworkEvent event) {
                if (FrameworkEvent.ERROR == event.getType() && getSubsystemCoreBundle().equals(event.getBundle())) {
                    frameworkEvent.set(event);
                    if (event.getThrowable() != null) {
                        event.getThrowable().printStackTrace();
                    }
                }
            }
        });
        bundleA.loadClass("a.A");
        assertTrue("Weaving hook not called", weavingHookCalled.get());
        Thread.sleep(1000);
        assertNull("An exception was thrown", frameworkEvent.get());
    } finally {
        uninstallSubsystemSilently(applicationA);
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) FrameworkEvent(org.osgi.framework.FrameworkEvent) Bundle(org.osgi.framework.Bundle) AriesSubsystem(org.apache.aries.subsystem.AriesSubsystem) Subsystem(org.osgi.service.subsystem.Subsystem) WovenClass(org.osgi.framework.hooks.weaving.WovenClass) AtomicReference(java.util.concurrent.atomic.AtomicReference) FrameworkListener(org.osgi.framework.FrameworkListener) WeavingHook(org.osgi.framework.hooks.weaving.WeavingHook) BundleContext(org.osgi.framework.BundleContext) SubsystemTest(org.apache.aries.subsystem.itests.SubsystemTest) Test(org.junit.Test)

Example 2 with FrameworkEvent

use of org.osgi.framework.FrameworkEvent in project aries by apache.

the class SubsystemTest method assertRefresh.

protected void assertRefresh(Collection<Bundle> bundles) throws InterruptedException {
    FrameworkWiring wiring = getSystemBundleAsFrameworkWiring();
    final AtomicBoolean refreshed = new AtomicBoolean(false);
    wiring.refreshBundles(bundles, new FrameworkListener[] { new FrameworkListener() {

        @Override
        public void frameworkEvent(FrameworkEvent event) {
            if (FrameworkEvent.PACKAGES_REFRESHED == event.getType()) {
                synchronized (refreshed) {
                    refreshed.set(true);
                    refreshed.notify();
                }
            }
        }
    } });
    synchronized (refreshed) {
        refreshed.wait(5000);
    }
    assertTrue("Bundles not refreshed", refreshed.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) FrameworkEvent(org.osgi.framework.FrameworkEvent) FrameworkWiring(org.osgi.framework.wiring.FrameworkWiring) FrameworkListener(org.osgi.framework.FrameworkListener)

Example 3 with FrameworkEvent

use of org.osgi.framework.FrameworkEvent in project karaf by apache.

the class Main method destroy.

public boolean destroy() throws Exception {
    if (framework == null) {
        return true;
    }
    try {
        int timeout = config.shutdownTimeout;
        if (config.shutdownTimeout <= 0) {
            timeout = Integer.MAX_VALUE;
        }
        if (shutdownCallback != null) {
            shutdownCallback.waitingForShutdown(timeout);
        }
        exiting = true;
        if (framework.getState() == Bundle.ACTIVE || framework.getState() == Bundle.STARTING) {
            new Thread(() -> {
                try {
                    framework.stop();
                } catch (BundleException e) {
                    System.err.println("Error stopping karaf: " + e.getMessage());
                }
            }).start();
        }
        int step = 5000;
        while (timeout > 0) {
            timeout -= step;
            FrameworkEvent event = framework.waitForStop(step);
            if (event.getType() != FrameworkEvent.WAIT_TIMEDOUT) {
                if (activatorManager != null) {
                    activatorManager.stopKarafActivators();
                }
                return true;
            }
        }
        return false;
    } finally {
        if (lock != null) {
            exiting = true;
            lock.release();
        }
    }
}
Also used : FrameworkEvent(org.osgi.framework.FrameworkEvent) BundleException(org.osgi.framework.BundleException)

Example 4 with FrameworkEvent

use of org.osgi.framework.FrameworkEvent in project sling by apache.

the class LogSupportTest method testFrameworkEventStarted.

@Test
public void testFrameworkEventStarted() throws Exception {
    FrameworkEvent frameworkEvent = new FrameworkEvent(FrameworkEvent.STARTED, bundle, null);
    logSupport.frameworkEvent(frameworkEvent);
    Mockito.verify(testLogger).info("FrameworkEvent STARTED", (Throwable) null);
}
Also used : FrameworkEvent(org.osgi.framework.FrameworkEvent) Test(org.junit.Test)

Example 5 with FrameworkEvent

use of org.osgi.framework.FrameworkEvent in project bnd by bndtools.

the class AgentServer method refresh.

public void refresh(boolean async) throws InterruptedException {
    FrameworkWiring f = context.getBundle(0).adapt(FrameworkWiring.class);
    if (f != null) {
        refresh = new CountDownLatch(1);
        f.refreshBundles(null, new FrameworkListener() {

            @Override
            public void frameworkEvent(FrameworkEvent event) {
                refresh.countDown();
            }
        });
        if (async)
            return;
        refresh.await();
    }
}
Also used : FrameworkEvent(org.osgi.framework.FrameworkEvent) FrameworkWiring(org.osgi.framework.wiring.FrameworkWiring) CountDownLatch(java.util.concurrent.CountDownLatch) FrameworkListener(org.osgi.framework.FrameworkListener)

Aggregations

FrameworkEvent (org.osgi.framework.FrameworkEvent)15 FrameworkListener (org.osgi.framework.FrameworkListener)10 BundleException (org.osgi.framework.BundleException)5 IOException (java.io.IOException)4 Semaphore (java.util.concurrent.Semaphore)3 Test (org.junit.Test)3 Bundle (org.osgi.framework.Bundle)3 FrameworkWiring (org.osgi.framework.wiring.FrameworkWiring)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 BundleContext (org.osgi.framework.BundleContext)2 ServiceReference (org.osgi.framework.ServiceReference)2 Framework (org.osgi.framework.launch.Framework)2 FrameworkFactory (org.osgi.framework.launch.FrameworkFactory)2 MiniFramework (aQute.launcher.minifw.MiniFramework)1 Event (aQute.remote.api.Event)1 File (java.io.File)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1