Search in sources :

Example 1 with DaemonStoppedException

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);
    }
}
Also used : Finished(org.gradle.launcher.daemon.protocol.Finished) DaemonUnavailable(org.gradle.launcher.daemon.protocol.DaemonUnavailable) BuildActionResult(org.gradle.launcher.exec.BuildActionResult) Result(org.gradle.launcher.daemon.protocol.Result) DaemonStoppedException(org.gradle.launcher.daemon.server.api.DaemonStoppedException) DaemonDiagnostics(org.gradle.launcher.daemon.diagnostics.DaemonDiagnostics) BuildStarted(org.gradle.launcher.daemon.protocol.BuildStarted) BuildActionResult(org.gradle.launcher.exec.BuildActionResult) BuildCancelledException(org.gradle.api.BuildCancelledException) Failure(org.gradle.launcher.daemon.protocol.Failure)

Example 2 with DaemonStoppedException

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));
    }
}
Also used : DaemonStoppedException(org.gradle.launcher.daemon.server.api.DaemonStoppedException) DaemonStateControl(org.gradle.launcher.daemon.server.api.DaemonStateControl) DaemonUnavailable(org.gradle.launcher.daemon.protocol.DaemonUnavailable) BuildStarted(org.gradle.launcher.daemon.protocol.BuildStarted) DaemonUnavailableException(org.gradle.launcher.daemon.server.api.DaemonUnavailableException) Failure(org.gradle.launcher.daemon.protocol.Failure)

Aggregations

BuildStarted (org.gradle.launcher.daemon.protocol.BuildStarted)2 DaemonUnavailable (org.gradle.launcher.daemon.protocol.DaemonUnavailable)2 Failure (org.gradle.launcher.daemon.protocol.Failure)2 DaemonStoppedException (org.gradle.launcher.daemon.server.api.DaemonStoppedException)2 BuildCancelledException (org.gradle.api.BuildCancelledException)1 DaemonDiagnostics (org.gradle.launcher.daemon.diagnostics.DaemonDiagnostics)1 Finished (org.gradle.launcher.daemon.protocol.Finished)1 Result (org.gradle.launcher.daemon.protocol.Result)1 DaemonStateControl (org.gradle.launcher.daemon.server.api.DaemonStateControl)1 DaemonUnavailableException (org.gradle.launcher.daemon.server.api.DaemonUnavailableException)1 BuildActionResult (org.gradle.launcher.exec.BuildActionResult)1