List of usage examples for java.util.concurrent ScheduledFuture cancel
boolean cancel(boolean mayInterruptIfRunning);
From source file:com.heliosapm.script.AbstractDeployedScript.java
/** * Activates the passed execution schedule for this depoyment * @param newSchedule the new execution schedule for this depoyment *///from w w w . j av a 2s. c om public void setExecutionSchedule(final ExecutionSchedule newSchedule) { if (newSchedule == null) throw new IllegalArgumentException("The passed ExecutionSchedule was null"); if (newSchedule.getScheduleType() != ScheduleType.NONE) { pausedSchedule.set(newSchedule); } final ExecutionSchedule priorSchedule = schedule.getAndSet(newSchedule); if (!newSchedule.equals(priorSchedule)) { final ScheduledFuture<?> priorFuture = scheduleHandle.get(); if (priorFuture != null) { priorFuture.cancel(true); } scheduleHandle.set(ScheduledExecutionService.getInstance().scheduleDeploymentExecution(this)); } }
From source file:org.apache.druid.indexing.overlord.RemoteTaskRunner.java
private boolean cancelWorkerCleanup(String workerHost) { ScheduledFuture previousCleanup = removedWorkerCleanups.remove(workerHost); if (previousCleanup != null) { log.info("Cancelling Worker[%s] scheduled task cleanup", workerHost); previousCleanup.cancel(false); }//from ww w. j a va 2s .c o m return previousCleanup != null; }
From source file:com.l2jfree.gameserver.instancemanager.AutoSpawnManager.java
/** * Sets the active state of the specified spawn. * //from ww w . j a v a 2 s . c o m * @param spawnInst * @param isActive */ public void setSpawnActive(AutoSpawnInstance spawnInst, boolean isActive) { if (spawnInst == null) return; int objectId = spawnInst._objectId; if (isSpawnRegistered(objectId)) { ScheduledFuture<?> spawnTask = null; if (isActive) { AutoSpawner rs = new AutoSpawner(objectId); if (spawnInst._desDelay > 0) spawnTask = ThreadPoolManager.getInstance().scheduleEffectAtFixedRate(rs, spawnInst._initDelay, spawnInst._resDelay); else spawnTask = ThreadPoolManager.getInstance().scheduleEffect(rs, spawnInst._initDelay); _runningSpawns.put(objectId, spawnTask); } else { AutoDespawner rd = new AutoDespawner(objectId); spawnTask = _runningSpawns.remove(objectId); if (spawnTask != null) spawnTask.cancel(false); ThreadPoolManager.getInstance().scheduleEffect(rd, 0); } spawnInst.setSpawnActive(isActive); } }
From source file:org.openhab.binding.amazonechocontrol.internal.handler.EchoHandler.java
private void stopProgressTimer() { ScheduledFuture<?> updateProgressJob = this.updateProgressJob; this.updateProgressJob = null; if (updateProgressJob != null) { updateProgressJob.cancel(false); }/*from w w w .ja v a2 s . c om*/ }
From source file:org.openhab.binding.zoneminder.handler.ZoneMinderServerBridgeHandler.java
/** * Method to stop the datarefresh task.//from ww w . ja v a 2 s .com */ protected void stopTask(ScheduledFuture<?> task) { try { if (task != null && !task.isCancelled()) { logger.debug("{}: Stopping ZoneMinder Bridge Monitor Task. Task='{}'", getLogIdentifier(), task.toString()); task.cancel(true); } } catch (Exception ex) { } }
From source file:org.openhab.binding.amazonechocontrol.internal.handler.EchoHandler.java
private void startTextToSpeech(Connection connection, Device device, String text) throws IOException, URISyntaxException { if (textToSpeechVolume != 0) { @Nullable ScheduledFuture<?> oldIgnoreVolumeChange = this.ignoreVolumeChange; if (oldIgnoreVolumeChange != null) { oldIgnoreVolumeChange.cancel(false); }/* w ww . j av a 2s . c o m*/ this.ignoreVolumeChange = scheduler.schedule(this::stopIgnoreVolumeChange, 2000, TimeUnit.MILLISECONDS); } if (text.startsWith("<speak>") && text.endsWith("</speak>")) { connection.sendAnnouncement(device, text, null, textToSpeechVolume, lastKnownVolume); } else { connection.textToSpeech(device, text, textToSpeechVolume, lastKnownVolume); } }
From source file:com.funambol.pushlistener.service.taskexecutor.ScheduledTaskExecutor.java
/** * Cancels execution of the task identified by the given id and removes its * scheduled execution/* w ww .j av a 2s . c o m*/ * @param taskId the id of task to stop/remove * @param mayInterruptIfRunning true if the thread executing this task should * be interrupted; otherwise, in-progress tasks are allowed to complete * @return true if the task has been removed successfully, false otherwise (for instance * if the task doesn't exist) */ public boolean removeScheduledTask(long taskId, boolean mayInterruptIfRunning) { ScheduledTaskWrapper dummyTask = new ScheduledTaskWrapper(taskId); if (log.isTraceEnabled()) { log.trace("Removing task '" + taskId + "'"); } // // Locking the lock for this task so no other thread can handle it avoiding // conflict (what happens if a thread is removing it an another threead is // updating it ?) // Lock handlingTaskLock = getHandlingTaskLock(taskId); handlingTaskLock.lock(); try { ScheduledFuture scheduledFuture = null; ScheduledTaskWrapper scheduledTask = null; synchronized (scheduledFutures) { scheduledFuture = (ScheduledFuture) scheduledFutures.get(dummyTask); scheduledTask = (ScheduledTaskWrapper) scheduledFutures.getKey(scheduledFuture); } if (scheduledFuture != null) { scheduledFuture.cancel(mayInterruptIfRunning); if (scheduledTask != null) { try { scheduledTask.shutdown(); } catch (TaskException ex) { log.error("Error shutting down scheduled task '" + scheduledTask + "'", ex); } scheduledTask.setState(ScheduledTaskWrapper.State.SHUTDOWN); } synchronized (scheduledFutures) { // // Any time we remove the scheduledTask from scheduledFutures, // we try to remove the scheduledFuture from the queue. This // is not really needed because after a while this is performed // automatically but in this way we keep scheduledFutures and // the queue in sync // if (scheduledFuture instanceof Runnable) { super.remove((Runnable) scheduledFuture); } scheduledFutures.remove(scheduledTask); } if (log.isTraceEnabled()) { log.trace("Task '" + taskId + "' cancelled successfully"); } return true; } else { if (log.isTraceEnabled()) { log.trace("Task '" + taskId + "' seems not scheduled"); } return false; } } finally { handlingTaskLock.unlock(); } }
From source file:org.openhab.binding.amazonechocontrol.internal.handler.EchoHandler.java
@Override public void dispose() { stopCurrentNotification();//from w w w .jav a2 s . c om ScheduledFuture<?> updateStateJob = this.updateStateJob; this.updateStateJob = null; if (updateStateJob != null) { this.disableUpdate = false; updateStateJob.cancel(false); } stopProgressTimer(); super.dispose(); }
From source file:org.openhab.binding.amazonechocontrol.internal.handler.EchoHandler.java
private void stopCurrentNotification() { ScheduledFuture<?> currentNotifcationUpdateTimer = this.currentNotifcationUpdateTimer; if (currentNotifcationUpdateTimer != null) { this.currentNotifcationUpdateTimer = null; currentNotifcationUpdateTimer.cancel(true); }/*from www . ja v a2s. c o m*/ JsonNotificationResponse currentNotification = this.currentNotification; if (currentNotification != null) { this.currentNotification = null; Connection currentConnection = this.findConnection(); if (currentConnection != null) { try { currentConnection.stopNotification(currentNotification); } catch (IOException | URISyntaxException e) { logger.warn("Stop notification failed: {}", e); } } } }
From source file:org.hyperledger.fabric.sdk.ServiceDiscovery.java
void shutdown() { logger.trace("Service discovery shutdown."); try {//from w w w . java 2 s . c om final ScheduledFuture<?> lseviceDiscovery = seviceDiscovery; seviceDiscovery = null; if (null != lseviceDiscovery) { lseviceDiscovery.cancel(true); } } catch (Exception e) { logger.error(e); //best effort. } }