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


Java ListenableFutureTask类代码示例

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


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

示例1: callFromMainThread

import com.google.common.util.concurrent.ListenableFutureTask; //导入依赖的package包/类
public <V> ListenableFuture<V> callFromMainThread(Callable<V> callable)
{
    Validate.notNull(callable);

    if (!this.isCallingFromMinecraftThread() && !this.isServerStopped())
    {
        ListenableFutureTask<V> listenablefuturetask = ListenableFutureTask.<V>create(callable);

        synchronized (this.futureTaskQueue)
        {
            this.futureTaskQueue.add(listenablefuturetask);
            return listenablefuturetask;
        }
    }
    else
    {
        try
        {
            return Futures.<V>immediateFuture(callable.call());
        }
        catch (Exception exception)
        {
            return Futures.immediateFailedCheckedFuture(exception);
        }
    }
}
 
开发者ID:Notoh,项目名称:DecompiledMinecraft,代码行数:27,代码来源:MinecraftServer.java

示例2: addScheduledTask

import com.google.common.util.concurrent.ListenableFutureTask; //导入依赖的package包/类
public <V> ListenableFuture<V> addScheduledTask(Callable<V> callableToSchedule)
{
    Validate.notNull(callableToSchedule);

    if (!this.isCallingFromMinecraftThread())
    {
        ListenableFutureTask<V> listenablefuturetask = ListenableFutureTask.<V>create(callableToSchedule);

        synchronized (this.scheduledTasks)
        {
            this.scheduledTasks.add(listenablefuturetask);
            return listenablefuturetask;
        }
    }
    else
    {
        try
        {
            return Futures.<V>immediateFuture(callableToSchedule.call());
        }
        catch (Exception exception)
        {
            return Futures.immediateFailedCheckedFuture(exception);
        }
    }
}
 
开发者ID:Notoh,项目名称:DecompiledMinecraft,代码行数:27,代码来源:Minecraft.java

示例3: addScheduledTask

import com.google.common.util.concurrent.ListenableFutureTask; //导入依赖的package包/类
public <V> ListenableFuture<V> addScheduledTask(Callable<V> callableToSchedule) {
	Validate.notNull(callableToSchedule);

	if (!this.isCallingFromMinecraftThread()) {
		ListenableFutureTask<V> listenablefuturetask = ListenableFutureTask.<V>create(callableToSchedule);

		synchronized (this.scheduledTasks) {
			this.scheduledTasks.add(listenablefuturetask);
			return listenablefuturetask;
		}
	} else {
		try {
			return Futures.<V>immediateFuture(callableToSchedule.call());
		} catch (Exception exception) {
			return Futures.immediateFailedCheckedFuture(exception);
		}
	}
}
 
开发者ID:SkidJava,项目名称:BaseClient,代码行数:19,代码来源:Minecraft.java

示例4: addScheduledTask

import com.google.common.util.concurrent.ListenableFutureTask; //导入依赖的package包/类
public <V> ListenableFuture<V> addScheduledTask(Callable<V> callableToSchedule)
{
    Validate.notNull(callableToSchedule);

    if (this.isCallingFromMinecraftThread())
    {
        try
        {
            return Futures.<V>immediateFuture(callableToSchedule.call());
        }
        catch (Exception exception)
        {
            return Futures.immediateFailedCheckedFuture(exception);
        }
    }
    else
    {
        ListenableFutureTask<V> listenablefuturetask = ListenableFutureTask.<V>create(callableToSchedule);

        synchronized (this.scheduledTasks)
        {
            this.scheduledTasks.add(listenablefuturetask);
            return listenablefuturetask;
        }
    }
}
 
开发者ID:NSExceptional,项目名称:Zombe-Modpack,代码行数:27,代码来源:Minecraft.java

示例5: main

import com.google.common.util.concurrent.ListenableFutureTask; //导入依赖的package包/类
public static void main(String[] args) {
    ExecutorService executorService = Executors.newSingleThreadExecutor();
    // create ListenableFutureTask instance
    ListenableFutureTask<String> listenableFutureTask = ListenableFutureTask.create(() -> {
        log.info("listenable future begin to execute");
        TimeUnit.SECONDS.sleep(5);  // monitor
        return "listenable future task done";
    });
    // add three listeners, use MoreExecutors.directExecutor() to execute Runnable in ExecutorServcie
    listenableFutureTask.addListener(()-> log.info("listener one execute"), MoreExecutors.directExecutor());
    listenableFutureTask.addListener(() -> log.info("listener two execute"), MoreExecutors.directExecutor());
    listenableFutureTask.addListener(() -> log.info("listener three execute"), MoreExecutors.directExecutor());
    // execute listenable future task
    executorService.execute(listenableFutureTask);
    // ExecutorService.shutdown()
    executorService.shutdown();
}
 
开发者ID:xitongjiagoushi,项目名称:java-basic-skills,代码行数:18,代码来源:ListenableFutureDemo.java

示例6: main

