Java 类com.google.common.util.concurrent.ListenableScheduledFuture 实例源码

项目:centraldogma    文件:DefaultMirroringService.java   
public synchronized void start(CommandExecutor commandExecutor) {
    if (isStarted()) {
        return;
    }

    this.commandExecutor = requireNonNull(commandExecutor, "commandExecutor");

    scheduler = MoreExecutors.listeningDecorator(Executors.newSingleThreadScheduledExecutor(
            new DefaultThreadFactory("mirroring-scheduler", true)));

    worker = MoreExecutors.listeningDecorator(
            new ThreadPoolExecutor(0, numThreads, 1, TimeUnit.MINUTES, new SynchronousQueue<>(),
                                   new DefaultThreadFactory("mirroring-worker", true)));

    final ListenableScheduledFuture<?> future = scheduler.scheduleWithFixedDelay(
            this::schedulePendingMirrors,
            TICK.getSeconds(), TICK.getSeconds(), TimeUnit.SECONDS);

    FuturesExtra.addFailureCallback(
            future,
            cause -> logger.error("Git-to-CD mirroring scheduler stopped due to an unexpected exception:",
                                  cause));
}
项目:athena    文件:MastershipLoadBalancer.java   
private void scheduleBalance() {
    if (isLeader.get() && nextTask.get() == null) {

        ListenableScheduledFuture task =
                executorService.schedule(mastershipAdminService::balanceRoles,
                        SCHEDULE_PERIOD, TimeUnit.SECONDS);
        task.addListener(() -> {
                    log.info("Completed balance roles");
                    nextTask.set(null);
                }, MoreExecutors.directExecutor()
        );
        if (!nextTask.compareAndSet(null, task)) {
            task.cancel(false);
        }
    }
}
项目:age3-nanorobots    文件:HazelcastDiscoveryService.java   
@Override public void start() {
    log.debug("Discovery service starting.");
    log.debug("Hazelcast instance: {}.", hazelcastInstance);
    log.debug("Neighbourhood map: {}.", members);
    running.set(true);
    hazelcastInstance.getLifecycleService().addLifecycleListener(this::onHazelcastStateChange);
    log.debug("Waiting for initialization to complete.");
    updateMap();
    final ListenableScheduledFuture<?> mapUpdateTask = executorService.scheduleAtFixedRate(this::updateMap, 10L,
                                                                                           10L, TimeUnit.SECONDS);
    Futures.addCallback(mapUpdateTask, new FutureCallback<Object>() {
        @Override public void onSuccess(final Object result) {
            // Empty
        }

        @Override public void onFailure(final @NonNull Throwable t) {
            log.error("Map update failed.", t);
        }
    });
    log.info("Discovery service started.");
}
项目:cloudbreak    文件:SyncPollingScheduler.java   
public T schedule(PollTask<T> task, int interval, int maxAttempt, int maxFailureTolerant) throws ExecutionException, InterruptedException, TimeoutException {
    T result;
    int actualFailureTolerant = 0;
    for (int i = 0; i < maxAttempt; i++) {
        if (task.cancelled()) {
            throw new CancellationException("Task was cancelled.");
        }
        try {
            ListenableScheduledFuture<T> ft = schedule(task, interval);
            result = ft.get();
            if (task.completed(result)) {
                return result;
            }
        } catch (Exception ex) {
            actualFailureTolerant++;
            if (actualFailureTolerant >= maxFailureTolerant) {
                throw ex;
            }
        }
    }
    throw new TimeoutException(String.format("Task did not finished within %d seconds", interval * maxAttempt));
}
项目:guava-mock    文件:SameThreadScheduledExecutorService.java   
@Override
public ListenableScheduledFuture<?> schedule(Runnable command, long delay,
    TimeUnit unit) {
  Preconditions.checkNotNull(command, "command must not be null");
  Preconditions.checkNotNull(unit, "unit must not be null!");
  return schedule(java.util.concurrent.Executors.callable(command),
      delay, unit);
}
项目:guava-mock    文件:SameThreadScheduledExecutorService.java   
@Override
public <V> ListenableScheduledFuture<V> schedule(final Callable<V> callable,
    long delay, TimeUnit unit) {
  Preconditions.checkNotNull(callable, "callable must not be null!");
  Preconditions.checkNotNull(unit, "unit must not be null!");
  ListenableFuture<V> delegateFuture = submit(callable);
  return new ImmediateScheduledFuture<V>(delegateFuture);
}
项目:googles-monorepo-demo    文件:SameThreadScheduledExecutorService.java   
@Override
public ListenableScheduledFuture<?> schedule(Runnable command, long delay,
    TimeUnit unit) {
  Preconditions.checkNotNull(command, "command must not be null");
  Preconditions.checkNotNull(unit, "unit must not be null!");
  return schedule(java.util.concurrent.Executors.callable(command),
      delay, unit);
}
项目:googles-monorepo-demo    文件:SameThreadScheduledExecutorService.java   
@Override
public <V> ListenableScheduledFuture<V> schedule(final Callable<V> callable,
    long delay, TimeUnit unit) {
  Preconditions.checkNotNull(callable, "callable must not be null!");
  Preconditions.checkNotNull(unit, "unit must not be null!");
  ListenableFuture<V> delegateFuture = submit(callable);
  return new ImmediateScheduledFuture<V>(delegateFuture);
}
项目:intellij    文件:WebExperimentSyncer.java   
private void scheduleNextRefresh(boolean refreshWasSuccessful) {
  int delayInMinutes =
      refreshWasSuccessful ? SUCESSFUL_DOWNLOAD_DELAY_MINUTES : DOWNLOAD_FAILURE_DELAY_MINUTES;
  ListenableScheduledFuture<String> refreshResults =
      executor.schedule(new WebExperimentsDownloader(), delayInMinutes, TimeUnit.MINUTES);
  refreshResults.addListener(
      new WebExperimentsResultProcessor(refreshResults), MoreExecutors.directExecutor());
}
项目:guava-libraries    文件:SameThreadScheduledExecutorService.java   
@Override
public ListenableScheduledFuture<?> schedule(Runnable command, long delay,
    TimeUnit unit) {
  Preconditions.checkNotNull(command, "command must not be null");
  Preconditions.checkNotNull(unit, "unit must not be null!");
  return schedule(java.util.concurrent.Executors.callable(command),
      delay, unit);
}
项目:guava-libraries    文件:SameThreadScheduledExecutorService.java   
@Override
public <V> ListenableScheduledFuture<V> schedule(final Callable<V> callable,
    long delay, TimeUnit unit) {
  Preconditions.checkNotNull(callable, "callable must not be null!");
  Preconditions.checkNotNull(unit, "unit must not be null!");
  ListenableFuture<V> delegateFuture = submit(callable);
  return new ImmediateScheduledFuture<V>(delegateFuture);
}
项目:otroslogviewer    文件:JumpToCodeSelectionListener.java   
@Override
public void valueChanged(ListSelectionEvent e) {
  boolean hasFocus = otrosApplication.getApplicationJFrame().isFocused();
  final boolean enabled = otrosApplication.getConfiguration().getBoolean(ConfKeys.JUMP_TO_CODE_AUTO_JUMP_ENABLED, false);
  if (hasFocus && enabled && !e.getValueIsAdjusting()) {
    try {
      final LogData logData = dataTableModel.getLogData(table.convertRowIndexToModel(e.getFirstIndex()));
      Optional<Integer> line = Optional.empty();
      if (StringUtils.isNotBlank(logData.getLine()) && StringUtils.isAlphanumeric(logData.getLine())) {
        line = Optional.of(Integer.valueOf(logData.getLine()));
      }
      final LocationInfo li = new LocationInfo(
        Optional.ofNullable(logData.getClazz()).orElseGet(logData::getLoggerName),
        logData.getMethod(), logData.getFile(),
        line,
        Optional.ofNullable(logData.getMessage()));
      final JumpToCodeService jumpToCodeService = otrosApplication.getServices().getJumpToCodeService();
      final boolean ideAvailable = jumpToCodeService.isIdeAvailable();
      if (ideAvailable) {
        scheduledJump.map(input -> {
          input.cancel(false);
          return Boolean.TRUE;
        });
        ListeningScheduledExecutorService scheduledExecutorService = otrosApplication.getServices().getTaskSchedulerService().getListeningScheduledExecutorService();
        delayMs = 300;
        ListenableScheduledFuture<?> jump = scheduledExecutorService.schedule(
          new JumpRunnable(li, jumpToCodeService), delayMs, TimeUnit.MILLISECONDS
        );

        scheduledJump = Optional.of(jump);
      }
    } catch (Exception e1) {
      LOGGER.warn("Can't perform jump to code: " + e1.getMessage(), e1);
      e1.printStackTrace();
    }

  }
}
项目:guava    文件:SameThreadScheduledExecutorService.java   
@Override
public <V> ListenableScheduledFuture<V> schedule(
    final Callable<V> callable, long delay, TimeUnit unit) {
  Preconditions.checkNotNull(callable, "callable must not be null!");
  Preconditions.checkNotNull(unit, "unit must not be null!");
  ListenableFuture<V> delegateFuture = submit(callable);
  return new ImmediateScheduledFuture<V>(delegateFuture);
}
项目:guava    文件:SameThreadScheduledExecutorService.java   
@Override
public <V> ListenableScheduledFuture<V> schedule(
    final Callable<V> callable, long delay, TimeUnit unit) {
  Preconditions.checkNotNull(callable, "callable must not be null!");
  Preconditions.checkNotNull(unit, "unit must not be null!");
  ListenableFuture<V> delegateFuture = submit(callable);
  return new ImmediateScheduledFuture<V>(delegateFuture);
}
项目:guava-mock    文件:SameThreadScheduledExecutorService.java   
@Override
public ListenableScheduledFuture<?> scheduleAtFixedRate(Runnable command,
    long initialDelay, long period, TimeUnit unit) {
  throw new UnsupportedOperationException(
      "scheduleAtFixedRate is not supported.");
}
项目:guava-mock    文件:SameThreadScheduledExecutorService.java   
@Override
public ListenableScheduledFuture<?> scheduleWithFixedDelay(Runnable command,
    long initialDelay, long delay, TimeUnit unit) {
  throw new UnsupportedOperationException(
      "scheduleWithFixedDelay is not supported.");
}
项目:guava-mock    文件:TestingExecutors.java   
@Override public <V> ListenableScheduledFuture<V> schedule(
    Callable<V> callable, long delay, TimeUnit unit) {
  return NeverScheduledFuture.create();
}
项目:guava-mock    文件:TestingExecutors.java   
@Override public ListenableScheduledFuture<?> schedule(
    Runnable command, long delay, TimeUnit unit) {
  return NeverScheduledFuture.create();
}
项目:guava-mock    文件:TestingExecutors.java   
@Override public ListenableScheduledFuture<?> scheduleAtFixedRate(
    Runnable command, long initialDelay, long period, TimeUnit unit) {
  return NeverScheduledFuture.create();
}
项目:guava-mock    文件:TestingExecutors.java   
@Override public ListenableScheduledFuture<?> scheduleWithFixedDelay(
    Runnable command, long initialDelay, long delay, TimeUnit unit) {
  return NeverScheduledFuture.create();
}
项目:googles-monorepo-demo    文件:SameThreadScheduledExecutorService.java   
@Override
public ListenableScheduledFuture<?> scheduleAtFixedRate(Runnable command,
    long initialDelay, long period, TimeUnit unit) {
  throw new UnsupportedOperationException(
      "scheduleAtFixedRate is not supported.");
}
项目:googles-monorepo-demo    文件:SameThreadScheduledExecutorService.java   
@Override
public ListenableScheduledFuture<?> scheduleWithFixedDelay(Runnable command,
    long initialDelay, long delay, TimeUnit unit) {
  throw new UnsupportedOperationException(
      "scheduleWithFixedDelay is not supported.");
}
项目:googles-monorepo-demo    文件:TestingExecutors.java   
@Override public <V> ListenableScheduledFuture<V> schedule(
    Callable<V> callable, long delay, TimeUnit unit) {
  return NeverScheduledFuture.create();
}
项目:googles-monorepo-demo    文件:TestingExecutors.java   
@Override public ListenableScheduledFuture<?> schedule(
    Runnable command, long delay, TimeUnit unit) {
  return NeverScheduledFuture.create();
}
项目:googles-monorepo-demo    文件:TestingExecutors.java   
@Override public ListenableScheduledFuture<?> scheduleAtFixedRate(
    Runnable command, long initialDelay, long period, TimeUnit unit) {
  return NeverScheduledFuture.create();
}
项目:googles-monorepo-demo    文件:TestingExecutors.java   
@Override public ListenableScheduledFuture<?> scheduleWithFixedDelay(
    Runnable command, long initialDelay, long delay, TimeUnit unit) {
  return NeverScheduledFuture.create();
}
项目:helloiot    文件:CompletableAsync.java   
public static ListenableScheduledFuture<?> scheduleTask(long millis, Runnable r) {
    return service.schedule(r, millis, TimeUnit.MILLISECONDS);
}
项目:helloiot    文件:CompletableAsync.java   
public static ListenableScheduledFuture<?> scheduleTask(long millis, long period, Runnable r) {
    return service.scheduleAtFixedRate(r, millis, period, TimeUnit.MILLISECONDS);
}
项目:knowledgestore    文件:Util.java   
@Override
public ListenableScheduledFuture<?> schedule(final Runnable command, final long delay,
        final TimeUnit unit) {
    return delegate().schedule(wrap(command, MDC.getCopyOfContextMap()), delay, unit);
}
项目:knowledgestore    文件:Util.java   
@Override
public <V> ListenableScheduledFuture<V> schedule(final Callable<V> callable,
        final long delay, final TimeUnit unit) {
    return delegate().schedule(wrap(callable, MDC.getCopyOfContextMap()), delay, unit);
}
项目:knowledgestore    文件:Util.java   
@Override
public ListenableScheduledFuture<?> scheduleAtFixedRate(final Runnable command,
        final long initialDelay, final long period, final TimeUnit unit) {
    return delegate().scheduleAtFixedRate(wrap(command, MDC.getCopyOfContextMap()),
            initialDelay, period, unit);
}
项目:knowledgestore    文件:Util.java   
@Override
public ListenableScheduledFuture<?> scheduleWithFixedDelay(final Runnable command,
        final long initialDelay, final long delay, final TimeUnit unit) {
    return delegate().scheduleWithFixedDelay(wrap(command, MDC.getCopyOfContextMap()),
            initialDelay, delay, unit);
}
项目:guava-libraries    文件:SameThreadScheduledExecutorService.java   
@Override
public ListenableScheduledFuture<?> scheduleAtFixedRate(Runnable command,
    long initialDelay, long period, TimeUnit unit) {
  throw new UnsupportedOperationException(
      "scheduleAtFixedRate is not supported.");
}
项目:guava-libraries    文件:SameThreadScheduledExecutorService.java   
@Override
public ListenableScheduledFuture<?> scheduleWithFixedDelay(Runnable command,
    long initialDelay, long delay, TimeUnit unit) {
  throw new UnsupportedOperationException(
      "scheduleWithFixedDelay is not supported.");
}
项目:guava-libraries    文件:TestingExecutors.java   
@Override public <V> ListenableScheduledFuture<V> schedule(
    Callable<V> callable, long delay, TimeUnit unit) {
  return NeverScheduledFuture.create();
}
项目:guava-libraries    文件:TestingExecutors.java   
@Override public ListenableScheduledFuture<?> schedule(
    Runnable command, long delay, TimeUnit unit) {
  return NeverScheduledFuture.create();
}
项目:guava-libraries    文件:TestingExecutors.java   
@Override public ListenableScheduledFuture<?> scheduleAtFixedRate(
    Runnable command, long initialDelay, long period, TimeUnit unit) {
  return NeverScheduledFuture.create();
}
项目:guava-libraries    文件:TestingExecutors.java   
@Override public ListenableScheduledFuture<?> scheduleWithFixedDelay(
    Runnable command, long initialDelay, long delay, TimeUnit unit) {
  return NeverScheduledFuture.create();
}
项目:age3-nanorobots    文件:WorkerCommunication.java   
ListenableScheduledFuture<?> scheduleAtFixedRate(
Runnable command, long initialDelay, long period, TimeUnit unit);
项目:age3-nanorobots    文件:DefaultWorkerService.java   
@Override public ListenableScheduledFuture<?> scheduleAtFixedRate(final Runnable command, final long initialDelay,
                                                                  final long period, final TimeUnit unit) {
    return executorService.scheduleAtFixedRate(command, initialDelay, period, unit);
}