Search in sources :

Example 1 with WsAgentStateEvent

use of org.eclipse.che.ide.api.machine.events.WsAgentStateEvent in project che by eclipse.

the class AbstractDebugger method addHandlers.

private void addHandlers(final MessageBusProvider messageBusProvider) {
    eventBus.addHandler(WsAgentStateEvent.TYPE, new WsAgentStateHandler() {

        @Override
        public void onWsAgentStarted(WsAgentStateEvent event) {
            messageBus = messageBusProvider.getMachineMessageBus();
            if (!isConnected()) {
                return;
            }
            Promise<DebugSessionDto> promise = service.getSessionInfo(debugSessionDto.getId());
            promise.then(new Operation<DebugSessionDto>() {

                @Override
                public void apply(DebugSessionDto arg) throws OperationException {
                    debuggerManager.setActiveDebugger(AbstractDebugger.this);
                    setDebugSession(arg);
                    DebuggerInfo debuggerInfo = arg.getDebuggerInfo();
                    String info = debuggerInfo.getName() + " " + debuggerInfo.getVersion();
                    String address = debuggerInfo.getHost() + ":" + debuggerInfo.getPort();
                    DebuggerDescriptor debuggerDescriptor = new DebuggerDescriptor(info, address);
                    JsPromise<Void> promise = Promises.resolve(null);
                    for (DebuggerObserver observer : observers) {
                        observer.onDebuggerAttached(debuggerDescriptor, promise);
                    }
                    startCheckingEvents();
                }
            }).catchError(new Operation<PromiseError>() {

                @Override
                public void apply(PromiseError arg) throws OperationException {
                    if (!isConnected()) {
                        invalidateDebugSession();
                    }
                }
            });
        }

        @Override
        public void onWsAgentStopped(WsAgentStateEvent event) {
        }
    });
    this.debuggerEventsHandler = new SubscriptionHandler<DebuggerEventDto>(new DebuggerEventUnmarshaller(dtoFactory)) {

        @Override
        public void onMessageReceived(DebuggerEventDto result) {
            if (!isConnected()) {
                return;
            }
            onEventListReceived(result);
        }

        @Override
        public void onErrorReceived(Throwable exception) {
            if (!isConnected()) {
                return;
            }
            try {
                messageBus.unsubscribe(eventChannel, this);
            } catch (WebSocketException e) {
                Log.error(AbstractDebugger.class, e);
            }
            if (exception instanceof ServerException) {
                ServerException serverException = (ServerException) exception;
                if (HTTPStatus.INTERNAL_ERROR == serverException.getHTTPStatus() && serverException.getMessage() != null && serverException.getMessage().contains("not found")) {
                    disconnect();
                }
            }
        }
    };
}
Also used : DebuggerInfo(org.eclipse.che.api.debug.shared.model.DebuggerInfo) ServerException(org.eclipse.che.ide.websocket.rest.exceptions.ServerException) WebSocketException(org.eclipse.che.ide.websocket.WebSocketException) WsAgentStateHandler(org.eclipse.che.ide.api.machine.events.WsAgentStateHandler) DebuggerDescriptor(org.eclipse.che.ide.debug.DebuggerDescriptor) JsPromise(org.eclipse.che.api.promises.client.js.JsPromise) Operation(org.eclipse.che.api.promises.client.Operation) JsPromise(org.eclipse.che.api.promises.client.js.JsPromise) Promise(org.eclipse.che.api.promises.client.Promise) DebuggerEventDto(org.eclipse.che.api.debug.shared.dto.event.DebuggerEventDto) JsPromiseError(org.eclipse.che.api.promises.client.js.JsPromiseError) PromiseError(org.eclipse.che.api.promises.client.PromiseError) DebugSessionDto(org.eclipse.che.api.debug.shared.dto.DebugSessionDto) WsAgentStateEvent(org.eclipse.che.ide.api.machine.events.WsAgentStateEvent) DebuggerObserver(org.eclipse.che.ide.debug.DebuggerObserver) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 2 with WsAgentStateEvent

use of org.eclipse.che.ide.api.machine.events.WsAgentStateEvent 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 WsAgentStateEvent

use of org.eclipse.che.ide.api.machine.events.WsAgentStateEvent in project che by eclipse.

the class ProcessesPanelPresenterTest method commandShouldBeRestoredWhenWsAgentIsStarted.

