Search in sources :

Example 1 with Failure

use of org.gradle.launcher.daemon.protocol.Failure in project gradle by gradle.

the class NotifyDaemonAboutChangedPathsClient method dispatch.

private static void dispatch(Connection<Message> connection, Command command) {
    Throwable failure = null;
    try {
        connection.dispatch(command);
        Result result = (Result) connection.receive();
        if (result instanceof Failure) {
            failure = ((Failure) result).getValue();
        }
        connection.dispatch(new Finished());
    } catch (Throwable e) {
        failure = e;
    }
    if (failure != null) {
        throw UncheckedException.throwAsUncheckedException(failure);
    }
}
Also used : Finished(org.gradle.launcher.daemon.protocol.Finished) Failure(org.gradle.launcher.daemon.protocol.Failure) Result(org.gradle.launcher.daemon.protocol.Result)

Example 2 with Failure

use of org.gradle.launcher.daemon.protocol.Failure 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 3 with Failure

use of org.gradle.launcher.daemon.protocol.Failure in project gradle by gradle.

the class ReportStatusDispatcher method dispatch.

public Status dispatch(Connection<Message> connection, Command statusCommand) {
    Status returnedStatus = null;
    Throwable failure = null;
    try {
        connection.dispatch(statusCommand);
        Result result = (Result) connection.receive();
        if (result instanceof Failure) {
            failure = ((Failure) result).getValue();
        } else if (result instanceof Success) {
            returnedStatus = (Status) result.getValue();
        }
        connection.dispatch(new Finished());
    } catch (Throwable e) {
        failure = e;
    }
    if (failure != null) {
        LOGGER.debug(String.format("Unable to get status of %s.", connection), failure);
    }
    return returnedStatus;
}
Also used : Status(org.gradle.launcher.daemon.protocol.Status) Finished(org.gradle.launcher.daemon.protocol.Finished) Failure(org.gradle.launcher.daemon.protocol.Failure) Success(org.gradle.launcher.daemon.protocol.Success) Result(org.gradle.launcher.daemon.protocol.Result)

Example 4 with Failure

use of org.gradle.launcher.daemon.protocol.Failure 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

Failure (org.gradle.launcher.daemon.protocol.Failure)4 Finished (org.gradle.launcher.daemon.protocol.Finished)3 Result (org.gradle.launcher.daemon.protocol.Result)3 BuildStarted (org.gradle.launcher.daemon.protocol.BuildStarted)2 DaemonUnavailable (org.gradle.launcher.daemon.protocol.DaemonUnavailable)2 DaemonStoppedException (org.gradle.launcher.daemon.server.api.DaemonStoppedException)2 BuildCancelledException (org.gradle.api.BuildCancelledException)1 DaemonDiagnostics (org.gradle.launcher.daemon.diagnostics.DaemonDiagnostics)1 Status (org.gradle.launcher.daemon.protocol.Status)1 Success (org.gradle.launcher.daemon.protocol.Success)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