Search in sources :

Example 1 with EventAdmin

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

the class OsgiEventAdminNotifier method notify.

public void notify(EventObject event) throws Exception {
    EventAdmin eventAdmin = tracker.getService();
    if (eventAdmin == null) {
        return;
    }
    Dictionary<String, Object> props = new Hashtable<String, Object>();
    props.put(TYPE, getType(event));
    props.put(EVENT, event);
    props.put(TIMESTAMP, System.currentTimeMillis());
    props.put(BUNDLE, bundleContext.getBundle());
    props.put(BUNDLE_SYMBOLICNAME, bundleContext.getBundle().getSymbolicName());
    props.put(BUNDLE_ID, bundleContext.getBundle().getBundleId());
    props.put(BUNDLE_VERSION, getBundleVersion(bundleContext.getBundle()));
    try {
        props.put(CAUSE, event.getClass().getMethod("getCause").invoke(event));
    } catch (Throwable t) {
    // ignore
    }
    eventAdmin.postEvent(new Event(getTopic(event), props));
}
Also used : EventAdmin(org.osgi.service.event.EventAdmin) Hashtable(java.util.Hashtable) Event(org.osgi.service.event.Event) EventObject(java.util.EventObject)

Example 2 with EventAdmin

use of org.osgi.service.event.EventAdmin in project jersey by jersey.

the class Activator method sendAdminEvent.

private void sendAdminEvent() {
    ServiceReference eaRef = bc.getServiceReference(EventAdmin.class.getName());
    if (eaRef != null) {
        EventAdmin ea = (EventAdmin) bc.getService(eaRef);
        ea.sendEvent(new Event("jersey/test/DEPLOYED", new HashMap<String, String>() {

            {
                put("context-path", "/");
            }
        }));
        bc.ungetService(eaRef);
    }
}
Also used : EventAdmin(org.osgi.service.event.EventAdmin) HashMap(java.util.HashMap) Event(org.osgi.service.event.Event) ServiceReference(org.osgi.framework.ServiceReference)

Example 3 with EventAdmin

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

the class EventAdminListener method featureEvent.

public void featureEvent(FeatureEvent event) {
    try {
        EventAdmin eventAdmin = tracker.getService();
        if (eventAdmin == null) {
            return;
        }
        Dictionary<String, Object> props = new Hashtable<>();
        props.put(EventConstants.TYPE, event.getType());
        props.put(EventConstants.EVENT, event);
        props.put(EventConstants.TIMESTAMP, System.currentTimeMillis());
        props.put(EventConstants.FEATURE_NAME, event.getFeature().getName());
        props.put(EventConstants.FEATURE_VERSION, event.getFeature().getVersion());
        String topic;
        switch(event.getType()) {
            case FeatureInstalled:
                topic = EventConstants.TOPIC_FEATURES_INSTALLED;
                break;
            case FeatureUninstalled:
                topic = EventConstants.TOPIC_FEATURES_UNINSTALLED;
                break;
            default:
                throw new IllegalStateException("Unknown features event type: " + event.getType());
        }
        eventAdmin.postEvent(new Event(topic, props));
    } catch (IllegalStateException e) {
        LOGGER.warn("Unable to post event to EventAdmin", e);
    }
}
Also used : EventAdmin(org.osgi.service.event.EventAdmin) Hashtable(java.util.Hashtable) Event(org.osgi.service.event.Event) FeatureEvent(org.apache.karaf.features.FeatureEvent) RepositoryEvent(org.apache.karaf.features.RepositoryEvent)

Example 4 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 5 with EventAdmin

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

the class AdapterManagerImpl 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<AdapterFactory> reference) {
    final String[] adaptables = PropertiesUtil.toStringArray(reference.getProperty(ADAPTABLE_CLASSES));
    final String[] adapters = PropertiesUtil.toStringArray(reference.getProperty(ADAPTER_CLASSES));
    final boolean allowedInPrivatePackage = PropertiesUtil.toBoolean(reference.getProperty(ALLOWED_IN_PRIVATE), false);
    if (adaptables == null || adaptables.length == 0 || adapters == null || adapters.length == 0) {
        return;
    }
    for (String clazz : adaptables) {
        if (!allowedInPrivatePackage && !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 (!allowedInPrivatePackage && !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<>();
    props.put(SlingConstants.PROPERTY_ADAPTABLE_CLASSES, adaptables);
    props.put(SlingConstants.PROPERTY_ADAPTER_CLASSES, adapters);
    ServiceRegistration<Adaption> adaptionRegistration = this.context.getBundleContext().registerService(Adaption.class, 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 : Adaption(org.apache.sling.adapter.Adaption) 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