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);
}
}
Aggregations