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);
}
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;
}
});
}
}
});
}
Aggregations