import com.google.common.util.concurrent.ListenableFutureTask; //导入依赖的package包/类
public static void main(String[] args) throws BrokenBarrierException, InterruptedException {
    final CyclicBarrier barrier = new CyclicBarrier(4);
    ExecutorService executorService = Executors.newSingleThreadExecutor();
    ListenableFutureTask<String> listenableFutureTask = ListenableFutureTask.create(() -> {
        log.info("listenable future begin to execute");
        TimeUnit.SECONDS.sleep(5);
        return "listenable future task done";
    });
    // !!!!! barrier貌似并不能实现,对比下CountDownLatch,两种控制的应用场景
    Futures.addCallback(listenableFutureTask, new BarrieredSimpleFutureCallback(0, barrier), executorService);
    Futures.addCallback(listenableFutureTask, new BarrieredSimpleFutureCallback(1, barrier), executorService);
    Futures.addCallback(listenableFutureTask, new BarrieredSimpleFutureCallback(2, barrier), executorService);
    executorService.execute(listenableFutureTask);

    barrier.await();
    executorService.shutdown();
}
 
开发者ID:xitongjiagoushi,项目名称:java-basic-skills,代码行数:18,代码来源:CallbackListenableFutureBarrierDemo.java

示例7: main

import com.google.common.util.concurrent.ListenableFutureTask; //导入依赖的package包/类
public static void main(String[] args) throws InterruptedException, BrokenBarrierException {
    final CountDownLatch latch = new CountDownLatch(3);
    //ListeningExecutorService executorService = MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor());
    ExecutorService executorService = Executors.newSingleThreadExecutor();
    ListenableFutureTask<String> listenableFutureTask = ListenableFutureTask.create(() -> {
        log.info("listenable future begin to execute");
        TimeUnit.SECONDS.sleep(5);
        return "listenable future task done";
    });
    // add three callbacks, use executorService instance to execute
    Futures.addCallback(listenableFutureTask, new LatchedSimpleFutureCallback(0, latch), executorService);
    Futures.addCallback(listenableFutureTask, new LatchedSimpleFutureCallback(1, latch), executorService);
    Futures.addCallback(listenableFutureTask, new LatchedSimpleFutureCallback(2, latch), executorService);
    // execute listenable future task
    executorService.execute(listenableFutureTask);
    // ensure listener execution before ExecutorService#shutdown
    if (latch.getCount() > 0) {
        latch.await();
    }
    // ExecutorService.shutdown()
    executorService.shutdown();
}
 
开发者ID:xitongjiagoushi,项目名称:java-basic-skills,代码行数:23,代码来源:CallbackListenableFutureLatchDemo.java

示例8: AbstractJobInstance

import com.google.common.util.concurrent.ListenableFutureTask; //导入依赖的package包/类
public AbstractJobInstance(Config config) {
    Assert.notNull(config.parameters, "parameters is null");
    Assert.notNull(config.job, "job is null");
    Assert.notNull(config.jobsManager, "jobsManager is null");
    Assert.notNull(config.info, "info is null");
    this.jobContext = new JobContext(this, config.parameters);
    this.infoRef = new AtomicReference<>(config.info);
    this.manager = config.jobsManager;
    // create wait future with stub
    this.atEndFuture = SettableFuture.create();
    this.job = config.job;
    this.authentication = config.authentication;
    this.watcher = config.watcher;
    this.cancelFuture = ListenableFutureTask.create(this::innerCancel);
    this.startFuture = ListenableFutureTask.create(this::innerStart);
}
 
开发者ID:codeabovelab,项目名称:haven-platform,代码行数:17,代码来源:AbstractJobInstance.java

示例9: sheduleUpdateHtml

import com.google.common.util.concurrent.ListenableFutureTask; //导入依赖的package包/类
private ListenableFuture<Void> sheduleUpdateHtml(final WaveId waveId) {
  ListenableFutureTask<Void> task = processingWaves.get(waveId);
  if (task == null) {
    task = ListenableFutureTask.create(new Callable<Void>() {

      @Override
      public Void call() throws Exception {
        processingWaves.remove(waveId);
        try {
          updateHtml(waveId);
        } catch (Exception e) {
          LOG.log(Level.SEVERE, "Failed to make HTML for " + waveId.serialise(), e);
          throw e;
        }
        return null;
      }
    });
    processingWaves.put(waveId, task);
    executor.schedule(task, WAVE_UPDATE_HTML_DELAY_MIN, TimeUnit.MINUTES);
  }
  return task;
}
 
开发者ID:jorkey,项目名称:Wiab.pro,代码行数:23,代码来源:WaveHtmlRendererImpl.java

示例10: close

import com.google.common.util.concurrent.ListenableFutureTask; //导入依赖的package包/类
@Override
public ListenableFuture close() {
  checkOpened();
  writeLock.lock();
  try {
    closingFutureTask = ListenableFutureTask.<Void>create(closingTask);
    if (latestVersionToPersist != null) {
      deferredClosing = true;
    } else {
      persistExecutor.execute(closingFutureTask);
    }
    return closingFutureTask;
  } finally {
    writeLock.unlock();
  }
}
 
