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);
}
}
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());
}
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();
}
}
}
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);
}
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();
}
}
Aggregations