java.util.concurrent.ScheduledFuture#isCancelled ( )源码实例Demo

下面列出了java.util.concurrent.ScheduledFuture#isCancelled ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: BioSolr   文件: OntologyMapper.java
private void disposeHelper() {
	String helperKey = buildHelperKey(ontologySettings);
	if (checkers.containsKey(helperKey)) {
		ScheduledFuture checker = checkers.remove(helperKey);
		if (!checker.isCancelled() && !checker.isDone()) {
			logger.debug("Cancelling ScheduledFuture for {}", helperKey);
			checker.cancel(false);
		}
	}
	if (helpers.containsKey(helperKey)) {
		OntologyHelper helper = helpers.remove(helperKey);
		helper.dispose();
	}

	threadPool.stats();
	logger.debug("helpers.size() = {}; checkers.size() = {}", helpers.size(), checkers.size());
}
 
源代码2 项目: smarthome   文件: LifxLightDiscovery.java
@Override
protected void stopBackgroundDiscovery() {
    logger.debug("Stopping LIFX device background discovery");

    ScheduledFuture<?> localDiscoveryJob = discoveryJob;
    if (localDiscoveryJob != null && !localDiscoveryJob.isCancelled()) {
        localDiscoveryJob.cancel(true);
        discoveryJob = null;
    }

    ScheduledFuture<?> localNetworkJob = networkJob;
    if (localNetworkJob != null && !localNetworkJob.isCancelled()) {
        localNetworkJob.cancel(true);
        networkJob = null;
    }
}
 
源代码3 项目: smarthome   文件: LifxLightCommunicationHandler.java
public void start() {
    try {
        lock.lock();

        logger.debug("{} : Starting communication handler", logId);
        logger.debug("{} : Using '{}' as source identifier", logId, Long.toString(sourceId, 16));

        ScheduledFuture<?> localNetworkJob = networkJob;
        if (localNetworkJob == null || localNetworkJob.isCancelled()) {
            networkJob = scheduler.scheduleWithFixedDelay(this::receiveAndHandlePackets, 0, PACKET_INTERVAL,
                    TimeUnit.MILLISECONDS);
        }

        currentLightState.setOffline();

        Selector localSelector = Selector.open();
        selector = localSelector;

        if (isBroadcastEnabled()) {
            broadcastKey = openBroadcastChannel(selector, logId, broadcastPort);
            selectorContext = new LifxSelectorContext(localSelector, sourceId, sequenceNumberSupplier, logId, host,
                    macAddress, broadcastKey, unicastKey);
            broadcastPacket(new GetServiceRequest());
        } else {
            unicastKey = openUnicastChannel(selector, logId, host);
            selectorContext = new LifxSelectorContext(localSelector, sourceId, sequenceNumberSupplier, logId, host,
                    macAddress, broadcastKey, unicastKey);
            sendPacket(new GetServiceRequest());
        }
    } catch (IOException e) {
        logger.error("{} while starting LIFX communication handler for light '{}' : {}",
                e.getClass().getSimpleName(), logId, e.getMessage(), e);
    } finally {
        lock.unlock();
    }
}
 
源代码4 项目: tomee   文件: ManagedScheduledServiceTest.java
/**
 * Happy path with single task to be executed periodically until it's canceled.
 *
 * @throws InterruptedException we don't expect it
 */
@Test
public void periodicFixedDelayTask() throws InterruptedException {
    final CountDownLatch countDownLatch = new CountDownLatch(4); // execute 4 times
    final ScheduledFuture<?> scheduledFuture = scheduledService.periodicFixedDelayTask(1, null, countDownLatch);
    LOGGER.info("Do some other work while we wait for the tasks");
    countDownLatch.await(500, TimeUnit.MILLISECONDS);
    if (!scheduledFuture.isCancelled()) {
        scheduledFuture.cancel(true);
        LOGGER.info("task stopped");
    }
}
 
