use of org.gradle.launcher.daemon.server.expiry.DaemonExpirationResult 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.server.expiry.DaemonExpirationResult in project gradle by gradle.
the class HandleStop method execute.
@Override
public void execute(DaemonCommandExecution execution) {
if (execution.getCommand() instanceof Stop) {
listenerBroadcast.onExpirationEvent(new DaemonExpirationResult(DaemonExpirationStatus.IMMEDIATE_EXPIRE, EXPIRATION_REASON));
execution.getConnection().completed(new Success(null));
} else if (execution.getCommand() instanceof StopWhenIdle) {
hangShutdownForTesting();
listenerBroadcast.onExpirationEvent(new DaemonExpirationResult(DaemonExpirationStatus.GRACEFUL_EXPIRE, EXPIRATION_REASON));
execution.getConnection().completed(new Success(null));
} else {
execution.proceed();
}
}
use of org.gradle.launcher.daemon.server.expiry.DaemonExpirationResult in project gradle by gradle.
the class DefaultDaemonScanInfo method notifyOnUnhealthy.
@Override
public void notifyOnUnhealthy(final Action<? super String> listener) {
/*
The semantics of this method are that the given action should be notified if the
Daemon is going to be terminated at the end of this build.
It is not a generic outlet for “expiry events”.
Ideally, the value given would describe the problem and not be phrased in terms of why we are shutting down,
but this is a practical compromise born out of piggy backing on the expiration listener mechanism to implement it.
*/
final AtomicReference<DaemonExpirationListener> daemonExpirationListenerReference = new AtomicReference<DaemonExpirationListener>();
final DaemonExpirationListener daemonExpirationListener = new DaemonExpirationListener() {
@Override
public void onExpirationEvent(DaemonExpirationResult result) {
if (result.getStatus() == DaemonExpirationStatus.GRACEFUL_EXPIRE) {
try {
listener.execute(result.getReason());
} finally {
// set the reference to null, which says that we're taking care of removing the listener
if (daemonExpirationListenerReference.getAndSet(null) != null) {
listenerManager.removeListener(this);
}
}
}
}
};
daemonExpirationListenerReference.set(daemonExpirationListener);
listenerManager.addListener(daemonExpirationListener);
final BuildAdapter buildListener = new InternalBuildAdapter() {
@Override
public void buildFinished(BuildResult result) {
DaemonExpirationListener daemonExpirationListener = daemonExpirationListenerReference.getAndSet(null);
if (daemonExpirationListener != null) {
listenerManager.removeListener(daemonExpirationListener);
}
listenerManager.removeListener(this);
}
};
listenerManager.addListener(buildListener);
}
Aggregations