List of usage examples for com.google.common.util.concurrent ListenableScheduledFuture cancel
boolean cancel(boolean mayInterruptIfRunning);
From source file:org.onosproject.mlb.MastershipLoadBalancer.java
private void scheduleBalance() { if (isLeader.get() && nextTask.get() == null) { ListenableScheduledFuture task = executorService.schedule(mastershipAdminService::balanceRoles, 30, TimeUnit.SECONDS); task.addListener(() -> {/*from w ww. ja va2s. com*/ log.info("Completed balance roles"); nextTask.set(null); }, MoreExecutors.directExecutor()); if (!nextTask.compareAndSet(null, task)) { task.cancel(false); } } }
From source file:io.druid.server.lookup.cache.LookupCoordinatorManager.java
@LifecycleStop public void stop() { synchronized (startStopSync) { if (!started) { LOG.warn("Not started, ignoring stop request"); return; }/*w w w. ja va 2 s . c om*/ started = false; executorService.shutdownNow(); final ListenableScheduledFuture backgroundManagerFuture = this.backgroundManagerFuture; this.backgroundManagerFuture = null; if (backgroundManagerFuture != null && !backgroundManagerFuture.cancel(true)) { LOG.warn("Background lookup manager thread could not be cancelled"); } // NOTE: we can't un-watch the configuration key LOG.debug("Stopped"); } }
From source file:org.opendaylight.sxp.core.SxpNode.java
/** * Sets SxpNode specific Timer/*from www. ja v a 2 s . com*/ * * @param timerType Type of Timer that will be set * @param timer Timer logic * @return ListenableScheduledFuture callback */ private ListenableScheduledFuture<?> setTimer(TimerType timerType, ListenableScheduledFuture<?> timer) { ListenableScheduledFuture<?> t = this.timers.put(timerType, timer); if (t != null && !t.isDone()) { t.cancel(false); } return timer; }
From source file:org.neoscoinj.core.PeerGroup.java
@SuppressWarnings("NonAtomicOperationOnVolatileField") private void setupPinging() { if (getPingIntervalMsec() <= 0) return; // Disabled. vPingTask = executor.scheduleAtFixedRate(new Runnable() { @Override// w w w . j av a 2s. co m public void run() { try { if (getPingIntervalMsec() <= 0) { ListenableScheduledFuture<?> task = vPingTask; if (task != null) { task.cancel(false); vPingTask = null; } return; // Disabled. } for (Peer peer : getConnectedPeers()) { if (peer.getPeerVersionMessage().clientVersion < Pong.MIN_PROTOCOL_VERSION) continue; peer.ping(); } } catch (Throwable e) { log.error("Exception in ping loop", e); // The executor swallows exceptions :( } } }, getPingIntervalMsec(), getPingIntervalMsec(), TimeUnit.MILLISECONDS); }
From source file:org.bitcoinj_extra.core.PeerGroup.java
/** * Sets the period between pings for an individual peer. Setting this lower means more accurate and timely ping * times are available via {@link org.bitcoinj_extra.core.Peer#getLastPingTime()} but it increases load on the * remote node. It defaults to {@link PeerGroup#DEFAULT_PING_INTERVAL_MSEC}. * Setting the value to be <= 0 disables pinging entirely, although you can still request one yourself * using {@link org.bitcoinj_extra.core.Peer#ping()}. *///www . java 2 s. c om public void setPingIntervalMsec(long pingIntervalMsec) { lock.lock(); try { this.pingIntervalMsec = pingIntervalMsec; ListenableScheduledFuture<?> task = vPingTask; if (task != null) task.cancel(false); setupPinging(); } finally { lock.unlock(); } }
From source file:org.bitcoinj_extra.core.PeerGroup.java
@SuppressWarnings("NonAtomicOperationOnVolatileField") private void setupPinging() { if (getPingIntervalMsec() <= 0) return; // Disabled. vPingTask = executor.scheduleAtFixedRate(new Runnable() { @Override// w ww . j ava2 s .com public void run() { try { if (getPingIntervalMsec() <= 0) { ListenableScheduledFuture<?> task = vPingTask; if (task != null) { task.cancel(false); vPingTask = null; } return; // Disabled. } for (Peer peer : getConnectedPeers()) { if (peer.getPeerVersionMessage().clientVersion < params .getProtocolVersionNum(NetworkParameters.ProtocolVersion.PONG)) continue; peer.ping(); } } catch (Throwable e) { log.error("Exception in ping loop", e); // The executor swallows exceptions :( } } }, getPingIntervalMsec(), getPingIntervalMsec(), TimeUnit.MILLISECONDS); }