源代码5 项目: util4j   文件: TaskCenter.java
public void close() {
	System.out.println("TaskCenter closing");
	this.monitoring.cancel(true);

	// 停止所有定时任务
	for (ScheduledFuture<?> sf : this.scheduledFutureList) {
		if (!sf.isCancelled() || !sf.isDone()) {
			sf.cancel(true);
		}
	}
	this.scheduledFutureList.clear();

	Iterator<Timer> iter = this.timers.values().iterator();
	while (iter.hasNext()) {
		Timer timer = iter.next();
		timer.cancel();
	}
	this.timers.clear();

	// 关闭滑动窗
	this.slidingWindow.stop();

	// 关闭线程池
	this.mainExecutor.shutdown();
	this.scheduledExecutor.shutdown();
	System.out.println("TaskCenter closed");
}
 
源代码6 项目: smarthome   文件: LifxLightPropertiesUpdater.java
public void stop() {
    try {
        lock.lock();
        communicationHandler.removeResponsePacketListener(this::handleResponsePacket);
        ScheduledFuture<?> localUpdateJob = updateJob;
        if (localUpdateJob != null && !localUpdateJob.isCancelled()) {
            localUpdateJob.cancel(true);
            updateJob = null;
        }
    } catch (Exception e) {
        logger.error("Error occurred while stopping properties update job for a light ({})", logId, e);
    } finally {
        lock.unlock();
    }
}
 
源代码7 项目: dubbox   文件: HeaderExchangeServer.java
private void stopHeartbeatTimer() {
    try {
        ScheduledFuture<?> timer = heatbeatTimer;
        if (timer != null && ! timer.isCancelled()) {
            timer.cancel(true);
        }
    } catch (Throwable t) {
        logger.warn(t.getMessage(), t);
    } finally {
        heatbeatTimer =null;
    }
}
 
源代码8 项目: dubbox-hystrix   文件: HeaderExchangeServer.java
private void stopHeartbeatTimer() {
    try {
        ScheduledFuture<?> timer = heatbeatTimer;
        if (timer != null && ! timer.isCancelled()) {
            timer.cancel(true);
        }
    } catch (Throwable t) {
        logger.warn(t.getMessage(), t);
    } finally {
        heatbeatTimer =null;
    }
}
 
源代码9 项目: consulo   文件: SimpleTimer.java
@Nonnull
public SimpleTimerTask setUp(@Nonnull final Runnable runnable, final long delay) {
  final ScheduledFuture<?> future = myScheduledExecutorService.schedule(runnable, delay, TimeUnit.MILLISECONDS);
  return new SimpleTimerTask() {
    @Override
    public void cancel() {
      future.cancel(false);
    }

    @Override
    public boolean isCancelled() {
      return future.isCancelled();
    }
  };
}
 
源代码10 项目: openhab-core   文件: PollingUsbSerialScanner.java
/**
 * Stops repeatedly scanning for newly added and removed USB devices. This can be restarted using
 * {@link #startBackgroundScanning()}.
 */
@Override
public synchronized void stopBackgroundScanning() {
    logger.debug("Stopping USB-Serial background discovery");
    ScheduledFuture<?> currentBackgroundScanningJob = backgroundScanningJob;
    if (currentBackgroundScanningJob != null && !currentBackgroundScanningJob.isCancelled()) {
        if (currentBackgroundScanningJob.cancel(true)) {
            backgroundScanningJob = null;
            logger.debug("Stopped USB-serial background discovery");
        }
    }
}
 
源代码11 项目: smarthome   文件: LifxLightCurrentStateUpdater.java
public void start() {
    try {
        lock.lock();
        communicationHandler.addResponsePacketListener(this::handleResponsePacket);
        ScheduledFuture<?> localStatePollingJob = statePollingJob;
        if (localStatePollingJob == null || localStatePollingJob.isCancelled()) {
            statePollingJob = scheduler.scheduleWithFixedDelay(this::pollLightState, 0, STATE_POLLING_INTERVAL,
                    TimeUnit.SECONDS);
        }
    } catch (Exception e) {
        logger.error("Error occurred while starting light state updater", e);
    } finally {
        lock.unlock();
    }
}
 
