Search in sources :

Example 1 with DaemonExpirationResult

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;
}
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)

Example 2 with DaemonExpirationResult

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();
    }
}
Also used : Stop(org.gradle.launcher.daemon.protocol.Stop) StopWhenIdle(org.gradle.launcher.daemon.protocol.StopWhenIdle) DaemonExpirationResult(org.gradle.launcher.daemon.server.expiry.DaemonExpirationResult) Success(org.gradle.launcher.daemon.protocol.Success)

Example 3 with DaemonExpirationResult

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);
}
Also used : BuildResult(org.gradle.BuildResult) AtomicReference(java.util.concurrent.atomic.AtomicReference) BuildAdapter(org.gradle.BuildAdapter) InternalBuildAdapter(org.gradle.internal.InternalBuildAdapter) DaemonExpirationResult(org.gradle.launcher.daemon.server.expiry.DaemonExpirationResult) InternalBuildAdapter(org.gradle.internal.InternalBuildAdapter) DaemonExpirationListener(org.gradle.launcher.daemon.server.expiry.DaemonExpirationListener)

Aggregations

DaemonExpirationResult (org.gradle.launcher.daemon.server.expiry.DaemonExpirationResult)3 File (java.io.File)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 BuildAdapter (org.gradle.BuildAdapter)1 BuildResult (org.gradle.BuildResult)1 InternalBuildAdapter (org.gradle.internal.InternalBuildAdapter)1 DaemonContext (org.gradle.launcher.daemon.context.DaemonContext)1 Stop (org.gradle.launcher.daemon.protocol.Stop)1 StopWhenIdle (org.gradle.launcher.daemon.protocol.StopWhenIdle)1 Success (org.gradle.launcher.daemon.protocol.Success)1 DaemonDir (org.gradle.launcher.daemon.registry.DaemonDir)1 DaemonInfo (org.gradle.launcher.daemon.registry.DaemonInfo)1 DaemonExpirationListener (org.gradle.launcher.daemon.server.expiry.DaemonExpirationListener)1