public static void cancelScheduledFuture(ScheduledFuture<?> scheduledFuture) { ScheduledFuture<?> future = scheduledFuture; if (future != null && !future.isCancelled()) { future.cancel(true); } } }
public static void cancelScheduledFuture(ScheduledFuture<?> scheduledFuture) { ScheduledFuture<?> future = scheduledFuture; if (future != null && !future.isCancelled()) { future.cancel(true); } } }
public void cancelFuture() { if (mFuture != null && !mFuture.isCancelled()) { mFuture.cancel(true); mFuture = null; } }
@Override public boolean isCancelled() { synchronized (this.triggerContextMonitor) { return obtainCurrentFuture().isCancelled(); } }
private void cancelFuture() { if (mFuture != null && !mFuture.isCancelled()) { mFuture.cancel(true); mFuture = null; } }
private void cancel(@Nullable ScheduledFuture<?> future) { if (future != null && !future.isCancelled()) { if (!future.cancel(true)) { LOG.warn("Could not cancel refresh job"); } } }
/** * Cancel the polling job for the given {@link ScheduledFuture}. * @param future polling job future */ private void cancel(@Nullable ScheduledFuture<?> future) { if (future != null && !future.isCancelled()) { if (!future.cancel(true)) { LOG.warn("Couldn't cancel field type update job"); } } }
/** * Stop periodically checking the plugin directory. */ public void stopMonitoring() { if ( monitorTaskScheduledFuture != null && !monitorTaskScheduledFuture.isDone() ) { // Cancel, with an interrupt if this task has been cancelled before. monitorTaskScheduledFuture.cancel( monitorTaskScheduledFuture.isCancelled() ); } }
@Override public boolean cancel(boolean mayInterruptIfRunning) { if (future != null) { if (!future.isDone() && !future.isCancelled()) { return future.cancel(mayInterruptIfRunning); } } return false; }
@Override public boolean isCancelled() { synchronized (this.triggerContextMonitor) { return obtainCurrentFuture().isCancelled(); } }
/** * Start the scan task for long-idle connections. */ private synchronized void startScan() { if (scanTaskFuture == null || scanTaskFuture.isCancelled() || scanTaskFuture.isDone()) { scanTaskFuture = TIMER.scheduleAtFixedRate( new ScanIdleConnectionTask(this), 10, 30, TimeUnit.SECONDS); } }
@Override public Date getNextRunTime(LastExecution lastExecution, Date taskScheduledTime) { Date nextRunTime = trigger.getNextRunTime(lastExecution, taskScheduledTime); final ScheduledFuture future = this.future; if (future != null && future.isCancelled()) { nextRunTime = null; } return nextRunTime; }
@Override public void run() { Date actualExecutionTime = new Date(); super.run(); Date completionTime = new Date(); synchronized (this.triggerContextMonitor) { Assert.state(this.scheduledExecutionTime != null, "No scheduled execution"); this.triggerContext.update(this.scheduledExecutionTime, actualExecutionTime, completionTime); if (!obtainCurrentFuture().isCancelled()) { schedule(); } } }
private void stopExtendingTtl() { if (!ttlExtendTaskExecutor.isShutdown()) { ttlExtendTaskExecutor.shutdown(); } if (ttlExtendingFuture != null && !ttlExtendingFuture.isCancelled()) { logger.debug("Cancelling extending ttl..."); ttlExtendingFuture.cancel(true); } closeSilently(extendingApiClient); }
private void recycle() { readOpCount = -1; if (task != null && !task.isDone() && !task.isCancelled()) { try { task.cancel(false); } catch (Throwable th) { log.debug("[{}]Failed to cancle task for read-callback for {}-{}", name, ledgerId, entryId); } } readEntryCallback = null; readEntriesCallback = null; ledgerId = -1; entryId = -1; name = null; readCompleted = FALSE; recyclerHandle.recycle(this); }
@Override public void run() { Date actualExecutionTime = new Date(); super.run(); Date completionTime = new Date(); synchronized (this.triggerContextMonitor) { Assert.state(this.scheduledExecutionTime != null, "No scheduled execution"); this.triggerContext.update(this.scheduledExecutionTime, actualExecutionTime, completionTime); if (!obtainCurrentFuture().isCancelled()) { schedule(); } } }
/** * @return true if the instance is heartbeating; false otherwise */ public boolean isHeartbeating() { readLock.lock(); try { return heartbeatSenderFuture != null && !heartbeatSenderFuture.isCancelled(); } finally { readLock.unlock("isHeartbeating"); } }
public void testServiceStartStop() throws Exception { NullService service = new NullService(); service.startAsync().awaitRunning(); assertFalse(future.isDone()); service.stopAsync().awaitTerminated(); assertTrue(future.isCancelled()); }
public void testListeningDecorator_cancelled() throws Exception { ScheduledThreadPoolExecutor delegate = new ScheduledThreadPoolExecutor(1); BlockingQueue<?> delegateQueue = delegate.getQueue(); ListeningScheduledExecutorService service = listeningDecorator(delegate); ListenableFuture<?> future; ScheduledFuture<?> delegateFuture; Runnable runnable = new Runnable() { @Override public void run() {} }; future = service.schedule(runnable, 5, TimeUnit.MINUTES); future.cancel(true); assertTrue(future.isCancelled()); delegateFuture = (ScheduledFuture<?>) delegateQueue.element(); assertTrue(delegateFuture.isCancelled()); delegateQueue.clear(); future = service.scheduleAtFixedRate(runnable, 5, 5, TimeUnit.MINUTES); future.cancel(true); assertTrue(future.isCancelled()); delegateFuture = (ScheduledFuture<?>) delegateQueue.element(); assertTrue(delegateFuture.isCancelled()); delegateQueue.clear(); future = service.scheduleWithFixedDelay(runnable, 5, 5, TimeUnit.MINUTES); future.cancel(true); assertTrue(future.isCancelled()); delegateFuture = (ScheduledFuture<?>) delegateQueue.element(); assertTrue(delegateFuture.isCancelled()); }
@Test public void scheduleAndCancelHeartbeat() throws Exception { ScheduledFuture<?> task = mock(ScheduledFuture.class); willReturn(task).given(this.taskScheduler).schedule(any(Runnable.class), any(Date.class)); this.session.setActive(true); this.session.scheduleHeartbeat(); verify(this.taskScheduler).schedule(any(Runnable.class), any(Date.class)); verifyNoMoreInteractions(this.taskScheduler); given(task.isCancelled()).willReturn(false); given(task.cancel(false)).willReturn(true); this.session.cancelHeartbeat(); verify(task).cancel(false); verifyNoMoreInteractions(task); }