List of usage examples for java.util.concurrent ScheduledFuture cancel
boolean cancel(boolean mayInterruptIfRunning);
From source file:org.cryptomator.ui.settings.SettingsProvider.java
private void scheduleSave(Settings settings) { if (settings == null) { return;/*from w ww.j a v a 2 s . c o m*/ } ScheduledFuture<?> saveCmd = saveScheduler.schedule(() -> { this.save(settings); }, SAVE_DELAY_MS, TimeUnit.MILLISECONDS); ScheduledFuture<?> previousSaveCmd = scheduledSaveCmd.getAndSet(saveCmd); if (previousSaveCmd != null) { previousSaveCmd.cancel(false); } }
From source file:org.wso2.carbon.deployment.synchronizer.DeploymentSynchronizationManager.java
/** * Cleanup and shutdown the RepositoryManager instance. This method will also gracefully * destroy all the created synchronizers, cancel any existing scheduled tasks and then * free up any additional resources.//from w w w . java 2 s . c om */ public void shutdown() { for (DeploymentSynchronizer repository : synchronizers.values()) { repository.stop(); } synchronizers.clear(); for (ScheduledFuture future : scheduledFutures.values()) { future.cancel(false); } ((ScheduledThreadPoolExecutor) repositoryTaskExecutor).purge(); scheduledFutures.clear(); repositoryTaskExecutor.shutdownNow(); }
From source file:org.wso2.carbon.deployment.synchronizer.internal.DeploymentSynchronizationManager.java
/** * Cleanup and shutdown the RepositoryManager instance. This method will also gracefully * destroy all the created synchronizers, cancel any existing scheduled tasks and then * free up any additional resources.//from w ww . j a v a 2 s .co m */ void shutdown() { for (DeploymentSynchronizer repository : synchronizers.values()) { repository.stop(); } synchronizers.clear(); for (ScheduledFuture future : scheduledFutures.values()) { future.cancel(false); } ((ScheduledThreadPoolExecutor) repositoryTaskExecutor).purge(); scheduledFutures.clear(); repositoryTaskExecutor.shutdownNow(); }
From source file:com.netflix.genie.web.tasks.leader.LeadershipTasksCoordinator.java
private void cancelTasks() { for (final ScheduledFuture<?> future : this.futures) { log.info("Attempting to cancel thread {}", future); if (future.cancel(true)) { log.info("Successfully cancelled."); } else {//from w w w.j a va2s . c o m log.info("Failed to cancel."); } } // Clear out the tasks this.futures.clear(); this.tasks.forEach(LeadershipTask::cleanup); }
From source file:org.apache.stratos.mock.iaas.statistics.generator.MockHealthStatisticsGenerator.java
/** * Stop statistics updater task of a service/cartridge type, factor. * * @param serviceName service name/cartridge type * @param scalingFactor scaling factor/*from ww w . j a va2s . c om*/ */ public void stopStatisticsUpdaterTask(String serviceName, String scalingFactor) { Map<String, ScheduledFuture> autoscalingFactorToTaskMap = serviceNameToTaskListMap.get(serviceName); if (autoscalingFactorToTaskMap != null) { ScheduledFuture task = autoscalingFactorToTaskMap.get(scalingFactor); if (task != null) { task.cancel(true); autoscalingFactorToTaskMap.remove(scalingFactor); if (log.isInfoEnabled()) { log.info(String.format( "Mock statistics updater task stopped: [service-name] %s" + " [scaling-factor] %s", serviceName, scalingFactor)); } } } }
From source file:org.wso2.carbon.deployment.synchronizer.DeploymentSynchronizationManager.java
void cancelSynchronizationTask(String key) { ScheduledFuture future = scheduledFutures.get(key); if (future != null) { future.cancel(false); ((ScheduledThreadPoolExecutor) repositoryTaskExecutor).purge(); scheduledFutures.remove(key);/* w ww . j ava2 s . c om*/ } }
From source file:com.bt.aloha.testing.mockphones.HangUpDialogBeanBase.java
@Override protected void processBye(Request request, ServerTransaction serverTransaction, String dialogId) { super.processBye(request, serverTransaction, dialogId); log.debug(String.format("Descheduling hang up process waiting for dialogId %s", dialogId)); ScheduledFuture<?> future = timers.remove(dialogId); if (null != future) { log.debug(String.format("Descheduling for hangup the future [%s] for dialogId %s", future.toString(), dialogId));//from w w w .j av a2 s . c om future.cancel(true); } }
From source file:name.abhijitsarkar.javaee.coffeehouse.spring.event.CoffeeHouseClosingEventPublisher.java
void closeShop() { final Runnable closer = new Runnable() { public void run() { final OperationalEvent event = new OperationalEvent(this); event.setOpen(false);/*from w w w .j av a 2 s. co m*/ LOGGER.debug("Firing notification to close shop."); CoffeeHouseClosingEventPublisher.this.publisher.publishEvent(event); } }; final long initialDelay = 1L; final long delay = 2L; final long duration = 10L; final ScheduledFuture<?> closerHandle = scheduler.scheduleWithFixedDelay(closer, initialDelay, delay, TimeUnit.SECONDS); scheduler.schedule(new Runnable() { public void run() { closerHandle.cancel(true); } }, duration, TimeUnit.SECONDS); }
From source file:edu.umass.cs.gigapaxos.FailureDetection.java
protected synchronized boolean dontSendKeepAlive(NodeIDType id) { if (this.futures.containsKey(id)) { ScheduledFuture<PingTask> pingTask = futures.get(id); pingTask.cancel(true); futures.remove(id);//w w w .j av a 2 s. c o m return true; } return false; }
From source file:com.netflix.genie.web.tasks.leader.LeadershipTasksCoordinatorUnitTests.java
/** * Make sure all leadership activities are stopped when leadership is revoked. *//*from ww w.j ava 2s . co m*/ @Test @SuppressWarnings("unchecked") public void canStopLeadershipTasks() { final long task1Period = 13238; Mockito.when(this.task1.getScheduleType()).thenReturn(GenieTaskScheduleType.FIXED_RATE); Mockito.when(this.task1.getFixedRate()).thenReturn(task1Period); final long task2Period = 3891082; Mockito.when(this.task2.getScheduleType()).thenReturn(GenieTaskScheduleType.FIXED_DELAY); Mockito.when(this.task2.getFixedDelay()).thenReturn(task2Period); final Trigger task3Trigger = Mockito.mock(Trigger.class); Mockito.when(this.task3.getScheduleType()).thenReturn(GenieTaskScheduleType.TRIGGER); Mockito.when(this.task3.getTrigger()).thenReturn(task3Trigger); final ScheduledFuture future1 = Mockito.mock(ScheduledFuture.class); Mockito.when(future1.cancel(true)).thenReturn(true); Mockito.when(this.scheduler.scheduleAtFixedRate(this.task1, task1Period)).thenReturn(future1); final ScheduledFuture future2 = Mockito.mock(ScheduledFuture.class); Mockito.when(future2.cancel(true)).thenReturn(true); Mockito.when(this.scheduler.scheduleWithFixedDelay(this.task2, task2Period)).thenReturn(future2); final ScheduledFuture future3 = Mockito.mock(ScheduledFuture.class); Mockito.when(future3.cancel(true)).thenReturn(false); Mockito.when(this.scheduler.schedule(this.task3, task3Trigger)).thenReturn(future3); final OnGrantedEvent grantedEvent = new OnGrantedEvent(this, null, "blah"); this.coordinator.onLeaderEvent(grantedEvent); Mockito.verify(this.scheduler, Mockito.times(1)).scheduleAtFixedRate(this.task1, task1Period); Mockito.verify(this.task1, Mockito.never()).getFixedDelay(); Mockito.verify(this.task1, Mockito.never()).getTrigger(); Mockito.verify(this.scheduler, Mockito.times(1)).scheduleWithFixedDelay(this.task2, task2Period); Mockito.verify(this.task2, Mockito.never()).getFixedRate(); Mockito.verify(this.task2, Mockito.never()).getTrigger(); Mockito.verify(this.scheduler, Mockito.times(1)).schedule(this.task3, task3Trigger); Mockito.verify(this.task3, Mockito.never()).getFixedRate(); Mockito.verify(this.task3, Mockito.never()).getFixedDelay(); // Should now be running final OnRevokedEvent revokedEvent = new OnRevokedEvent(this, null, "blah"); this.coordinator.onLeaderEvent(revokedEvent); Mockito.verify(future1, Mockito.times(1)).cancel(true); Mockito.verify(future2, Mockito.times(1)).cancel(true); Mockito.verify(future3, Mockito.times(1)).cancel(true); // Call again to make sure nothing is invoked even though they were cancelled this.coordinator.onLeaderEvent(revokedEvent); Mockito.verify(future1, Mockito.times(1)).cancel(true); Mockito.verify(future2, Mockito.times(1)).cancel(true); Mockito.verify(future3, Mockito.times(1)).cancel(true); }