Search in sources :

Example 1 with MessageEventContext

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);
}
Also used : DolphinContext(com.canoo.dp.impl.server.context.DolphinContext) MessageEventContext(com.canoo.platform.remoting.server.event.MessageEventContext) HttpSession(javax.servlet.http.HttpSession) ClientSession(com.canoo.platform.server.client.ClientSession)

Aggregations

DolphinContext (com.canoo.dp.impl.server.context.DolphinContext)1 MessageEventContext (com.canoo.platform.remoting.server.event.MessageEventContext)1 ClientSession (com.canoo.platform.server.client.ClientSession)1 HttpSession (javax.servlet.http.HttpSession)1