Search in sources :

Example 1 with WorkspaceStartingEvent

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

the class WorkspaceEventsHandler method onWorkspaceStarting.

private void onWorkspaceStarting(final String workspaceId) {
    // TODO timer is a workaround. Is needed because for some reason after receiving of event workspace starting
    // get workspace event should contain runtime but it doesn't
    new Timer() {

        @Override
        public void run() {
            workspaceServiceClient.getWorkspace(workspaceId).then(new Operation<WorkspaceDto>() {

                @Override
                public void apply(WorkspaceDto workspace) throws OperationException {
                    String devMachineName = getDevMachineName(workspace);
                    if (devMachineName != null) {
                        subscribeOnWsAgentOutputChannel(workspace, devMachineName);
                    }
                    workspaceComponent.setCurrentWorkspace(workspace);
                    loader.show(LoaderPresenter.Phase.STARTING_WORKSPACE_RUNTIME);
                    eventBus.fireEvent(new WorkspaceStartingEvent(workspace));
                }
            });
        }
    }.schedule(1000);
}
Also used : Timer(com.google.gwt.user.client.Timer) WorkspaceDto(org.eclipse.che.api.workspace.shared.dto.WorkspaceDto) Operation(org.eclipse.che.api.promises.client.Operation) WorkspaceStartingEvent(org.eclipse.che.ide.api.workspace.event.WorkspaceStartingEvent)

Example 2 with WorkspaceStartingEvent

use of org.eclipse.che.ide.api.workspace.event.WorkspaceStartingEvent 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

WorkspaceStartingEvent (org.eclipse.che.ide.api.workspace.event.WorkspaceStartingEvent)2 Timer (com.google.gwt.user.client.Timer)1 Map (java.util.Map)1 WorkspaceStatus (org.eclipse.che.api.core.model.workspace.WorkspaceStatus)1 Function (org.eclipse.che.api.promises.client.Function)1 Operation (org.eclipse.che.api.promises.client.Operation)1 WorkspaceDto (org.eclipse.che.api.workspace.shared.dto.WorkspaceDto)1 WorkspaceStartedEvent (org.eclipse.che.ide.api.workspace.event.WorkspaceStartedEvent)1 ConnectionOpenedHandler (org.eclipse.che.ide.websocket.events.ConnectionOpenedHandler)1