List of usage examples for com.google.common.util.concurrent ListenableScheduledFuture isCancelled
boolean isCancelled();
From source file:org.opendaylight.sxp.core.SxpConnection.java
/** * Sets SxpConnection specific Timer// w ww. jav a 2 s .c o m * * @param timerType Type of Timer that will be set * @param period Time period to wait till execution in Seconds * @return ListenableScheduledFuture callback * @throws UnknownTimerTypeException If current TimerType isn't supported */ public synchronized ListenableScheduledFuture<?> setTimer(TimerType timerType, int period) throws UnknownTimerTypeException { SxpTimerTask timer; switch (timerType) { case DeleteHoldDownTimer: timer = new DeleteHoldDownTimerTask(this, period); break; case HoldTimer: timer = new HoldTimerTask(this, period); break; case KeepAliveTimer: timer = new KeepAliveTimerTask(this, period); break; case ReconciliationTimer: timer = new ReconcilationTimerTask(this, period); break; default: throw new UnknownTimerTypeException(timerType); } ListenableScheduledFuture<?> timer_ = getTimer(timerType); if (period > 0 && (timer_ == null || !timer_.isCancelled())) { return this.setTimer(timerType, owner.getWorker().scheduleTask(timer, period, TimeUnit.SECONDS)); } else { return this.setTimer(timerType, null); } }
From source file:org.opendaylight.sxp.core.SxpNode.java
/** * Sets SxpNode specific Timer/*from w w w .j a v a 2 s . com*/ * * @param timerType Type of Timer that will be set * @param period Time period to wait till execution in Seconds * @return ListenableScheduledFuture callback * @throws UnknownTimerTypeException If current TimerType isn't supported */ public ListenableScheduledFuture<?> setTimer(TimerType timerType, int period) throws UnknownTimerTypeException { synchronized (timers) { SxpTimerTask timer; switch (timerType) { case RetryOpenTimer: timer = new RetryOpenTimerTask(this, period); break; default: throw new UnknownTimerTypeException(timerType); } ListenableScheduledFuture<?> timer_ = getTimer(timerType); if (period > 0 && (timer_ == null || !timer_.isCancelled())) { return this.setTimer(timerType, getWorker().scheduleTask(timer, period, TimeUnit.SECONDS)); } else { return this.setTimer(timerType, null); } } }
From source file:io.druid.server.lookup.cache.LookupCoordinatorManager.java
@LifecycleStart public void start() { synchronized (startStopSync) { if (started) { return; }/*from ww w . j a v a2 s .c o m*/ if (executorService.isShutdown()) { throw new ISE("Cannot restart after stop!"); } lookupMapConfigRef = configManager.watch(LOOKUP_CONFIG_KEY, new TypeReference<Map<String, Map<String, Map<String, Object>>>>() { }, null); final ListenableScheduledFuture backgroundManagerFuture = this.backgroundManagerFuture = executorService .scheduleWithFixedDelay(new Runnable() { @Override public void run() { final Map<String, Map<String, Map<String, Object>>> allLookupTiers = lookupMapConfigRef .get(); // Sanity check for if we are shutting down if (Thread.currentThread().isInterrupted()) { LOG.info("Not updating lookups because process was interrupted"); return; } if (!started) { LOG.info("Not started. Returning"); return; } if (allLookupTiers == null) { LOG.info("Not updating lookups because no data exists"); return; } for (final String tier : allLookupTiers.keySet()) { try { final Map<String, Map<String, Object>> allLookups = allLookupTiers.get(tier); final Map<String, Map<String, Object>> oldLookups = prior_update.get(tier); final Collection<String> drops; if (oldLookups == null) { drops = ImmutableList.of(); } else { drops = Sets.difference(oldLookups.keySet(), allLookups.keySet()); } if (allLookupTiers == prior_update) { LOG.debug("No updates"); updateAllNewOnTier(tier, allLookups); } else { updateAllOnTier(tier, allLookups); deleteAllOnTier(tier, drops); } } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw Throwables.propagate(e); } catch (Exception e) { LOG.error(e, "Error updating lookups for tier [%s]. Will try again soon", tier); } } prior_update = allLookupTiers; } }, 0, lookupCoordinatorManagerConfig.getPeriod(), TimeUnit.MILLISECONDS); Futures.addCallback(backgroundManagerFuture, new FutureCallback<Object>() { @Override public void onSuccess(@Nullable Object result) { backgroundManagerExitedLatch.countDown(); LOG.debug("Exited background lookup manager"); } @Override public void onFailure(Throwable t) { backgroundManagerExitedLatch.countDown(); if (backgroundManagerFuture.isCancelled()) { LOG.info("Background lookup manager exited"); LOG.trace(t, "Background lookup manager exited with throwable"); } else { LOG.makeAlert(t, "Background lookup manager exited with error!").emit(); } } }); started = true; LOG.debug("Started"); } }