com.google.common.util.concurrent.SettableFuture.isDone()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(6.7k)|赞(0)|评价(0)|浏览(103)

本文整理了Java中com.google.common.util.concurrent.SettableFuture.isDone()方法的一些代码示例,展示了SettableFuture.isDone()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。SettableFuture.isDone()方法的具体详情如下:
包路径:com.google.common.util.concurrent.SettableFuture
类名称:SettableFuture
方法名:isDone

SettableFuture.isDone介绍

暂无

代码示例

代码示例来源:origin: prestodb/presto

public synchronized ListenableFuture<?> getNotFullFuture()
{
  // if we are full and the current not full future is already complete, create a new one
  if (bufferedBytes.get() > maxBufferedBytes && notFullFuture.isDone()) {
    notFullFuture = SettableFuture.create();
  }
  return notFullFuture;
}

代码示例来源:origin: prestodb/presto

public synchronized void release()
  {
    checkState(!freeFuture.isDone(), "Reference has already been freed");
    count--;
    if (count == 0) {
      freeFuture.set(null);
    }
  }
}

代码示例来源:origin: prestodb/presto

public IndexSnapshot getFinishedIndexSnapshot()
  {
    checkState(indexSnapshotFuture.isDone(), "Update request is not finished");
    return MoreFutures.getFutureValue(indexSnapshotFuture);
  }
}

代码示例来源:origin: google/guava

@Override
 public void run() {
  assertTrue(futureInteger.isDone());
  assertTrue(futureBoolean.isDone());
  throw thrown;
 }
};

代码示例来源:origin: google/guava

@Override
 public ListenableFuture<String> call() throws Exception {
  assertTrue(futureInteger.isDone());
  assertTrue(futureBoolean.isDone());
  return immediateFailedFuture(thrown);
 }
};

代码示例来源:origin: prestodb/presto

public void pause()
{
  if (!future.isDone()) {
    return;
  }
  future = SettableFuture.create();
}

代码示例来源:origin: google/guava

@Override
 public void run() {
  assertTrue(futureInteger.isDone());
  assertTrue(futureBoolean.isDone());
  result[0] =
    createCombinedResult(
      Futures.getUnchecked(futureInteger), Futures.getUnchecked(futureBoolean));
 }
};

代码示例来源:origin: google/guava

public void testSetFuture_stackOverflow() {
 SettableFuture<String> orig = SettableFuture.create();
 SettableFuture<String> prev = orig;
 for (int i = 0; i < 100000; i++) {
  SettableFuture<String> curr = SettableFuture.create();
  prev.setFuture(curr);
  prev = curr;
 }
 // prev represents the 'innermost' future
 prev.set("done");
 assertTrue(orig.isDone());
}

代码示例来源:origin: prestodb/presto

synchronized void setNoNewLookups()
{
  if (noNewLookups) {
    return;
  }
  checkState(!lookupDoneFuture.isDone());
  noNewLookups = true;
  checkAllLookupsDone();
}

代码示例来源:origin: prestodb/presto

public synchronized void decrementPendingLookupCount()
{
  checkState(!lookupDoneFuture.isDone());
  pendingLookupCount--;
  checkAllLookupsDone();
}

代码示例来源:origin: google/guava

public void testTrustedGetFailure_NotCompleted() {
 SettableFuture<String> future = SettableFuture.create();
 assertThat(future.isDone()).isFalse();
 assertThat(future.tryInternalFastPathGetFailure()).isNull();
}

代码示例来源:origin: google/guava

public void testSetFailureNull() throws Exception {
 try {
  future.setException(null);
  fail();
 } catch (NullPointerException expected) {
 }
 assertFalse(future.isDone());
 assertTrue(future.setException(new Exception("failure")));
 tester.testFailedFuture("failure");
}

代码示例来源:origin: google/guava

/** Tests the initial state of the future. */
public void testCreate() throws Exception {
 SettableFuture<Integer> future = SettableFuture.create();
 assertFalse(future.isDone());
 assertFalse(future.isCancelled());
}

代码示例来源:origin: google/guava

