use of com.canoo.platform.remoting.server.event.MessageEventContext in project dolphin-platform by canoo.
the class AbstractEventBus method publish.
@Override
public <T extends Serializable> void publish(final Topic<T> topic, final T data) {
checkInitialization();
final DolphinEvent event = new DolphinEvent(topic, System.currentTimeMillis(), data);
event.addMetadata(EventConstants.TYPE_PARAM, EventConstants.TYPE_PLATFORM);
final DolphinContext currentContext = getCurrentContext();
if (currentContext != null) {
final ClientSession clientSession = currentContext.getClientSession();
if (clientSession != null) {
event.addMetadata(EventConstants.CLIENT_SESSION_PARAM, clientSession.getId());
final HttpSession httpSession = clientSession.getHttpSession();
if (httpSession != null) {
event.addMetadata(EventConstants.HTTP_SESSION_PARAM, httpSession.getId());
}
}
}
// Handle listener in same session
if (currentContext != null) {
final List<ListenerWithFilter<T>> listenersInCurrentSession = getListenersForSessionAndTopic(currentContext.getId(), topic);
for (ListenerWithFilter<T> listenerAndFilter : listenersInCurrentSession) {
final Predicate<MessageEventContext<T>> filter = listenerAndFilter.getFilter();
final MessageListener<T> listener = listenerAndFilter.getListener();
if (filter == null || filter.test(event.getMessageEventContext())) {
listener.onMessage(event);
}
}
}
publishForOtherSessions(event);
}
Aggregations