开发者ID:jorkey,项目名称:Wiab.pro,代码行数:17,代码来源:DeltaWaveletStateImpl.java

示例11: sheduleCommitIndex

import com.google.common.util.concurrent.ListenableFutureTask; //导入依赖的package包/类
private ListenableFutureTask<Void> sheduleCommitIndex() {
  ListenableFutureTask<Void> task = commitTask.get();
  if (task == null) {
    task = ListenableFutureTask.create(new Callable<Void>() {

      @Override
      public Void call() throws Exception {
        commitTask.set(null);
        try {
          LOG.info("Commiting indexes...");
          indexWriter.commit();
          LOG.info("Commiting indexes is complete");
        } catch (IndexException e) {
          LOG.log(Level.SEVERE, "Index commit failed", e);
          throw e;
        }
        return null;
      }
    });
    commitTask.set(task);
    indexExecutor.schedule(task, WAVE_COMMIT_DELAY_SEC, TimeUnit.SECONDS);
  }
  return task;
}
 
开发者ID:jorkey,项目名称:Wiab.pro,代码行数:25,代码来源:LuceneSearchImpl.java

示例12: loadSegmentWaveletState

import com.google.common.util.concurrent.ListenableFutureTask; //导入依赖的package包/类
@VisibleForTesting
static ListenableFuture<SegmentWaveletState> loadSegmentWaveletState(
  final WaveletName waveletName,
  final WaveletStateFactory waveletStateFactory,
  Executor waveletLoadExecutor) {
  ListenableFutureTask<SegmentWaveletState> task
    = ListenableFutureTask.<SegmentWaveletState>create(
      new Callable<SegmentWaveletState>() {

        @Override
        public SegmentWaveletState call()
        throws PersistenceException, OperationException, WaveletStateException, InterruptedException, ExecutionException {
          BlockWaveletState blockState = waveletStateFactory.createBlockWaveletState(waveletName);
          blockState.open();
          SegmentWaveletState state = waveletStateFactory.createSegmentWaveletState(waveletName, blockState);
          state.open();
          return state;
        }
      });
  waveletLoadExecutor.execute(task);
  return task;
}
 
开发者ID:jorkey,项目名称:Wiab.pro,代码行数:23,代码来源:WaveServerModule.java

示例13: load

import com.google.common.util.concurrent.ListenableFutureTask; //导入依赖的package包/类
@Override
public ListenableFuture<ArrayChunk> load(final Pair<Integer, Integer> key) throws Exception {
  final PyDebugValue value = myProvider.getDebugValue();
  final PyDebugValue slicedValue =
    new PyDebugValue(myProvider.getSliceText(), value.getType(), value.getValue(), value.isContainer(), value.isErrorOnEval(),
                     value.getParent(), value.getFrameAccessor());

  ListenableFutureTask<ArrayChunk> task = ListenableFutureTask.create(new Callable<ArrayChunk>() {
    @Override
    public ArrayChunk call() throws Exception {
      return value.getFrameAccessor()
        .getArrayItems(slicedValue, key.first, key.second, Math.min(CHUNK_ROW_SIZE, getRowCount() - key.first),
                       Math.min(CHUNK_COL_SIZE, getColumnCount() - key.second),
                       myProvider.getFormat());
    }
  });

  myExecutorService.execute(task);

  return task;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:AsyncArrayTableModel.java

示例14: testOneSlice

import com.google.common.util.concurrent.ListenableFutureTask; //导入依赖的package包/类
private static void testOneSlice(final String id, final NavigableSet<Integer> test, final NavigableSet<Integer> canon, List<ListenableFuture<?>> results)
{
    ListenableFutureTask<?> f = ListenableFutureTask.create(new Runnable()
    {

        @Override
        public void run()
        {
            test(id + " Count", test.size(), canon.size());
            testEqual(id, test.iterator(), canon.iterator());
            testEqual(id + "->DSCI", test.descendingIterator(), canon.descendingIterator());
            testEqual(id + "->DSCS", test.descendingSet().iterator(), canon.descendingSet().iterator());
            testEqual(id + "->DSCS->DSCI", test.descendingSet().descendingIterator(), canon.descendingSet().descendingIterator());
        }
    }, null);
    results.add(f);
    COMPARE.execute(f);
}
 
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:19,代码来源:LongBTreeTest.java

示例15: a

import com.google.common.util.concurrent.ListenableFutureTask; //导入依赖的package包/类
public <V> ListenableFuture<V> a(Callable<V> callable) {
    Validate.notNull(callable);
    if (!this.isMainThread() && !this.isStopped()) {
        ListenableFutureTask listenablefuturetask = ListenableFutureTask.create(callable);
        Queue queue = this.j;

        synchronized (this.j) {
            this.j.add(listenablefuturetask);
            return listenablefuturetask;
        }
    } else {
        try {
            return Futures.immediateFuture(callable.call());
        } catch (Exception exception) {
            return Futures.immediateFailedCheckedFuture(exception);
        }
    }
}
 
开发者ID:Prismarine,项目名称:Prismarine,代码行数:19,代码来源:MinecraftServer.java


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