本文整理汇总了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));
}
示例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);
}
}
}
示例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.");
}
示例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));
}
示例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);
}
示例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());
}
示例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();
}
}
}
示例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);
}
示例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.");
}
示例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.");
}
示例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();
}
示例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();
}
示例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();
}
示例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);
}
示例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);
}