Search in sources :

Example 1 with MessageHandler

use of org.eclipse.che.ide.websocket.events.MessageHandler in project che by eclipse.

the class AbstractMessageBus method processSubscriptionMessage.

/**
     * Process the {@link Message} that received by subscription.
     *
     * @param message
     *         {@link Message}
     */
private void processSubscriptionMessage(Message message) {
    String channel = getChannel(message);
    List<MessageHandler> subscribersSet = channelToSubscribersMap.get(channel);
    if (subscribersSet != null) {
        for (MessageHandler handler : subscribersSet) {
            //TODO this is nasty, need refactor this
            if (handler instanceof SubscriptionHandler) {
                ((SubscriptionHandler) handler).onMessage(message);
            } else {
                handler.onMessage(message.getBody());
            }
        }
    }
}
Also used : SubscriptionHandler(org.eclipse.che.ide.websocket.rest.SubscriptionHandler) MessageHandler(org.eclipse.che.ide.websocket.events.MessageHandler)

Example 2 with MessageHandler

use of org.eclipse.che.ide.websocket.events.MessageHandler in project che by eclipse.

the class ResolvingMavenProjectStateHolder method onWsAgentStarted.

@Override
public void onWsAgentStarted(WsAgentStateEvent event) {
    wsAgentStateController.getMessageBus().then(new Operation<MessageBus>() {

        @Override
        public void apply(MessageBus messageBus) throws OperationException {
            try {
                messageBus.subscribe(MAVEN_CHANEL_NAME, new MessageHandler() {

                    @Override
                    public void onMessage(String message) {
                        Jso jso = Jso.deserialize(message);
                        int type = jso.getFieldCastedToInteger("$type");
                        MessageType messageType = MessageType.valueOf(type);
                        if (messageType == START_STOP) {
                            handleStartStop(factory.createDtoFromJson(message, StartStopNotification.class));
                        }
                    }
                });
            } catch (WebSocketException e) {
                Log.error(getClass(), e);
            }
        }
    });
}
Also used : MessageBus(org.eclipse.che.ide.websocket.MessageBus) MessageHandler(org.eclipse.che.ide.websocket.events.MessageHandler) WebSocketException(org.eclipse.che.ide.websocket.WebSocketException) Jso(org.eclipse.che.ide.collections.Jso) StartStopNotification(org.eclipse.che.plugin.maven.shared.dto.StartStopNotification) OperationException(org.eclipse.che.api.promises.client.OperationException) MessageType(org.eclipse.che.plugin.maven.shared.MessageType)

Aggregations

MessageHandler (org.eclipse.che.ide.websocket.events.MessageHandler)2 OperationException (org.eclipse.che.api.promises.client.OperationException)1 Jso (org.eclipse.che.ide.collections.Jso)1 MessageBus (org.eclipse.che.ide.websocket.MessageBus)1 WebSocketException (org.eclipse.che.ide.websocket.WebSocketException)1 SubscriptionHandler (org.eclipse.che.ide.websocket.rest.SubscriptionHandler)1 MessageType (org.eclipse.che.plugin.maven.shared.MessageType)1 StartStopNotification (org.eclipse.che.plugin.maven.shared.dto.StartStopNotification)1