Search in sources :

Example 1 with EventHandlerWrapper

use of org.eclipse.ecf.internal.remoteservice.eventadmin.EventHandlerWrapper in project ecf by eclipse.

the class DistributedEventAdmin method localDispatch.

/**
 * Locally dispatch an Event. This method is used to deliver an
 * {@link Event} to matching {@link EventHandler}s that are registered in
 * the local OSGi service registry.
 *
 * @param dispatchedEvent
 *            the Event to dispatch. Will not be <code>null</code>.
 * @param isAsync
 *            <code>true</code> if the dispatch should be done
 *            asynchronously (non-blocking), <code>false</code> if the
 *            dispatch should be done synchronously.
 */
protected void localDispatch(Event dispatchedEvent, boolean isAsync) {
    EventManager currentManager = eventManager;
    if (currentManager == null) {
        return;
    }
    if (dispatchedEvent == null) {
        log.log(LogService.LOG_ERROR, "Null event passed to EventAdmin was ignored.");
    }
    Event event = notifyPreLocalDispatch(dispatchedEvent);
    if (event != null) {
        String eventTopic = event.getTopic();
        try {
            SecurityManager sm = System.getSecurityManager();
            if (sm != null)
                sm.checkPermission(new TopicPermission(eventTopic, TopicPermission.PUBLISH));
        } catch (SecurityException e) {
            logError("Caller bundle does not have TopicPermission to publish topic " + eventTopic, e);
            throw e;
        }
        Set eventHandlerWrappers = eventHandlerTracker.getHandlers(eventTopic);
        SecurityManager sm = System.getSecurityManager();
        Permission perm = (sm == null) ? null : new TopicPermission(eventTopic, TopicPermission.SUBSCRIBE);
        CopyOnWriteIdentityMap listeners = new CopyOnWriteIdentityMap();
        Iterator iter = eventHandlerWrappers.iterator();
        while (iter.hasNext()) {
            EventHandlerWrapper wrapper = (EventHandlerWrapper) iter.next();
            listeners.put(wrapper, perm);
        }
        ListenerQueue listenerQueue = new ListenerQueue(currentManager);
        listenerQueue.queueListeners(listeners.entrySet(), eventHandlerTracker);
        if (isAsync) {
            listenerQueue.dispatchEventAsynchronous(0, event);
        } else {
            listenerQueue.dispatchEventSynchronous(0, event);
        }
        notifyPostLocalDispatch(event);
    }
}
Also used : CopyOnWriteIdentityMap(org.eclipse.osgi.framework.eventmgr.CopyOnWriteIdentityMap) HashSet(java.util.HashSet) Set(java.util.Set) EventManager(org.eclipse.osgi.framework.eventmgr.EventManager) TopicPermission(org.osgi.service.event.TopicPermission) Permission(java.security.Permission) Iterator(java.util.Iterator) ISharedObjectMessageEvent(org.eclipse.ecf.core.sharedobject.events.ISharedObjectMessageEvent) ISharedObjectCreateResponseEvent(org.eclipse.ecf.core.sharedobject.events.ISharedObjectCreateResponseEvent) Event(org.osgi.service.event.Event) ListenerQueue(org.eclipse.osgi.framework.eventmgr.ListenerQueue) EventHandlerWrapper(org.eclipse.ecf.internal.remoteservice.eventadmin.EventHandlerWrapper) TopicPermission(org.osgi.service.event.TopicPermission)

Aggregations

Permission (java.security.Permission)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 Set (java.util.Set)1 ISharedObjectCreateResponseEvent (org.eclipse.ecf.core.sharedobject.events.ISharedObjectCreateResponseEvent)1 ISharedObjectMessageEvent (org.eclipse.ecf.core.sharedobject.events.ISharedObjectMessageEvent)1 EventHandlerWrapper (org.eclipse.ecf.internal.remoteservice.eventadmin.EventHandlerWrapper)1 CopyOnWriteIdentityMap (org.eclipse.osgi.framework.eventmgr.CopyOnWriteIdentityMap)1 EventManager (org.eclipse.osgi.framework.eventmgr.EventManager)1 ListenerQueue (org.eclipse.osgi.framework.eventmgr.ListenerQueue)1 Event (org.osgi.service.event.Event)1 TopicPermission (org.osgi.service.event.TopicPermission)1