use of org.gradle.api.internal.specs.ExplainingSpec in project gradle by gradle.
the class DaemonStopClient method stop.
/**
* Stops all daemons, blocking until all have completed.
*/
public void stop() {
CountdownTimer timer = Time.startCountdownTimer(STOP_TIMEOUT_SECONDS, TimeUnit.SECONDS);
final Set<String> seen = new HashSet<String>();
ExplainingSpec<DaemonContext> spec = new ExplainingSpec<DaemonContext>() {
@Override
public String whyUnsatisfied(DaemonContext element) {
return "already seen";
}
@Override
public boolean isSatisfiedBy(DaemonContext element) {
return !seen.contains(element.getUid());
}
};
DaemonClientConnection connection = connector.maybeConnect(spec);
if (connection == null) {
LOGGER.lifecycle(DaemonMessages.NO_DAEMONS_RUNNING);
return;
}
LOGGER.lifecycle("Stopping Daemon(s)");
// iterate and stop all daemons
int numStopped = 0;
while (connection != null && !timer.hasExpired()) {
try {
seen.add(connection.getDaemon().getUid());
LOGGER.debug("Requesting daemon {} stop now", connection.getDaemon());
boolean stopped = stopDispatcher.dispatch(connection, new Stop(idGenerator.generateId(), connection.getDaemon().getToken()));
if (stopped) {
numStopped++;
}
} finally {
connection.stop();
}
connection = connector.maybeConnect(spec);
}
if (numStopped > 0) {
LOGGER.lifecycle(numStopped + " Daemon" + ((numStopped > 1) ? "s" : "") + " stopped");
}
if (connection != null) {
throw new GradleException(String.format("Timeout waiting for all daemons to stop. Waited %s.", timer.getElapsed()));
}
}
Aggregations