use of org.gradle.launcher.daemon.registry.DaemonInfo in project gradle by gradle.
the class DaemonRegistryUnavailableExpirationStrategy method checkExpiration.
@Override
public DaemonExpirationResult checkExpiration() {
try {
final DaemonContext daemonContext = daemon.getDaemonContext();
final File daemonRegistryDir = daemonContext.getDaemonRegistryDir();
if (!new DaemonDir(daemonRegistryDir).getRegistry().canRead()) {
LOG.warn("Daemon registry {} became unreadable. Expiring daemon.", daemonRegistryDir);
return new DaemonExpirationResult(GRACEFUL_EXPIRE, REGISTRY_BECAME_UNREADABLE);
} else {
// Check that given daemon still exists in registry - a daemon registry could be removed and recreated between checks
List<Long> allDaemonPids = Lists.transform(daemon.getDaemonRegistry().getAll(), new Function<DaemonInfo, Long>() {
@Override
public Long apply(DaemonInfo info) {
return info.getPid();
}
});
if (!allDaemonPids.contains(daemonContext.getPid())) {
return new DaemonExpirationResult(GRACEFUL_EXPIRE, REGISTRY_ENTRY_UNEXPECTEDLY_LOST);
}
}
} catch (SecurityException se) {
LOG.warn("Daemon registry became inaccessible. Expiring daemon. Error message is '{}'", se.getMessage());
return new DaemonExpirationResult(GRACEFUL_EXPIRE, REGISTRY_BECAME_INACCESSIBLE);
}
return DaemonExpirationResult.NOT_TRIGGERED;
}
use of org.gradle.launcher.daemon.registry.DaemonInfo in project gradle by gradle.
the class DaemonRegistryUpdater method onStart.
public void onStart(Address connectorAddress) {
LOGGER.info("{}{}", DaemonMessages.ADVERTISING_DAEMON, connectorAddress);
LOGGER.debug("Advertised daemon context: {}", daemonContext);
this.connectorAddress = connectorAddress;
daemonRegistry.store(new DaemonInfo(connectorAddress, daemonContext, token, Busy));
}
use of org.gradle.launcher.daemon.registry.DaemonInfo in project gradle by gradle.
the class ReportDaemonStatusClient method listAll.
public void listAll() {
final List<DaemonInfo> daemons = daemonRegistry.getAll();
final List<Status> statuses = Lists.newArrayList();
for (DaemonInfo daemon : daemons) {
DaemonClientConnection connection = connector.maybeConnect(daemon);
if (connection != null) {
try {
final ReportStatus statusCommand = new ReportStatus(idGenerator.generateId(), daemon.getToken());
final Status status = reportStatusDispatcher.dispatch(connection, statusCommand);
if (status != null) {
statuses.add(status);
} else {
// Handle failure
statuses.add(new Status(connection.getDaemon().getPid(), "UNKNOWN", "UNKNOWN"));
}
} finally {
connection.stop();
}
}
}
final List<DaemonStopEvent> stopEvents = DaemonStopEvents.uniqueRecentDaemonStopEvents(daemonRegistry.getStopEvents());
if (statuses.isEmpty()) {
LOGGER.quiet(DaemonMessages.NO_DAEMONS_RUNNING);
}
if (!(statuses.isEmpty() && stopEvents.isEmpty())) {
LOGGER.quiet(String.format(STATUS_FORMAT, "PID", "STATUS", "INFO"));
}
printRunningDaemons(statuses);
printStoppedDaemons(stopEvents);
LOGGER.quiet("");
LOGGER.quiet(STATUS_FOOTER + " See " + documentationRegistry.getDocumentationFor("gradle_daemon", "sec:status"));
}
use of org.gradle.launcher.daemon.registry.DaemonInfo in project gradle by gradle.
the class DefaultDaemonConnector method connectToCanceledDaemon.
private DaemonClientConnection connectToCanceledDaemon(Collection<DaemonInfo> busyDaemons, ExplainingSpec<DaemonContext> constraint) {
DaemonClientConnection connection = null;
final Pair<Collection<DaemonInfo>, Collection<DaemonInfo>> canceledBusy = partitionByState(busyDaemons, Canceled);
final Collection<DaemonInfo> compatibleCanceledDaemons = getCompatibleDaemons(canceledBusy.getLeft(), constraint);
if (!compatibleCanceledDaemons.isEmpty()) {
LOGGER.info(DaemonMessages.WAITING_ON_CANCELED);
CountdownTimer timer = Time.startCountdownTimer(CANCELED_WAIT_TIMEOUT);
while (connection == null && !timer.hasExpired()) {
try {
sleep(200);
connection = connectToIdleDaemon(daemonRegistry.getIdle(), constraint);
} catch (InterruptedException e) {
throw UncheckedException.throwAsUncheckedException(e);
}
}
}
return connection;
}
use of org.gradle.launcher.daemon.registry.DaemonInfo in project gradle by gradle.
the class NotifyDaemonAboutChangedPathsClient method notifyDaemonsAboutChangedPaths.
public void notifyDaemonsAboutChangedPaths(List<String> changedPaths) {
for (DaemonInfo daemonInfo : daemonRegistry.getAll()) {
DaemonStateControl.State state = daemonInfo.getState();
if (state == Idle || state == Busy || state == Canceled) {
DaemonClientConnection connection = connector.maybeConnect(daemonInfo);
if (connection == null) {
continue;
}
dispatch(connection, new InvalidateVirtualFileSystem(changedPaths, idGenerator.generateId(), connection.getDaemon().getToken()));
}
}
}
Aggregations