use of org.osgi.framework.BundleEvent in project atlas by alibaba.
the class Framework method notifyBundleListeners.
/**
* notify all bundle listeners.
*
* @param state the new state.
* @param bundle the bundle.
*/
static void notifyBundleListeners(final int state, final Bundle bundle) {
if (syncBundleListeners.isEmpty() && bundleListeners.isEmpty()) {
return;
}
final BundleEvent event = new BundleEvent(state, bundle);
// inform the synchrounous bundle listeners first ...
final BundleListener[] syncs = (BundleListener[]) syncBundleListeners.toArray(new BundleListener[syncBundleListeners.size()]);
for (int i = 0; i < syncs.length; i++) {
syncs[i].bundleChanged(event);
}
if (bundleListeners.isEmpty()) {
return;
}
final BundleListener[] asyncs = (BundleListener[]) bundleListeners.toArray(new BundleListener[bundleListeners.size()]);
for (int i = 0; i < asyncs.length; i++) {
asyncs[i].bundleChanged(event);
}
}
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();
}
use of org.osgi.framework.BundleEvent in project sling by apache.
the class QuartzSchedulerTest method testBundleChangedWithStartedBundle.
@Test
public void testBundleChangedWithStartedBundle() 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.STARTED, bundle);
quartzScheduler.bundleChanged(event);
assertTrue(proxies.get("testName").getScheduler().checkExists(JobKey.jobKey(firstJob)));
assertTrue(proxies.get("testName").getScheduler().checkExists(JobKey.jobKey(secondJob)));
}
Aggregations