use of org.gradle.internal.time.CountdownTimer in project gradle by gradle.
the class WaitingReader method readLine.
String readLine() throws IOException {
CountdownTimer timer = Timers.startTimer(timeoutMs);
reader.mark(READAHEAD_BUFFER_SIZE);
int character = EOF;
while (character != NEW_LINE && character != CARRIAGE_RETURN) {
character = reader.read();
if (character == EOF) {
if (timer.hasExpired()) {
break;
}
try {
Thread.sleep(clockTick);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
retriedCount++;
}
}
reader.reset();
String line = reader.readLine();
return line;
}
use of org.gradle.internal.time.CountdownTimer in project gradle by gradle.
the class DaemonStopClient method stop.
/**
* Stops all daemons, blocking until all have completed.
*/
public void stop() {
CountdownTimer timer = Timers.startTimer(STOP_TIMEOUT_SECONDS, TimeUnit.SECONDS);
final Set<String> seen = new HashSet<String>();
ExplainingSpec<DaemonContext> spec = new ExplainingSpec<DaemonContext>() {
@Override
public String whyUnsatisfied(DaemonContext element) {
return "already seen";
}
@Override
public boolean isSatisfiedBy(DaemonContext element) {
return !seen.contains(element.getUid());
}
};
DaemonClientConnection connection = connector.maybeConnect(spec);
if (connection == null) {
LOGGER.lifecycle(DaemonMessages.NO_DAEMONS_RUNNING);
return;
}
LOGGER.lifecycle("Stopping Daemon(s)");
//iterate and stop all daemons
int numStopped = 0;
while (connection != null && !timer.hasExpired()) {
try {
seen.add(connection.getDaemon().getUid());
LOGGER.debug("Requesting daemon {} stop now", connection.getDaemon());
boolean stopped = stopDispatcher.dispatch(connection, new Stop(idGenerator.generateId(), connection.getDaemon().getToken()));
if (stopped) {
numStopped++;
}
} finally {
connection.stop();
}
connection = connector.maybeConnect(spec);
}
if (numStopped > 0) {
LOGGER.lifecycle(numStopped + " Daemon" + ((numStopped > 1) ? "s" : "") + " stopped");
}
if (connection != null) {
throw new GradleException(String.format("Timeout waiting for all daemons to stop. Waited %s.", timer.getElapsed()));
}
}
use of org.gradle.internal.time.CountdownTimer in project gradle by gradle.
the class DefaultDaemonConnector method startDaemon.
public DaemonClientConnection startDaemon(ExplainingSpec<DaemonContext> constraint) {
ProgressLogger progressLogger = progressLoggerFactory.newOperation(DefaultDaemonConnector.class).start("Starting Gradle Daemon", "Starting Daemon");
final DaemonStartupInfo startupInfo = daemonStarter.startDaemon();
LOGGER.debug("Started Gradle daemon {}", startupInfo);
CountdownTimer timer = Timers.startTimer(connectTimeout);
try {
do {
DaemonClientConnection daemonConnection = connectToDaemonWithId(startupInfo, constraint);
if (daemonConnection != null) {
startListener.daemonStarted(daemonConnection.getDaemon());
return daemonConnection;
}
try {
sleep(200L);
} catch (InterruptedException e) {
throw UncheckedException.throwAsUncheckedException(e);
}
} while (!timer.hasExpired());
} finally {
progressLogger.completed();
}
throw new DaemonConnectionException("Timeout waiting to connect to the Gradle daemon.\n" + startupInfo.describe());
}
use of org.gradle.internal.time.CountdownTimer 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 = Timers.startTimer(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.internal.time.CountdownTimer in project gradle by gradle.
the class DaemonStateCoordinator method cancelNow.
private void cancelNow() {
CountdownTimer timer = Timers.startTimer(cancelTimeoutMs);
LOGGER.debug("Cancel requested: will wait for daemon to become idle.");
try {
cancellationToken.cancel();
} catch (Exception ex) {
LOGGER.error("Cancel processing failed. Will continue.", ex);
}
lock.lock();
try {
while (!timer.hasExpired()) {
try {
switch(state) {
case Idle:
LOGGER.debug("Cancel: daemon is idle now.");
return;
case Busy:
case Canceled:
case StopRequested:
LOGGER.debug("Cancel: daemon is busy, sleeping until state changes.");
condition.awaitUntil(timer.getExpiryTime());
break;
case Broken:
throw new IllegalStateException("This daemon is in a broken state.");
case Stopped:
LOGGER.debug("Cancel: daemon has stopped.");
return;
}
} catch (InterruptedException e) {
throw UncheckedException.throwAsUncheckedException(e);
}
}
LOGGER.debug("Cancel: daemon is still busy after grace period. Will force stop.");
stopNow("cancel requested but timed out");
} finally {
lock.unlock();
}
}
Aggregations