use of org.osgi.framework.BundleEvent in project karaf by apache.
the class FeatureDeploymentListener method init.
public void init() throws Exception {
bundleContext.addBundleListener(this);
loadProperties();
// Scan bundles
for (Bundle bundle : bundleContext.getBundles()) {
if (bundle.getState() == Bundle.RESOLVED || bundle.getState() == Bundle.STARTING || bundle.getState() == Bundle.ACTIVE)
bundleChanged(new BundleEvent(BundleEvent.RESOLVED, bundle));
}
}
use of org.osgi.framework.BundleEvent in project jackrabbit-oak by apache.
the class OakOSGiRepositoryFactory method shutdown.
static void shutdown(PojoServiceRegistry registry, int timeoutInSecs) throws BundleException {
if (registry == null) {
return;
}
final Bundle systemBundle = registry.getBundleContext().getBundle();
final CountDownLatch shutdownLatch = new CountDownLatch(1);
//Logic here is similar to org.apache.felix.connect.PojoServiceRegistryFactoryImpl.FrameworkImpl.waitForStop()
systemBundle.getBundleContext().addBundleListener(new SynchronousBundleListener() {
public void bundleChanged(BundleEvent event) {
if (event.getBundle() == systemBundle && event.getType() == BundleEvent.STOPPED) {
shutdownLatch.countDown();
}
}
});
//Initiate shutdown
systemBundle.stop();
//Wait for framework shutdown to complete
try {
boolean shutdownWithinTimeout = shutdownLatch.await(timeoutInSecs, TimeUnit.SECONDS);
if (!shutdownWithinTimeout) {
throw new BundleException("Timed out while waiting for repository " + "shutdown for " + timeoutInSecs + " secs");
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new BundleException("Timed out while waiting for repository " + "shutdown for " + timeoutInSecs + " secs", e);
}
}
use of org.osgi.framework.BundleEvent in project sling by apache.
the class ScriptEngineManagerFactoryTest method checkAddingScriptBundle.
@Test
public void checkAddingScriptBundle() throws Exception {
context.checking(new Expectations() {
{
exactly(1).of(bundleCtx).registerService(with(equal(new String[] { "javax.script.ScriptEngineManager", "org.apache.sling.scripting.core.impl.helper.SlingScriptEngineManager" })), with(any(Object.class)), with(any(Dictionary.class)));
will(returnValue(new MockServiceRegistration()));
}
});
ScriptEngineManagerFactory factory = new ScriptEngineManagerFactory();
factory.activate(componentCtx);
ScriptEngineManager first = factory.getScriptEngineManager();
assertNull(first.getEngineByName("dummy"));
final Bundle bundle = context.mock(Bundle.class);
final File factoryFile = createFactoryFile();
context.checking(new Expectations() {
{
atLeast(1).of(bundle).getEntry("META-INF/services/javax.script.ScriptEngineFactory");
will(returnValue(factoryFile.toURI().toURL()));
atLeast(1).of(bundle).loadClass(SCRIPT_ENGINE_FACTORY.getName());
will(returnValue(SCRIPT_ENGINE_FACTORY));
}
});
factory.bundleChanged(new BundleEvent(BundleEvent.STARTED, bundle));
ScriptEngineManager second = factory.getScriptEngineManager();
assertNotNull(second.getEngineByName("dummy"));
}
use of org.osgi.framework.BundleEvent in project sling by apache.
the class QuartzSchedulerTest method testBundleChangedWithStoppedBundle.
@Test
public void testBundleChangedWithStoppedBundle() throws SchedulerException {
String firstJob = "testName1";
String secondJob = "testName2";
when(bundle.getBundleId()).thenReturn(2L);
quartzScheduler.addJob(1L, 1L, firstJob, new Thread(), new HashMap<String, Serializable>(), "0 * * * * ?", true);
quartzScheduler.addJob(2L, 2L, secondJob, new Thread(), new HashMap<String, Serializable>(), "0 * * * * ?", true);
BundleEvent event = new BundleEvent(BundleEvent.STOPPED, bundle);
quartzScheduler.bundleChanged(event);
assertTrue(proxies.get("testName").getScheduler().checkExists(JobKey.jobKey(firstJob)));
assertFalse(proxies.get("testName").getScheduler().checkExists(JobKey.jobKey(secondJob)));
}
use of org.osgi.framework.BundleEvent in project sling by apache.
the class QuartzSchedulerTest method testBundleChangedWithoutScheduler.
@Test
public void testBundleChangedWithoutScheduler() throws Exception {
String firstJob = "testName1";
String secondJob = "testName2";
Long bundleIdToRemove = 2L;
when(bundle.getBundleId()).thenReturn(bundleIdToRemove);
quartzScheduler.addJob(1L, 1L, firstJob, new Thread(), new HashMap<String, Serializable>(), "0 * * * * ?", true);
quartzScheduler.addJob(bundleIdToRemove, 2L, secondJob, new Thread(), new HashMap<String, Serializable>(), "0 * * * * ?", true);
setInternalSchedulerToNull();
BundleEvent event = new BundleEvent(BundleEvent.STOPPED, bundle);
quartzScheduler.bundleChanged(event);
assertTrue(proxies.get("testName").getScheduler().checkExists(JobKey.jobKey(firstJob)));
assertTrue(proxies.get("testName").getScheduler().checkExists(JobKey.jobKey(secondJob)));
returnInternalSchedulerBack();
}
Aggregations