/** * Blocks starting new workspaces and waits until all workspaces that are currently in a * starting/stopping state to finish this process * * @throws InterruptedException * @throws UnsupportedOperationException */ @Override public void suspend() throws InterruptedException, UnsupportedOperationException { try { runtimeInfrastructure.getIdentities(); } catch (UnsupportedOperationException | InfrastructureException e) { throw new UnsupportedOperationException("Current infrastructure does not support suspend."); } Preconditions.checkState(runtimes.refuseStart()); WorkspaceSuspendedEventsPropagator propagator = new WorkspaceSuspendedEventsPropagator(); eventService.subscribe(propagator); try { waitAllWorkspacesRunningOrStopped(); sharedPool.shutdown(); } finally { eventService.unsubscribe(propagator); } try { workspaceRemover.shutdown(); } catch (Exception ignored) { } }
/** * Blocks starting new workspaces and stops all that already running * * @throws InterruptedException */ @Override public void terminate() throws InterruptedException { Preconditions.checkState(runtimes.refuseStart()); WorkspaceStoppedEventsPropagator propagator = new WorkspaceStoppedEventsPropagator(); eventService.subscribe(propagator); try { stopRunningAndStartingWorkspacesAsync(); waitAllWorkspacesStopped(); sharedPool.shutdown(); } finally { eventService.unsubscribe(propagator); } try { workspaceRemover.shutdown(); } catch (Exception ignored) { } }