@Test
public void commandShouldBeRestoredWhenWsAgentIsStarted() throws Exception {
    WsAgentStateEvent event = mock(WsAgentStateEvent.class);
    MachineEntity machineEntity = mock(MachineEntity.class);
    MachineDto machine = mock(MachineDto.class);
    when(machineEntity.getId()).thenReturn(MACHINE_ID);
    when(machineEntity.getWorkspaceId()).thenReturn(WORKSPACE_ID);
    when(entityFactory.createMachine(machine)).thenReturn(machineEntity);
    MachineConfigDto machineConfigDto = mock(MachineConfigDto.class);
    when(machine.getConfig()).thenReturn(machineConfigDto);
    when(machineConfigDto.isDev()).thenReturn(true);
    when(machine.getStatus()).thenReturn(MachineStatus.RUNNING);
    List<MachineDto> machines = new ArrayList<>(2);
    machines.add(machine);
    when(workspaceRuntime.getMachines()).thenReturn(machines);
    MachineProcessDto machineProcessDto = mock(MachineProcessDto.class);
    when(machineProcessDto.getOutputChannel()).thenReturn(OUTPUT_CHANNEL);
    when(machineProcessDto.getPid()).thenReturn(PID);
    List<MachineProcessDto> processes = new ArrayList<>(1);
    processes.add(machineProcessDto);
    CommandOutputConsole outputConsole = mock(CommandOutputConsole.class);
    CommandType commandType = mock(CommandType.class);
    when(commandTypeRegistry.getCommandTypeById(anyString())).thenReturn(commandType);
    when(commandConsoleFactory.create(anyObject(), any(org.eclipse.che.api.core.model.machine.Machine.class))).thenReturn(outputConsole);
    presenter.onWsAgentStarted(event);
}
Also used : MachineEntity(org.eclipse.che.ide.api.machine.MachineEntity) ArrayList(java.util.ArrayList) MachineConfigDto(org.eclipse.che.api.machine.shared.dto.MachineConfigDto) MachineProcessDto(org.eclipse.che.api.machine.shared.dto.MachineProcessDto) DevMachine(org.eclipse.che.ide.api.machine.DevMachine) MachineDto(org.eclipse.che.api.machine.shared.dto.MachineDto) CommandType(org.eclipse.che.ide.api.command.CommandType) CommandOutputConsole(org.eclipse.che.ide.extension.machine.client.outputspanel.console.CommandOutputConsole) WsAgentStateEvent(org.eclipse.che.ide.api.machine.events.WsAgentStateEvent) Test(org.junit.Test)

Aggregations

WsAgentStateEvent (org.eclipse.che.ide.api.machine.events.WsAgentStateEvent)3 Operation (org.eclipse.che.api.promises.client.Operation)2 WsAgentStateHandler (org.eclipse.che.ide.api.machine.events.WsAgentStateHandler)2 WebSocketException (org.eclipse.che.ide.websocket.WebSocketException)2 ArrayList (java.util.ArrayList)1 DebugSessionDto (org.eclipse.che.api.debug.shared.dto.DebugSessionDto)1 DebuggerEventDto (org.eclipse.che.api.debug.shared.dto.event.DebuggerEventDto)1 DebuggerInfo (org.eclipse.che.api.debug.shared.model.DebuggerInfo)1 MachineConfigDto (org.eclipse.che.api.machine.shared.dto.MachineConfigDto)1 MachineDto (org.eclipse.che.api.machine.shared.dto.MachineDto)1 MachineProcessDto (org.eclipse.che.api.machine.shared.dto.MachineProcessDto)1 OperationException (org.eclipse.che.api.promises.client.OperationException)1 Promise (org.eclipse.che.api.promises.client.Promise)1 PromiseError (org.eclipse.che.api.promises.client.PromiseError)1 JsPromise (org.eclipse.che.api.promises.client.js.JsPromise)1 JsPromiseError (org.eclipse.che.api.promises.client.js.JsPromiseError)1 CommandType (org.eclipse.che.ide.api.command.CommandType)1 DevMachine (org.eclipse.che.ide.api.machine.DevMachine)1 MachineEntity (org.eclipse.che.ide.api.machine.MachineEntity)1 WorkspaceStoppedEvent (org.eclipse.che.ide.api.workspace.event.WorkspaceStoppedEvent)1