当前位置: 首页>>代码示例>>Java>>正文


Java ListenableScheduledFuture类代码示例

本文整理汇总了Java中com.google.common.util.concurrent.ListenableScheduledFuture的典型用法代码示例。如果您正苦于以下问题:Java ListenableScheduledFuture类的具体用法?Java ListenableScheduledFuture怎么用?Java ListenableScheduledFuture使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ListenableScheduledFuture类属于com.google.common.util.concurrent包,在下文中一共展示了ListenableScheduledFuture类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: start

import com.google.common.util.concurrent.ListenableScheduledFuture; //导入依赖的package包/类
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));
}
 
开发者ID:line,项目名称:centraldogma,代码行数:24,代码来源:DefaultMirroringService.java

示例2: scheduleBalance

import com.google.common.util.concurrent.ListenableScheduledFuture; //导入依赖的package包/类
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);
        }
    }
}
 
开发者ID:shlee89,项目名称:athena,代码行数:17,代码来源:MastershipLoadBalancer.java

示例3: start

import com.google.common.util.concurrent.ListenableScheduledFuture; //导入依赖的package包/类
@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.");
}
 
开发者ID:Kelleth,项目名称:age3-nanorobots,代码行数:22,代码来源:HazelcastDiscoveryService.java

示例4: schedule

import com.google.common.util.concurrent.ListenableScheduledFuture; //导入依赖的package包/类
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));
}
 
开发者ID:hortonworks,项目名称:cloudbreak,代码行数:23,代码来源:SyncPollingScheduler.java

示例5: schedule

import com.google.common.util.concurrent.ListenableScheduledFuture; //导入依赖的package包/类
@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);
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:9,代码来源:SameThreadScheduledExecutorService.java

示例6: scheduleNextRefresh

import com.google.common.util.concurrent.ListenableScheduledFuture; //导入依赖的package包/类
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());
}
 
开发者ID:bazelbuild,项目名称:intellij,代码行数:9,代码来源:WebExperimentSyncer.java

示例7: valueChanged

import com.google.common.util.concurrent.ListenableScheduledFuture; //导入依赖的package包/类
@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();
    }

  }
}
 
开发者ID:otros-systems,项目名称:otroslogviewer,代码行数:39,代码来源:JumpToCodeSelectionListener.java

示例8: schedule

import com.google.common.util.concurrent.ListenableScheduledFuture; //导入依赖的package包/类
@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);
}
 
开发者ID:google,项目名称:guava,代码行数:9,代码来源:SameThreadScheduledExecutorService.java

示例9: scheduleAtFixedRate

import com.google.common.util.concurrent.ListenableScheduledFuture; //导入依赖的package包/类
@Override
public ListenableScheduledFuture<?> scheduleAtFixedRate(Runnable command,
    long initialDelay, long period, TimeUnit unit) {
  throw new UnsupportedOperationException(
      "scheduleAtFixedRate is not supported.");
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:7,代码来源:SameThreadScheduledExecutorService.java

示例10: scheduleWithFixedDelay

import com.google.common.util.concurrent.ListenableScheduledFuture; //导入依赖的package包/类
@Override
public ListenableScheduledFuture<?> scheduleWithFixedDelay(Runnable command,
    long initialDelay, long delay, TimeUnit unit) {
  throw new UnsupportedOperationException(
      "scheduleWithFixedDelay is not supported.");
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:7,代码来源:SameThreadScheduledExecutorService.java

示例11: schedule

import com.google.common.util.concurrent.ListenableScheduledFuture; //导入依赖的package包/类
@Override public <V> ListenableScheduledFuture<V> schedule(
    Callable<V> callable, long delay, TimeUnit unit) {
  return NeverScheduledFuture.create();
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:5,代码来源:TestingExecutors.java

示例12: scheduleAtFixedRate

import com.google.common.util.concurrent.ListenableScheduledFuture; //导入依赖的package包/类
@Override public ListenableScheduledFuture<?> scheduleAtFixedRate(
    Runnable command, long initialDelay, long period, TimeUnit unit) {
  return NeverScheduledFuture.create();
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:5,代码来源:TestingExecutors.java

示例13: scheduleWithFixedDelay

import com.google.common.util.concurrent.ListenableScheduledFuture; //导入依赖的package包/类
@Override public ListenableScheduledFuture<?> scheduleWithFixedDelay(
    Runnable command, long initialDelay, long delay, TimeUnit unit) {
  return NeverScheduledFuture.create();
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:5,代码来源:TestingExecutors.java

示例14: scheduleTask

import com.google.common.util.concurrent.ListenableScheduledFuture; //导入依赖的package包/类
public static ListenableScheduledFuture<?> scheduleTask(long millis, Runnable r) {
    return service.schedule(r, millis, TimeUnit.MILLISECONDS);
}
 
开发者ID:adrianromero,项目名称:helloiot,代码行数:4,代码来源:CompletableAsync.java

示例15: schedule

import com.google.common.util.concurrent.ListenableScheduledFuture; //导入依赖的package包/类
@Override
public ListenableScheduledFuture<?> schedule(final Runnable command, final long delay,
        final TimeUnit unit) {
    return delegate().schedule(wrap(command, MDC.getCopyOfContextMap()), delay, unit);
}
 
开发者ID:dkmfbk,项目名称:knowledgestore,代码行数:6,代码来源:Util.java


注:本文中的com.google.common.util.concurrent.ListenableScheduledFuture类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。