public void testSetValue_simpleThreaded() throws Exception {
 SettableFuture<Integer> future = SettableFuture.create();
 assertTrue(future.set(42));
 // Later attempts to set the future should return false.
 assertFalse(future.set(23));
 assertFalse(future.setException(new Exception("bar")));
 assertFalse(future.setFuture(SettableFuture.<Integer>create()));
 // Check that the future has been set properly.
 assertTrue(future.isDone());
 assertFalse(future.isCancelled());
 assertEquals(42, (int) future.get());
}

代码示例来源:origin: google/guava

public void testAwaitDone_Future() {
 final SettableFuture<Void> future = SettableFuture.create();
 Object x =
   new Object() {
    @Override
    protected void finalize() {
     future.set(null);
    }
   };
 x = null; // Hint to the JIT that x is unreachable
 GcFinalization.awaitDone(future);
 assertTrue(future.isDone());
 assertFalse(future.isCancelled());
}

代码示例来源:origin: google/guava

public void testAwaitDone_Future_Cancel() {
 final SettableFuture<Void> future = SettableFuture.create();
 Object x =
   new Object() {
    @Override
    protected void finalize() {
     future.cancel(false);
    }
   };
 x = null; // Hint to the JIT that x is unreachable
 GcFinalization.awaitDone(future);
 assertTrue(future.isDone());
 assertTrue(future.isCancelled());
}

代码示例来源:origin: google/guava

public void testSetException() throws Exception {
 SettableFuture<Object> future = SettableFuture.create();
 Exception e = new Exception("foobarbaz");
 assertTrue(future.setException(e));
 // Later attempts to set the future should return false.
 assertFalse(future.set(23));
 assertFalse(future.setException(new Exception("quux")));
 assertFalse(future.setFuture(SettableFuture.create()));
 // Check that the future has been set properly.
 assertTrue(future.isDone());
 assertFalse(future.isCancelled());
 try {
  future.get();
  fail("Expected ExecutionException");
 } catch (ExecutionException ee) {
  assertThat(ee).hasCauseThat().isSameAs(e);
 }
}

代码示例来源:origin: google/guava

public void testAllAsList_failure() throws Exception {
 SingleCallListener listener = new SingleCallListener();
 SettableFuture<String> future1 = SettableFuture.create();
 SettableFuture<String> future2 = SettableFuture.create();
 @SuppressWarnings("unchecked") // array is never modified
 ListenableFuture<List<String>> compound = allAsList(future1, future2);
 compound.addListener(listener, directExecutor());
 listener.expectCall();
 Throwable exception = new Throwable("failed1");
 future1.setException(exception);
 assertTrue(compound.isDone());
 assertTrue(listener.wasCalled());
 assertFalse(future2.isDone());
 try {
  getDone(compound);
  fail();
 } catch (ExecutionException expected) {
  assertSame(exception, expected.getCause());
 }
}

代码示例来源:origin: google/guava

public void testAllAsList_cancelled() throws Exception {
 SingleCallListener listener = new SingleCallListener();
 SettableFuture<String> future1 = SettableFuture.create();
 SettableFuture<String> future2 = SettableFuture.create();
 @SuppressWarnings("unchecked") // array is never modified
 ListenableFuture<List<String>> compound = allAsList(future1, future2);
 compound.addListener(listener, directExecutor());
 listener.expectCall();
 future1.cancel(true);
 assertTrue(compound.isDone());
 assertTrue(listener.wasCalled());
 assertFalse(future2.isDone());
 try {
  getDone(compound);
  fail();
 } catch (CancellationException expected) {
 }
}

代码示例来源:origin: google/guava

public void testNonCancellationPropagating_doesNotPropagate() throws Exception {
 SettableFuture<Foo> input = SettableFuture.create();
 ListenableFuture<Foo> wrapper = nonCancellationPropagating(input);
 assertTrue(wrapper.cancel(true));
 assertTrue(wrapper.isCancelled());
 assertTrue(wrapper.isDone());
 assertFalse(input.isCancelled());
 assertFalse(input.isDone());
}

相关文章