use of org.gradle.launcher.daemon.diagnostics.DaemonDiagnostics in project gradle by gradle.
the class DaemonServices method createDaemonCommandActions.
protected ImmutableList<DaemonCommandAction> createDaemonCommandActions(DaemonContext daemonContext, ProcessEnvironment processEnvironment, DaemonHealthStats healthStats, DaemonHealthCheck healthCheck, BuildExecuter buildActionExecuter, DaemonRunningStats runningStats) {
File daemonLog = getDaemonLogFile();
DaemonDiagnostics daemonDiagnostics = new DaemonDiagnostics(daemonLog, daemonContext.getPid());
return ImmutableList.of(new HandleStop(get(ListenerManager.class)), new HandleCancel(), new HandleReportStatus(), new ReturnResult(), // from this point down, the daemon is 'busy'
new StartBuildOrRespondWithBusy(daemonDiagnostics), new EstablishBuildEnvironment(processEnvironment), // from this point down, logging is sent back to the client
new LogToClient(loggingManager, daemonDiagnostics), new LogAndCheckHealth(healthStats, healthCheck), new ForwardClientInput(), new RequestStopIfSingleUsedDaemon(), new ResetDeprecationLogger(), new WatchForDisconnection(), new ExecuteBuild(buildActionExecuter, runningStats, this));
}
use of org.gradle.launcher.daemon.diagnostics.DaemonDiagnostics in project gradle by gradle.
the class DaemonStartupCommunication method readDiagnostics.
public DaemonStartupInfo readDiagnostics(String message) {
//Assuming the message has correct format. Not bullet proof, but seems to work ok for now.
if (!message.startsWith(daemonGreeting())) {
throw new IllegalArgumentException(String.format("Unexpected daemon startup message: %s", message));
}
try {
String encoded = message.substring(daemonGreeting().length()).trim();
InputStream inputStream = new EncodedStream.EncodedInput(new ByteArrayInputStream(encoded.getBytes()));
Decoder decoder = new InputStreamBackedDecoder(inputStream);
String pidString = decoder.readNullableString();
String uid = decoder.readString();
Long pid = pidString == null ? null : Long.valueOf(pidString);
Address address = new MultiChoiceAddressSerializer().read(decoder);
File daemonLog = new File(decoder.readString());
return new DaemonStartupInfo(uid, address, new DaemonDiagnostics(daemonLog, pid));
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
use of org.gradle.launcher.daemon.diagnostics.DaemonDiagnostics in project gradle by gradle.
the class DaemonClient method executeBuild.
protected Object executeBuild(Build build, DaemonClientConnection connection, BuildCancellationToken cancellationToken, BuildEventConsumer buildEventConsumer) throws DaemonInitialConnectException {
Object result;
try {
LOGGER.info("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) {
throw new DaemonInitialConnectException("The first result from the daemon was empty. Most likely the process died immediately after connection.");
}
LOGGER.info("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.info("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()) {
LOGGER.error("Daemon was stopped to handle build cancel request.");
throw new BuildCancelledException();
}
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 ((Result) result).getValue();
} else {
throw invalidResponse(result, build, diagnostics);
}
}
Aggregations