Search in sources :

Example 1 with MessageBus

use of org.eclipse.che.ide.websocket.MessageBus in project che by eclipse.

the class JavaSearchServiceWS method findUsages.

@Override
public Promise<FindUsagesResponse> findUsages(final FindUsagesRequest request) {
    final MessageBus messageBus = provider.getMachineMessageBus();
    return createFromAsyncRequest(callback -> {
        final MessageBuilder builder = new MessageBuilder(POST, pathToService + "find/usages");
        builder.data(dtoFactory.toJson(request)).header(CONTENTTYPE, APPLICATION_JSON).header(ACCEPT, APPLICATION_JSON);
        loader.show();
        try {
            messageBus.send(builder.build(), new RequestCallback<FindUsagesResponse>(unmarshallerFactory.newWSUnmarshaller(FindUsagesResponse.class)) {

                @Override
                protected void onSuccess(FindUsagesResponse result) {
                    loader.hide();
                    callback.onSuccess(result);
                }

                @Override
                protected void onFailure(Throwable exception) {
                    loader.hide();
                    callback.onFailure(exception);
                }
            });
        } catch (WebSocketException e) {
            loader.hide();
            callback.onFailure(e);
        }
    });
}
Also used : MessageBus(org.eclipse.che.ide.websocket.MessageBus) FindUsagesResponse(org.eclipse.che.ide.ext.java.shared.dto.search.FindUsagesResponse) MessageBuilder(org.eclipse.che.ide.websocket.MessageBuilder) WebSocketException(org.eclipse.che.ide.websocket.WebSocketException)

Example 2 with MessageBus

use of org.eclipse.che.ide.websocket.MessageBus in project che by eclipse.

the class MavenMessagesHandler method handleOperations.

private void handleOperations(final DtoFactory factory, final WsAgentStateController wsAgentStateController) {
    eventBus.addHandler(WsAgentStateEvent.TYPE, new WsAgentStateHandler() {

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

                @Override
                public void apply(MessageBus messageBus) throws OperationException {
                    try {
                        handleMavenServerEvents(messageBus);
                        handleMavenArchetype(messageBus);
                    } catch (WebSocketException e) {
                        dependencyResolver.hide();
                        Log.error(getClass(), e);
                    }
                }
            });
        }

        @Override
        public void onWsAgentStopped(WsAgentStateEvent event) {
            dependencyResolver.hide();
        }
    });
    eventBus.addHandler(WorkspaceStoppedEvent.TYPE, new WorkspaceStoppedEvent.Handler() {

        @Override
        public void onWorkspaceStopped(WorkspaceStoppedEvent event) {
            dependencyResolver.hide();
        }
    });
}
Also used : MessageBus(org.eclipse.che.ide.websocket.MessageBus) WebSocketException(org.eclipse.che.ide.websocket.WebSocketException) WsAgentStateHandler(org.eclipse.che.ide.api.machine.events.WsAgentStateHandler) Operation(org.eclipse.che.api.promises.client.Operation) WsAgentStateEvent(org.eclipse.che.ide.api.machine.events.WsAgentStateEvent) WorkspaceStoppedEvent(org.eclipse.che.ide.api.workspace.event.WorkspaceStoppedEvent)

Example 3 with MessageBus

use of org.eclipse.che.ide.websocket.MessageBus 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

MessageBus (org.eclipse.che.ide.websocket.MessageBus)3 WebSocketException (org.eclipse.che.ide.websocket.WebSocketException)3 Operation (org.eclipse.che.api.promises.client.Operation)1 OperationException (org.eclipse.che.api.promises.client.OperationException)1 WsAgentStateEvent (org.eclipse.che.ide.api.machine.events.WsAgentStateEvent)1 WsAgentStateHandler (org.eclipse.che.ide.api.machine.events.WsAgentStateHandler)1 WorkspaceStoppedEvent (org.eclipse.che.ide.api.workspace.event.WorkspaceStoppedEvent)1 Jso (org.eclipse.che.ide.collections.Jso)1 FindUsagesResponse (org.eclipse.che.ide.ext.java.shared.dto.search.FindUsagesResponse)1 MessageBuilder (org.eclipse.che.ide.websocket.MessageBuilder)1 MessageHandler (org.eclipse.che.ide.websocket.events.MessageHandler)1 MessageType (org.eclipse.che.plugin.maven.shared.MessageType)1 StartStopNotification (org.eclipse.che.plugin.maven.shared.dto.StartStopNotification)1