public ListenableFuture<?> process() { checkLockNotHeld("Can not process while holding the driver lock"); // if the driver is blocked we don't need to continue SettableFuture<?> blockedFuture = driverBlockedFuture.get(); if (!blockedFuture.isDone()) { return blockedFuture; } Optional<ListenableFuture<?>> result = tryWithLock(100, TimeUnit.MILLISECONDS, () -> { ListenableFuture<?> future = processInternal(createTimer()); return updateDriverBlockedFuture(future); }); return result.orElse(NOT_BLOCKED); }
long start = System.nanoTime(); do { ListenableFuture<?> future = processInternal(operationTimer); if (!future.isDone()) { return updateDriverBlockedFuture(future);
public ListenableFuture<?> process() { checkLockNotHeld("Can not process while holding the driver lock"); try (DriverLockResult lockResult = tryLockAndProcessPendingStateChanges(100, TimeUnit.MILLISECONDS)) { if (!lockResult.wasAcquired()) { // this is unlikely to happen unless the driver is being // destroyed and in that case the caller should notice notice // this state change by calling isFinished return NOT_BLOCKED; } return processInternal(); } }
public ListenableFuture<?> processFor(Duration duration) { checkLockNotHeld("Can not process for a duration while holding the driver lock"); requireNonNull(duration, "duration is null"); long maxRuntime = duration.roundTo(TimeUnit.NANOSECONDS); try (DriverLockResult lockResult = tryLockAndProcessPendingStateChanges(100, TimeUnit.MILLISECONDS)) { if (lockResult.wasAcquired()) { driverContext.startProcessTimer(); try { long start = System.nanoTime(); do { ListenableFuture<?> future = processInternal(); if (!future.isDone()) { return future; } } while (System.nanoTime() - start < maxRuntime && !isFinishedInternal()); } finally { driverContext.recordProcessed(); } } } return NOT_BLOCKED; }