源代码12 项目: anima   文件: ServerSurrogate.java
private void stopHeartbeatTimer() {
	try {
		ScheduledFuture<?> timer = heatbeatTimer;
		if (timer != null && !timer.isCancelled()) {
			timer.cancel(true);
		}
	} catch (Throwable t) {
		logger.warn(t.getMessage(), t);
	} finally {
		heatbeatTimer = null;
	}
}
 
源代码13 项目: anima   文件: FrontendServer.java
private void stopHeartbeatTimer() {
    try {
        ScheduledFuture<?> timer = heatbeatTimer;
        if (timer != null && ! timer.isCancelled()) {
            timer.cancel(true);
        }
    } catch (Throwable t) {
        logger.warn(t.getMessage(), t);
    } finally {
        heatbeatTimer =null;
    }
}
 
源代码14 项目: smarthome   文件: LifxLightOnlineStateUpdater.java
public void start() {
    try {
        lock.lock();
        communicationHandler.addResponsePacketListener(this::handleResponsePacket);
        ScheduledFuture<?> localEchoJob = echoJob;
        if (localEchoJob == null || localEchoJob.isCancelled()) {
            echoJob = scheduler.scheduleWithFixedDelay(this::sendEchoPackets, 0, ECHO_POLLING_INTERVAL,
                    TimeUnit.SECONDS);
        }
    } catch (Exception e) {
        logger.error("Error occurred while starting online state poller for a light ({})", logId, e);
    } finally {
        lock.unlock();
    }
}
 
源代码15 项目: smarthome   文件: LifxLightDiscovery.java
@Override
protected void startBackgroundDiscovery() {
    logger.debug("Starting the LIFX device background discovery");

    ScheduledFuture<?> localDiscoveryJob = discoveryJob;
    if (localDiscoveryJob == null || localDiscoveryJob.isCancelled()) {
        discoveryJob = scheduler.scheduleWithFixedDelay(this::doScan, 0, REFRESH_INTERVAL, TimeUnit.SECONDS);
    }
}
 
源代码16 项目: dubbox   文件: HeaderExchangeServer.java
private void stopHeartbeatTimer() {
    try {
        ScheduledFuture<?> timer = heatbeatTimer;
        if (timer != null && ! timer.isCancelled()) {
            timer.cancel(true);
        }
    } catch (Throwable t) {
        logger.warn(t.getMessage(), t);
    } finally {
        heatbeatTimer =null;
    }
}
 
源代码17 项目: smarthome   文件: PollingUsbSerialScanner.java
/**
 * Stops repeatedly scanning for newly added and removed USB devices. This can be restarted using
 * {@link #startBackgroundScanning()}.
 */
@Override
public synchronized void stopBackgroundScanning() {
    logger.debug("Stopping USB-Serial background discovery");
    ScheduledFuture<?> currentBackgroundScanningJob = backgroundScanningJob;
    if (currentBackgroundScanningJob != null && !currentBackgroundScanningJob.isCancelled()) {
        if (currentBackgroundScanningJob.cancel(true)) {
            backgroundScanningJob = null;
            logger.debug("Stopped USB-serial background discovery");
        }
    }
}
 
public boolean isCancelled() {
    ScheduledFuture<?> future = this.future;
    if (future == null) return true;
    return future.isCancelled();
}
 
源代码19 项目: Conversations   文件: JingleRtpConnection.java
private void cancelRingingTimeout() {
    final ScheduledFuture<?> future = this.ringingTimeoutFuture;
    if (future != null && !future.isCancelled()) {
        future.cancel(false);
    }
}
 
源代码20 项目: davos   文件: ScheduleExecutor.java
public void stopSchedule(Long id) throws ScheduleNotRunningException {

        if (runningSchedules.containsKey(id)) {

            LOGGER.info("Stopping schedule {}", id);

            ScheduledFuture<?> future = runningSchedules.get(id).getFuture();
            
            if (!future.isCancelled()) {

                future.cancel(true);
                runningSchedules.remove(id);
                LOGGER.info("Schedule should now be stopped");
            }

        } else {
            throw new ScheduleNotRunningException();
        }
    }