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

x33g5p2x  于11个月前 转载在 其他  
字(6.4k)|赞(0)|评价(0)|浏览(27)

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

AbstractFuture.set介绍

[英]Sets the result of this Future unless this Future has already been cancelled or set (including #setFuture). When a call to this method returns, the Future is guaranteed to be #isDone only if the call was accepted (in which case it returns true). If it returns false, the Future may have previously been set asynchronously, in which case its result may not be known yet. That result, though not yet known, cannot be overridden by a call to a setmethod, only by a call to #cancel.
[中]设置此未来的结果,除非此未来已被取消或设置(包括#setFuture)。当对该方法的调用返回时,只有在该调用被接受的情况下(在这种情况下,它返回true),未来才会被保证为#isDone。如果返回false,则Future可能以前是异步设置的,在这种情况下,其结果可能还未知。这个结果虽然还不知道,但不能通过调用set
方法来覆盖,只能通过调用#cancel来覆盖。

代码示例

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

@Override
protected boolean set(QueryInfo value)
{
  return super.set(value);
}

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

@Override
 public void run() {
  AbstractFuture<String> future = setFutureFuture.get();
  setFutureSetSucess.set(currentFuture.get().setFuture(future));
  setFutureCompletionSucess.set(future.set("hello-async-world"));
  awaitUnchecked(barrier);
 }
};

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

private static void assertCannotSet(AbstractFuture<Integer> future) {
 assertThat(future.set(99)).isFalse();
 assertThat(future.setException(new IndexOutOfBoundsException())).isFalse();
 assertThat(future.setFuture(new AbstractFuture<Integer>() {})).isFalse();
 assertThat(future.setFuture(immediateFuture(99))).isFalse();
}

代码示例来源:origin: apache/incubator-druid

@Override
public boolean set(ChangeRequestsSnapshot<T> value)
{
 return super.set(value);
}

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

public void testToString_completed() throws Exception {
 AbstractFuture<Object> testFuture2 =
   new AbstractFuture<Object>() {
    @Override
    public String pendingToString() {
     return "cause=[Someday...]";
    }
   };
 AbstractFuture<Object> testFuture3 = new AbstractFuture<Object>() {};
 testFuture3.setFuture(testFuture2);
 assertThat(testFuture3.toString())
   .matches(
     "[^\\[]+\\[status=PENDING, info=\\[setFuture="
       + "\\[[^\\[]+\\[status=PENDING, info=\\[cause=\\[Someday...\\]\\]\\]\\]\\]\\]");
 testFuture2.set("result string");
 assertThat(testFuture3.toString())
   .matches("[^\\[]+\\[status=SUCCESS, result=\\[result string\\]\\]");
}

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

@Override
public boolean set(@Nullable V value)
{
  return super.set(value);
}

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

@Override
 public void run() {
  f.set("foo");
 }
};

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

@Override
 public AbstractFuture<BarChild> apply(Foo unused) {
  AbstractFuture<BarChild> future = new AbstractFuture<BarChild>() {};
  future.set(barChild);
  return future;
 }
};

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

public void testListenersExecuteImmediately_fromAfterDone() {
 AbstractFuture<String> f =
   new AbstractFuture<String>() {
    @Override
    protected void afterDone() {
     final AtomicBoolean ranImmediately = new AtomicBoolean();
     addListener(
       new Runnable() {
        @Override
        public void run() {
         ranImmediately.set(true);
        }
       },
       MoreExecutors.directExecutor());
     assertThat(ranImmediately.get()).isTrue();
    }
   };
 f.set("foo");
}

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

@Override
protected boolean set(QueryInfo value)
{
  return super.set(value);
}

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

@Override
 public Void call() {
  if (currentFuture.get().set("set")) {
   numSuccessfulSetCalls.incrementAndGet();
  }
  awaitUnchecked(barrier);
  return null;
 }
};

代码示例来源:origin: apache/incubator-druid

public void resolve()
{
 synchronized (statusRefs) {
  if (isDone()) {
   return;
  }
  List<DataSegmentChangeRequestAndStatus> result = new ArrayList<>(statusRefs.size());
  statusRefs.forEach(
    (request, statusRef) -> result.add(new DataSegmentChangeRequestAndStatus(request, statusRef.get()))
  );
  super.set(result);
 }
}

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

@Override
 public void run() {
  future.set("success");
  if (!future.isDone()) {
   errorMessage.set("Set call exited before future was complete.");
  }
 }
});

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

@CanIgnoreReturnValue
@Override
public boolean set(T t) {
 return super.set(t);
}

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

public void testGetFailure_Completed() {
 AbstractFuture<String> future = new AbstractFuture<String>() {};
 future.set("261");
 assertThat(future.tryInternalFastPathGetFailure()).isNull();
}

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

public void testSetFutureDelegateAlreadySuccessful() throws Exception {
 delegate.set(5);
 assertThat(future.setFuture(delegate)).isTrue();
 assertSuccessful(future, 5);
}

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

public void testSetFutureDelegateLaterSuccessful() throws Exception {
 assertThat(future.setFuture(delegate)).isTrue();
 delegate.set(6);
 assertSuccessful(future, 6);
}

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

public void testListenLaterSetAsynchronouslyLaterDelegateSuccessful() {
 CountingRunnable before = new CountingRunnable();
 CountingRunnable inBetween = new CountingRunnable();
 CountingRunnable after = new CountingRunnable();
 future.addListener(before, directExecutor());
 future.setFuture(delegate);
 future.addListener(inBetween, directExecutor());
 delegate.set(1);
 future.addListener(after, directExecutor());
 before.assertRun();
 inBetween.assertRun();
 after.assertRun();
}

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

public void testRemoveWaiter_interruption() throws Exception {
 final AbstractFuture<String> future = new AbstractFuture<String>() {};
 WaiterThread waiter1 = new WaiterThread(future);
 waiter1.start();
 waiter1.awaitWaiting();
 WaiterThread waiter2 = new WaiterThread(future);
 waiter2.start();
 waiter2.awaitWaiting();
 // The waiter queue should be waiter2->waiter1
 // This should wake up waiter1 and cause the waiter1 node to be removed.
 waiter1.interrupt();
 waiter1.join();
 waiter2.awaitWaiting(); // should still be blocked
 LockSupport.unpark(waiter2); // spurious wakeup
 waiter2.awaitWaiting(); // should eventually re-park
 future.set(null);
 waiter2.join();
}

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

public void testRemoveWaiter_polling() throws Exception {
 final AbstractFuture<String> future = new AbstractFuture<String>() {};
 WaiterThread waiter = new WaiterThread(future);
 waiter.start();
 waiter.awaitWaiting();
 PollingThread poller = new PollingThread(future);
 poller.start();
 PollingThread poller2 = new PollingThread(future);
 poller2.start();
 PollingThread poller3 = new PollingThread(future);
 poller3.start();
 poller.awaitInLoop();
 poller2.awaitInLoop();
 poller3.awaitInLoop();
 // The waiter queue should be {poller x 3}->waiter1
 waiter.interrupt();
 // This should wake up waiter1 and cause the waiter1 node to be removed.
 waiter.join();
 future.set(null);
 poller.join();
}

相关文章