當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。