Search in sources :

Example 1 with WorkspaceStartedEvent

use of org.eclipse.che.ide.api.workspace.event.WorkspaceStartedEvent in project che by eclipse.

the class MachinePanelPresenterTest method shouldSubscribeToMachineStateEvent.

@Test
public void shouldSubscribeToMachineStateEvent() {
    WorkspaceStartedEvent event = mock(WorkspaceStartedEvent.class);
    when(event.getWorkspace()).thenReturn(usersWorkspace);
    presenter.onWorkspaceStarted(event);
    verify(eventBus).addHandler(MachineStateEvent.TYPE, presenter);
}
Also used : WorkspaceStartedEvent(org.eclipse.che.ide.api.workspace.event.WorkspaceStartedEvent) Test(org.junit.Test)

Example 2 with WorkspaceStartedEvent

use of org.eclipse.che.ide.api.workspace.event.WorkspaceStartedEvent in project che by eclipse.

the class BootstrapController method startWsAgentComponents.

@Inject
private void startWsAgentComponents(EventBus eventBus, final Map<String, Provider<WsAgentComponent>> components) {
    eventBus.addHandler(WorkspaceStartedEvent.TYPE, new WorkspaceStartedEvent.Handler() {

        @Override
        public void onWorkspaceStarted(WorkspaceStartedEvent event) {
            workspaceService.getWorkspace(event.getWorkspace().getId()).then(new Operation<WorkspaceDto>() {

                @Override
                public void apply(WorkspaceDto ws) throws OperationException {
                    MachineDto devMachineDto = ws.getRuntime().getDevMachine();
                    DevMachine devMachine = new DevMachine(devMachineDto);
                    if (appContext instanceof AppContextImpl) {
                        ((AppContextImpl) appContext).setProjectsRoot(Path.valueOf(devMachineDto.getRuntime().projectsRoot()));
                    }
                    wsAgentStateControllerProvider.get().initialize(devMachine);
                    wsAgentURLModifier.initialize(devMachine);
                    SortedMap<String, Provider<WsAgentComponent>> sortedComponents = new TreeMap<>();
                    sortedComponents.putAll(components);
                    startWsAgentComponents(sortedComponents.values().iterator());
                }
            }).catchError(new Operation<PromiseError>() {

                @Override
                public void apply(PromiseError err) throws OperationException {
                    Log.error(getClass(), err.getCause());
                    initializationFailed(err.getMessage());
                }
            });
        }
    });
}
Also used : DevMachine(org.eclipse.che.ide.api.machine.DevMachine) WorkspaceStartedEvent(org.eclipse.che.ide.api.workspace.event.WorkspaceStartedEvent) WorkspaceDto(org.eclipse.che.api.workspace.shared.dto.WorkspaceDto) Operation(org.eclipse.che.api.promises.client.Operation) AppContextImpl(org.eclipse.che.ide.context.AppContextImpl) MachineDto(org.eclipse.che.api.machine.shared.dto.MachineDto) PromiseError(org.eclipse.che.api.promises.client.PromiseError) SortedMap(java.util.SortedMap) WsAgentComponent(org.eclipse.che.ide.api.component.WsAgentComponent) OperationException(org.eclipse.che.api.promises.client.OperationException) Inject(com.google.inject.Inject)

Example 3 with WorkspaceStartedEvent

use of org.eclipse.che.ide.api.workspace.event.WorkspaceStartedEvent in project che by eclipse.

the class WorkspaceComponent method handleWorkspaceEvents.

/**
     * Listens message bus and handles workspace events.
     *
     * @param workspace
     *         workspace to listen
     * @param callback
     *         callback
     * @param restoreFromSnapshot
     *         restore or not the workspace from snapshot
     */
public void handleWorkspaceEvents(final WorkspaceDto workspace, final Callback<Component, Exception> callback, final Boolean restoreFromSnapshot) {
    this.callback = callback;
    if (messageBus != null) {
        messageBus.cancelReconnection();
    }
    messageBus = messageBusProvider.createMessageBus();
    messageBus.addOnOpenHandler(new ConnectionOpenedHandler() {

        @Override
        public void onOpen() {
            loader.show(STARTING_WORKSPACE_RUNTIME);
            messageBus.removeOnOpenHandler(this);
            setCurrentWorkspace(workspace);
            workspaceEventsHandler.trackWorkspaceEvents(workspace, callback);
            final WorkspaceStatus workspaceStatus = workspace.getStatus();
            switch(workspaceStatus) {
                case SNAPSHOTTING:
                    loader.show(CREATING_WORKSPACE_SNAPSHOT);
                    break;
                case STARTING:
                    eventBus.fireEvent(new WorkspaceStartingEvent(workspace));
                    break;
                case RUNNING:
                    Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {

                        @Override
                        public void execute() {
                            loader.setSuccess(STARTING_WORKSPACE_RUNTIME);
                            eventBus.fireEvent(new WorkspaceStartedEvent(workspace));
                        }
                    });
                    break;
                default:
                    //
                    workspaceServiceClient.getSettings().then(new Function<Map<String, String>, Map<String, String>>() {

                        @Override
                        public Map<String, String> apply(Map<String, String> settings) throws FunctionException {
                            if (Boolean.parseBoolean(settings.getOrDefault(CHE_WORKSPACE_AUTO_START, "true"))) {
                                startWorkspaceById(workspace.getId(), workspace.getConfig().getDefaultEnv(), restoreFromSnapshot);
                            } else {
                                loader.show(WORKSPACE_STOPPED);
                            }
                            return settings;
                        }
                    });
            }
        }
    });
}
Also used : ConnectionOpenedHandler(org.eclipse.che.ide.websocket.events.ConnectionOpenedHandler) Function(org.eclipse.che.api.promises.client.Function) WorkspaceStartedEvent(org.eclipse.che.ide.api.workspace.event.WorkspaceStartedEvent) WorkspaceStatus(org.eclipse.che.api.core.model.workspace.WorkspaceStatus) WorkspaceStartingEvent(org.eclipse.che.ide.api.workspace.event.WorkspaceStartingEvent) Map(java.util.Map)

Aggregations

WorkspaceStartedEvent (org.eclipse.che.ide.api.workspace.event.WorkspaceStartedEvent)3 Inject (com.google.inject.Inject)1 Map (java.util.Map)1 SortedMap (java.util.SortedMap)1 WorkspaceStatus (org.eclipse.che.api.core.model.workspace.WorkspaceStatus)1 MachineDto (org.eclipse.che.api.machine.shared.dto.MachineDto)1 Function (org.eclipse.che.api.promises.client.Function)1 Operation (org.eclipse.che.api.promises.client.Operation)1 OperationException (org.eclipse.che.api.promises.client.OperationException)1 PromiseError (org.eclipse.che.api.promises.client.PromiseError)1 WorkspaceDto (org.eclipse.che.api.workspace.shared.dto.WorkspaceDto)1 WsAgentComponent (org.eclipse.che.ide.api.component.WsAgentComponent)1 DevMachine (org.eclipse.che.ide.api.machine.DevMachine)1 WorkspaceStartingEvent (org.eclipse.che.ide.api.workspace.event.WorkspaceStartingEvent)1 AppContextImpl (org.eclipse.che.ide.context.AppContextImpl)1 ConnectionOpenedHandler (org.eclipse.che.ide.websocket.events.ConnectionOpenedHandler)1 Test (org.junit.Test)1