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)));
}
use of org.osgi.framework.BundleEvent in project sling by apache.
the class BundleEventUtil method stopDummyBundle.
/**
* Simulate a bundle STARTED event with a given set of classes simulated to be found in the bundle's classpath.
*/
public static void stopDummyBundle(Bundle bundle) {
((DummyBundle) bundle).setState(Bundle.RESOLVED);
BundleEvent event = new BundleEvent(BundleEvent.STOPPED, bundle);
MockOsgi.sendBundleEvent(bundle.getBundleContext(), event);
}
use of org.osgi.framework.BundleEvent in project sling by apache.
the class Activator method start.
public void start(BundleContext context) throws Exception {
commandMap = new OsgiMailcapCommandMap();
for (Bundle bundle : context.getBundles()) registerBundleMailcapEntries(bundle);
CommandMap.setDefaultCommandMap(commandMap);
bundleTracker = new BundleTracker(context, Bundle.ACTIVE | Bundle.UNINSTALLED | Bundle.STOP_TRANSIENT, new BundleTrackerCustomizer() {
public void removedBundle(Bundle bundle, BundleEvent event, Object object) {
unregisterBundleMailcapEntries(bundle);
}
public void modifiedBundle(Bundle bundle, BundleEvent event, Object object) {
unregisterBundleMailcapEntries(bundle);
registerBundleMailcapEntries(bundle);
}
public Object addingBundle(Bundle bundle, BundleEvent event) {
registerBundleMailcapEntries(bundle);
return bundle;
}
});
bundleTracker.open();
}
use of org.osgi.framework.BundleEvent in project sling by apache.
the class ContentLoaderServiceTest method testBundleResolvedBundleChanged.
//-------ContentLoaderService#bundleChanged(BundleEvent)-------//
//I'm not very sure how to test this method, it looks like side effect of this method goes very deep
//And more affects BundleContentLoader than ContentLoaderService
@Test
public void testBundleResolvedBundleChanged() throws NoSuchFieldException, RepositoryException {
final Bundle bundle = createNewBundle();
final List<Bundle> delayedBundles = (List<Bundle>) PrivateAccessor.getField(contentLoader, "delayedBundles");
final Set<String> updatedBundles = (Set<String>) PrivateAccessor.getField(underTest, "updatedBundles");
updatedBundles.add(bundle.getSymbolicName());
int updatedBundlesCurrentAmout = updatedBundles.size();
underTest.bundleChanged(new BundleEvent(BundleEvent.RESOLVED, bundle));
//Below we check that this bundle was removed from updatedBundles set
assertEquals(updatedBundlesCurrentAmout - 1, delayedBundles.size());
updatedBundlesCurrentAmout = updatedBundles.size();
underTest.bundleChanged(new BundleEvent(BundleEvent.UPDATED, bundle));
assertEquals(updatedBundlesCurrentAmout + 1, updatedBundles.size());
//Is it ok just to call this method to check that no exception occurs?
underTest.bundleChanged(new BundleEvent(BundleEvent.UNINSTALLED, bundle));
}
use of org.osgi.framework.BundleEvent in project aries by apache.
the class Activator method start.
/*
* (non-Javadoc)
*
* @see
* org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext
* )
*/
public void start(BundleContext context) throws Exception {
System.out.println("bundle helloIsolation start");
SecurityManager security = System.getSecurityManager();
if (security != null) {
System.out.println("HelloIsolationImpl: system manager is not null");
} else {
System.out.println("HelloIsolationImpl: system manager is still null");
}
sr = context.registerService(HelloIsolation.class.getName(), new HelloIsolationImpl(), null);
bt = new BundleTracker(context, Bundle.INSTALLED | Bundle.UNINSTALLED | Bundle.ACTIVE, new BundleTrackerCustomizer() {
public synchronized Object addingBundle(Bundle bundle, BundleEvent event) {
if (event == null) {
System.out.println("HelloIsolation " + bundle.getSymbolicName() + "_" + bundle.getVersion().toString() + " - adding Bundle: " + bundle.getSymbolicName() + " event: null");
} else {
System.out.println("HelloIsolation " + bundle.getSymbolicName() + "_" + bundle.getVersion().toString() + " - adding Bundle: " + bundle.getSymbolicName() + " event: " + event.getType());
}
addEventCount++;
return bundle;
}
public synchronized void modifiedBundle(Bundle bundle, BundleEvent event, Object object) {
if (event == null) {
System.out.println("HelloIsolation " + bundle.getSymbolicName() + "_" + bundle.getVersion().toString() + " - modifying Bundle: " + bundle.getSymbolicName() + " event: null");
} else {
System.out.println("HelloIsolation " + bundle.getSymbolicName() + "_" + bundle.getVersion().toString() + " - modifying Bundle: " + bundle.getSymbolicName() + " event: " + event.getType());
}
modifyEventCount++;
}
public synchronized void removedBundle(Bundle bundle, BundleEvent event, Object object) {
if (event == null) {
System.out.println("HelloIsolation " + bundle.getSymbolicName() + "_" + bundle.getVersion().toString() + " - removing Bundle: " + bundle.getSymbolicName() + " event: null");
} else {
System.out.println("HelloIsolation " + bundle.getSymbolicName() + "_" + bundle.getVersion().toString() + " - removing Bundle: " + bundle.getSymbolicName() + " event: " + event.getType());
}
removeEventCount++;
}
});
bt.open();
}
Aggregations