Search in sources :

Example 1 with DaemonDir

use of org.gradle.launcher.daemon.registry.DaemonDir 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>() {

                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;
}
Also used : DaemonContext(org.gradle.launcher.daemon.context.DaemonContext) DaemonInfo(org.gradle.launcher.daemon.registry.DaemonInfo) File(java.io.File) DaemonDir(org.gradle.launcher.daemon.registry.DaemonDir) DaemonExpirationResult(org.gradle.launcher.daemon.server.expiry.DaemonExpirationResult)

Aggregations

File (java.io.File)1 DaemonContext (org.gradle.launcher.daemon.context.DaemonContext)1 DaemonDir (org.gradle.launcher.daemon.registry.DaemonDir)1 DaemonInfo (org.gradle.launcher.daemon.registry.DaemonInfo)1 DaemonExpirationResult (org.gradle.launcher.daemon.server.expiry.DaemonExpirationResult)1