Search in sources :

Example 1 with DaemonInfo

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

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));
}
Also used : DaemonInfo(org.gradle.launcher.daemon.registry.DaemonInfo)

Example 3 with DaemonInfo

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"));
}
Also used : ReportStatus(org.gradle.launcher.daemon.protocol.ReportStatus) Status(org.gradle.launcher.daemon.protocol.Status) DaemonStopEvent(org.gradle.launcher.daemon.registry.DaemonStopEvent) DaemonInfo(org.gradle.launcher.daemon.registry.DaemonInfo) ReportStatus(org.gradle.launcher.daemon.protocol.ReportStatus)

Example 4 with DaemonInfo

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;
}
Also used : CountdownTimer(org.gradle.internal.time.CountdownTimer) Collection(java.util.Collection) DaemonInfo(org.gradle.launcher.daemon.registry.DaemonInfo)

Example 5 with DaemonInfo

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()));
        }
    }
}
Also used : DaemonStateControl(org.gradle.launcher.daemon.server.api.DaemonStateControl) DaemonInfo(org.gradle.launcher.daemon.registry.DaemonInfo) InvalidateVirtualFileSystem(org.gradle.launcher.daemon.protocol.InvalidateVirtualFileSystem)

Aggregations

DaemonInfo (org.gradle.launcher.daemon.registry.DaemonInfo)6 File (java.io.File)1 Collection (java.util.Collection)1 Date (java.util.Date)1 CountdownTimer (org.gradle.internal.time.CountdownTimer)1 DaemonContext (org.gradle.launcher.daemon.context.DaemonContext)1 InvalidateVirtualFileSystem (org.gradle.launcher.daemon.protocol.InvalidateVirtualFileSystem)1 ReportStatus (org.gradle.launcher.daemon.protocol.ReportStatus)1 Status (org.gradle.launcher.daemon.protocol.Status)1 DaemonDir (org.gradle.launcher.daemon.registry.DaemonDir)1 DaemonStopEvent (org.gradle.launcher.daemon.registry.DaemonStopEvent)1 DaemonStateControl (org.gradle.launcher.daemon.server.api.DaemonStateControl)1 DaemonExpirationResult (org.gradle.launcher.daemon.server.expiry.DaemonExpirationResult)1