Search in sources :

Example 6 with EventAdmin

use of org.osgi.service.event.EventAdmin in project sling by apache.

the class SlingAuthenticator method postLoginEvent.

private void postLoginEvent(final AuthenticationInfo authInfo) {
    final Dictionary<String, Object> properties = new Hashtable<String, Object>();
    properties.put(SlingConstants.PROPERTY_USERID, authInfo.getUser());
    properties.put(AuthenticationInfo.AUTH_TYPE, authInfo.getAuthType());
    EventAdmin localEA = this.eventAdmin;
    if (localEA != null) {
        localEA.postEvent(new Event(AuthConstants.TOPIC_LOGIN, properties));
    }
}
Also used : EventAdmin(org.osgi.service.event.EventAdmin) Hashtable(java.util.Hashtable) ServletRequestEvent(javax.servlet.ServletRequestEvent) Event(org.osgi.service.event.Event)

Example 7 with EventAdmin

use of org.osgi.service.event.EventAdmin in project ddf by codice.

the class TestEventProcessorImpl method testNullOperation.

@Test
public void testNullOperation() {
    MetacardImpl metacard = new MetacardImpl();
    metacard.setContentTypeName("Nitf");
    metacard.setContentTypeVersion("2.0");
    metacard.setMetadata("<xml/>");
    EventAdmin eventAdmin = new MockEventAdmin();
    try {
        EventProcessorImpl.processEntry(metacard, null, eventAdmin);
    } catch (Exception e) {
        LOGGER.error("Unexpected exception.", e);
        fail();
    }
}
Also used : EventAdmin(org.osgi.service.event.EventAdmin) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Test(org.junit.Test)

Example 8 with EventAdmin

use of org.osgi.service.event.EventAdmin in project sling by apache.

the class MockAdapterManagerImpl method registerAdapterFactory.

/**
     * Unregisters the {@link AdapterFactory} referred to by the service
     * <code>reference</code> from the registry.
     */
private void registerAdapterFactory(final ComponentContext context, final ServiceReference reference) {
    final String[] adaptables = PropertiesUtil.toStringArray(reference.getProperty(ADAPTABLE_CLASSES));
    final String[] adapters = PropertiesUtil.toStringArray(reference.getProperty(ADAPTER_CLASSES));
    if (adaptables == null || adaptables.length == 0 || adapters == null || adapters.length == 0) {
        return;
    }
    // DISABLED IN THIS COPY OF CLASS
    /*
        for (String clazz : adaptables) {
            if (!checkPackage(packageAdmin, clazz)) {
                log.warn("Adaptable class {} in factory service {} is not in an exported package.", clazz, reference.getProperty(Constants.SERVICE_ID));
            }
        }

        for (String clazz : adapters) {
            if (!checkPackage(packageAdmin, clazz)) {
                log.warn("Adapter class {} in factory service {} is not in an exported package.", clazz, reference.getProperty(Constants.SERVICE_ID));
            }
        }
        */
    final AdapterFactoryDescriptor factoryDesc = new AdapterFactoryDescriptor(context, reference, adapters);
    for (final String adaptable : adaptables) {
        AdapterFactoryDescriptorMap adfMap = null;
        synchronized (this.descriptors) {
            adfMap = descriptors.get(adaptable);
            if (adfMap == null) {
                adfMap = new AdapterFactoryDescriptorMap();
                descriptors.put(adaptable, adfMap);
            }
        }
        synchronized (adfMap) {
            adfMap.put(reference, factoryDesc);
        }
    }
    // clear the factory cache to force rebuild on next access
    this.factoryCache.clear();
    // register adaption
    final Dictionary<String, Object> props = new Hashtable<String, Object>();
    props.put(SlingConstants.PROPERTY_ADAPTABLE_CLASSES, adaptables);
    props.put(SlingConstants.PROPERTY_ADAPTER_CLASSES, adapters);
    ServiceRegistration adaptionRegistration = this.context.getBundleContext().registerService(Adaption.class.getName(), AdaptionImpl.INSTANCE, props);
    if (log.isDebugEnabled()) {
        log.debug("Registered service {} with {} : {} and {} : {}", new Object[] { Adaption.class.getName(), SlingConstants.PROPERTY_ADAPTABLE_CLASSES, Arrays.toString(adaptables), SlingConstants.PROPERTY_ADAPTER_CLASSES, Arrays.toString(adapters) });
    }
    factoryDesc.setAdaption(adaptionRegistration);
    // send event
    final EventAdmin localEA = this.eventAdmin;
    if (localEA != null) {
        localEA.postEvent(new Event(SlingConstants.TOPIC_ADAPTER_FACTORY_ADDED, props));
    }
}
Also used : AdapterFactoryDescriptorMap(org.apache.sling.adapter.internal.AdapterFactoryDescriptorMap) Adaption(org.apache.sling.adapter.Adaption) EventAdmin(org.osgi.service.event.EventAdmin) AdapterFactoryDescriptor(org.apache.sling.adapter.internal.AdapterFactoryDescriptor) Hashtable(java.util.Hashtable) Event(org.osgi.service.event.Event) ServiceRegistration(org.osgi.framework.ServiceRegistration)

