use of org.eclipse.e4.core.di.suppliers.IRequestor in project eclipse.platform.runtime by eclipse.
the class ExtendedSupplierInjectionTests method testSupplierOrdering.
/**
* bug 428837: ensure suppliers are ranked by service.ranking
*/
@Test
public void testSupplierOrdering() {
BundleContext bc = FrameworkUtil.getBundle(getClass()).getBundleContext();
ExtendedObjectSupplier supplier = new ExtendedObjectSupplier() {
@Override
public Object get(IObjectDescriptor descriptor, IRequestor requestor, boolean track, boolean group) {
// TODO Auto-generated method stub
return null;
}
};
Dictionary<String, Object> properties = new Hashtable<>();
properties.put(ExtendedObjectSupplier.SERVICE_CONTEXT_KEY, EventTopic.class.getName());
properties.put(Constants.SERVICE_RANKING, 100);
ServiceRegistration<?> sr = bc.registerService(ExtendedObjectSupplier.SERVICE_NAME, supplier, properties);
try {
assertEquals(supplier, ProviderHelper.findProvider(EventTopic.class.getName(), null));
} finally {
sr.unregister();
}
}
use of org.eclipse.e4.core.di.suppliers.IRequestor in project eclipse.platform.runtime by eclipse.
the class EventObjectSupplier method subscribe.
private void subscribe(String topic, IRequestor requestor) {
Subscriber subscriber = new Subscriber(requestor, topic);
synchronized (registrations) {
if (registrations.containsKey(subscriber))
return;
}
BundleContext bundleContext = FrameworkUtil.getBundle(EventObjectSupplier.class).getBundleContext();
if (bundleContext == null)
throw new InjectionException(// $NON-NLS-1$
"Unable to subscribe to events: org.eclipse.e4.core.di.extensions bundle is not activated");
String[] topics = new String[] { topic };
Dictionary<String, Object> d = new Hashtable<>();
d.put(EventConstants.EVENT_TOPIC, topics);
EventHandler wrappedHandler = makeHandler(topic, requestor);
ServiceRegistration<EventHandler> registration = bundleContext.registerService(EventHandler.class, wrappedHandler, d);
// be OK
synchronized (registrations) {
registrations.put(subscriber, registration);
}
}
Aggregations