Search in sources :

Example 6 with IRequestor

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();
    }
}
Also used : IObjectDescriptor(org.eclipse.e4.core.di.suppliers.IObjectDescriptor) EventTopic(org.eclipse.e4.core.di.extensions.EventTopic) IRequestor(org.eclipse.e4.core.di.suppliers.IRequestor) Hashtable(java.util.Hashtable) ExtendedObjectSupplier(org.eclipse.e4.core.di.suppliers.ExtendedObjectSupplier) BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test)

Example 7 with IRequestor

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);
    }
}
Also used : InjectionException(org.eclipse.e4.core.di.InjectionException) Hashtable(java.util.Hashtable) EventHandler(org.osgi.service.event.EventHandler) BundleContext(org.osgi.framework.BundleContext)

Aggregations

IRequestor (org.eclipse.e4.core.di.suppliers.IRequestor)3 BundleContext (org.osgi.framework.BundleContext)3 Type (java.lang.reflect.Type)2 ArrayList (java.util.ArrayList)2 Hashtable (java.util.Hashtable)2 List (java.util.List)2 InjectionException (org.eclipse.e4.core.di.InjectionException)2 Bundle (org.osgi.framework.Bundle)2 ParameterizedType (java.lang.reflect.ParameterizedType)1 Collections (java.util.Collections)1 IEclipsePreferences (org.eclipse.core.runtime.preferences.IEclipsePreferences)1 Active (org.eclipse.e4.core.contexts.Active)1 RunAndTrack (org.eclipse.e4.core.contexts.RunAndTrack)1 EventTopic (org.eclipse.e4.core.di.extensions.EventTopic)1 Service (org.eclipse.e4.core.di.extensions.Service)1 ExtendedObjectSupplier (org.eclipse.e4.core.di.suppliers.ExtendedObjectSupplier)1 IObjectDescriptor (org.eclipse.e4.core.di.suppliers.IObjectDescriptor)1 Test (org.junit.Test)1 EventHandler (org.osgi.service.event.EventHandler)1 LogService (org.osgi.service.log.LogService)1