Search in sources :

Example 1 with Result

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

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

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

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

the class ReturnResult method execute.

@Override
public void execute(DaemonCommandExecution execution) {
    execution.proceed();
    Result result = new Success(execution.getResult());
    LOGGER.debug("Daemon is dispatching the build result: {}", result);
    execution.getConnection().completed(result);
}
Also used : Success(org.gradle.launcher.daemon.protocol.Success) Result(org.gradle.launcher.daemon.protocol.Result)

Aggregations

Result (org.gradle.launcher.daemon.protocol.Result)4 Failure (org.gradle.launcher.daemon.protocol.Failure)3 Finished (org.gradle.launcher.daemon.protocol.Finished)3 Success (org.gradle.launcher.daemon.protocol.Success)2 BuildCancelledException (org.gradle.api.BuildCancelledException)1 DaemonDiagnostics (org.gradle.launcher.daemon.diagnostics.DaemonDiagnostics)1 BuildStarted (org.gradle.launcher.daemon.protocol.BuildStarted)1 DaemonUnavailable (org.gradle.launcher.daemon.protocol.DaemonUnavailable)1 Status (org.gradle.launcher.daemon.protocol.Status)1 DaemonStoppedException (org.gradle.launcher.daemon.server.api.DaemonStoppedException)1 BuildActionResult (org.gradle.launcher.exec.BuildActionResult)1