Example 9 with EventAdmin

use of org.osgi.service.event.EventAdmin in project sling by apache.

the class MockEventAdminTest method testSendEvent_Sample1.

@Test
public void testSendEvent_Sample1() {
    EventAdmin eventAdmin = context.getService(EventAdmin.class);
    eventAdmin.sendEvent(EVENT_SAMPLE_1);
    assertEquals(ImmutableList.of(EVENT_SAMPLE_1), eventHandler1.getReceivedEvents());
    assertEquals(ImmutableList.of(EVENT_SAMPLE_1), eventHandler12.getReceivedEvents());
    assertEquals(ImmutableList.of(EVENT_SAMPLE_1), eventHandlerSampleAll.getReceivedEvents());
    assertEquals(ImmutableList.of(EVENT_SAMPLE_1), eventHandlerAll.getReceivedEvents());
}
Also used : EventAdmin(org.osgi.service.event.EventAdmin) Test(org.junit.Test)

Example 10 with EventAdmin

use of org.osgi.service.event.EventAdmin in project jetty.project by eclipse.

the class EventSender method send.

public void send(String topic, Bundle wab, String contextPath, Exception ex) {
    EventAdmin service = (EventAdmin) _serviceTracker.getService();
    if (service != null) {
        Dictionary<String, Object> props = new Hashtable<String, Object>();
        props.put("bundle.symbolicName", wab.getSymbolicName());
        props.put("bundle.id", wab.getBundleId());
        props.put("bundle", wab);
        props.put("bundle.version", wab.getVersion());
        props.put("context.path", contextPath);
        props.put("timestamp", System.currentTimeMillis());
        props.put("extender.bundle", _myBundle);
        props.put("extender.bundle.symbolicName", _myBundle.getSymbolicName());
        props.put("extender.bundle.id", _myBundle.getBundleId());
        props.put("extender.bundle.version", _myBundle.getVersion());
        if (FAILED_EVENT.equalsIgnoreCase(topic) && ex != null)
            props.put("exception", ex);
        service.sendEvent(new Event(topic, props));
    }
}
Also used : EventAdmin(org.osgi.service.event.EventAdmin) Hashtable(java.util.Hashtable) Event(org.osgi.service.event.Event)

Aggregations

EventAdmin (org.osgi.service.event.EventAdmin)26 Event (org.osgi.service.event.Event)18 Hashtable (java.util.Hashtable)11 Test (org.junit.Test)7 Adaption (org.apache.sling.adapter.Adaption)4 BundleContext (org.osgi.framework.BundleContext)4 HashMap (java.util.HashMap)3 Fixture (org.apache.sling.resourceresolver.impl.Fixture)3 ServiceReference (org.osgi.framework.ServiceReference)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 FeatureEvent (org.apache.karaf.features.FeatureEvent)2 RepositoryEvent (org.apache.karaf.features.RepositoryEvent)2 AdapterFactoryDescriptor (org.apache.sling.adapter.internal.AdapterFactoryDescriptor)2 AdapterFactoryDescriptorMap (org.apache.sling.adapter.internal.AdapterFactoryDescriptorMap)2 ChangeListener (org.apache.sling.resourceresolver.impl.providers.ResourceProviderTracker.ChangeListener)2 Before (org.junit.Before)2 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)1 Date (java.util.Date)1 Dictionary (java.util.Dictionary)1 EventObject (java.util.EventObject)1