use of org.gradle.launcher.daemon.server.api.DaemonStoppedException in project gradle by gradle.
the class DaemonClient method executeBuild.
protected BuildActionResult executeBuild(Build build, DaemonClientConnection connection, BuildCancellationToken cancellationToken, BuildEventConsumer buildEventConsumer) throws DaemonInitialConnectException {
Object result;
try {
LOGGER.debug("Connected to daemon {}. Dispatching request {}.", connection.getDaemon(), build);
connection.dispatch(build);
result = connection.receive();
} catch (StaleDaemonAddressException e) {
LOGGER.debug("Connected to a stale daemon address.", e);
// However, since we haven't yet started running the build, we can recover by just trying again.
throw new DaemonInitialConnectException("Connected to a stale daemon address.", e);
}
if (result == null) {
// If the response from the daemon is unintelligible, mark the daemon as unavailable so other
// clients won't try to communicate with it. We'll attempt to recovery by trying again.
connector.markDaemonAsUnavailable(connection.getDaemon());
throw new DaemonInitialConnectException("The first result from the daemon was empty. The daemon process may have died or a non-daemon process is reusing the same port.");
}
LOGGER.debug("Received result {} from daemon {} (build should be starting).", result, connection.getDaemon());
DaemonDiagnostics diagnostics = null;
if (result instanceof BuildStarted) {
diagnostics = ((BuildStarted) result).getDiagnostics();
result = monitorBuild(build, diagnostics, connection, cancellationToken, buildEventConsumer);
}
LOGGER.debug("Received result {} from daemon {} (build should be done).", result, connection.getDaemon());
connection.dispatch(new Finished());
if (result instanceof Failure) {
Throwable failure = ((Failure) result).getValue();
if (failure instanceof DaemonStoppedException && cancellationToken.isCancellationRequested()) {
return BuildActionResult.cancelled(new BuildCancelledException("Daemon was stopped to handle build cancel request.", failure));
}
throw UncheckedException.throwAsUncheckedException(failure);
} else if (result instanceof DaemonUnavailable) {
throw new DaemonInitialConnectException("The daemon we connected to was unavailable: " + ((DaemonUnavailable) result).getReason());
} else if (result instanceof Result) {
return (BuildActionResult) ((Result) result).getValue();
} else {
throw invalidResponse(result, build, diagnostics);
}
}
use of org.gradle.launcher.daemon.server.api.DaemonStoppedException in project gradle by gradle.
the class StartBuildOrRespondWithBusy method doBuild.
@Override
protected void doBuild(final DaemonCommandExecution execution, final Build build) {
DaemonStateControl stateCoordinator = execution.getDaemonStateControl();
try {
Runnable command = new Runnable() {
@Override
public void run() {
LOGGER.info("Daemon is about to start building {}. Dispatching build started information...", build);
execution.getConnection().buildStarted(new BuildStarted(diagnostics));
execution.proceed();
}
};
stateCoordinator.runCommand(command, execution.toString());
} catch (DaemonUnavailableException e) {
LOGGER.info("Daemon will not handle the command {} because is unavailable: {}", build, e.getMessage());
execution.getConnection().daemonUnavailable(new DaemonUnavailable(e.getMessage()));
} catch (DaemonStoppedException e) {
execution.getConnection().completed(new Failure(e));
}
}
Aggregations