當前位置: 首頁>>代碼示例>>Java>>正文


Java AbstractFuture類代碼示例

本文整理匯總了Java中com.google.common.util.concurrent.AbstractFuture的典型用法代碼示例。如果您正苦於以下問題:Java AbstractFuture類的具體用法?Java AbstractFuture怎麽用?Java AbstractFuture使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


AbstractFuture類屬於com.google.common.util.concurrent包,在下文中一共展示了AbstractFuture類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: fetchMoreResultsAsync

import com.google.common.util.concurrent.AbstractFuture; //導入依賴的package包/類
@Override
public ListenableFuture<ResultSet> fetchMoreResultsAsync() {

    return new AbstractFuture<ResultSet>() {
        
        {
            new Thread() {
                
                public void run() {
                    for (int i = 0; i< 5; i++) {
                        try {
                            Thread.sleep(fetchDelayMillis);
                        } catch (InterruptedException ignore) { }
                        System.out.print("z");
                    }

                    loadNextChunk();
                    set(null);
                };
                
            }.start();
            
        }
    };
}
 
開發者ID:1and1,項目名稱:Troilus,代碼行數:26,代碼來源:SimpleResultList.java

示例2: testDelayedCheckingOfCachingProviders

import com.google.common.util.concurrent.AbstractFuture; //導入依賴的package包/類
@Test
public void testDelayedCheckingOfCachingProviders() {
  String soyFileContent =
      "{namespace ns}\n"
          + "\n"
          + "{template .template}\n"
          + "  {@param foo: int}\n"
          + "  Before: {$foo}\n"
          + "{/template}\n";
  final StringBuilder outputSb = new StringBuilder();
  final AtomicReference<String> outputAtFutureGetTime = new AtomicReference<>();
  AbstractFuture<Integer> fooFuture =
      new AbstractFuture<Integer>() {
        {
          set(1);
        }

        @Override
        public Integer get() throws InterruptedException, ExecutionException {
          outputAtFutureGetTime.set(outputSb.toString());
          return super.get();
        }
      };
  SoyRecord data = SoyValueConverterUtility.newDict("foo", fooFuture);
  assertThat(
          renderTemplateInFile(
              SoyFileSetParserBuilder.forFileContents(soyFileContent).parse(),
              "ns.template",
              data,
              TEST_IJ_DATA,
              Predicates.<String>alwaysFalse(),
              outputSb))
      .isEqualTo("Before: 1");
  assertThat(outputAtFutureGetTime.get()).isEqualTo("Before: ");
}
 
開發者ID:google,項目名稱:closure-templates,代碼行數:36,代碼來源:RenderVisitorTest.java

示例3: to

import com.google.common.util.concurrent.AbstractFuture; //導入依賴的package包/類
/**
 * Immediately subscribes to the {@link Observable} and returns a future that will contain the only one value T passed in to the
 * {@link Observer#onNext(Object)}.  If more than one value is received then an {@link Observer#onError(Throwable)} is invoked.
 * <p>
 * If the source {@link Observable} emits more than one item or no items, notify of an IllegalArgumentException or NoSuchElementException respectively.
 * 
 * @param observable  The source {@link Observable} for the value.
 * @return a {@link ListenableFuture} that sets the value on completion.
 */
public static <T> ListenableFuture<T> to(final Observable<T> observable) {
    class ListenFutureSubscriberAdaptor extends AbstractFuture<T> {
        final Subscriber<? super T> subscriber;

        private ListenFutureSubscriberAdaptor() {
            subscriber = new Subscriber<T>() {
                private T value;

                @Override
                public void onCompleted() {
                    set(value);
                }

                @Override
                public void onError(Throwable e) {
                    setException(e);
                }

                @Override
                public void onNext(T t) {
                    // wait for the onCompleted to make sure the observable on emits one value.
                    value = t;
                }
            };
        }

        @Override
        protected void interruptTask() {
            subscriber.unsubscribe();
        }
    }

    ListenFutureSubscriberAdaptor future = new ListenFutureSubscriberAdaptor();

    // Futures are hot so subscribe immediately
    observable.single().subscribe(future.subscriber);

    return future;
}
 
開發者ID:ReactiveX,項目名稱:RxJavaGuava,代碼行數:49,代碼來源:ListenableFutureObservable.java

示例4: testStreamLazyParamsToOutputStreamDirectly

import com.google.common.util.concurrent.AbstractFuture; //導入依賴的package包/類
@Test
public void testStreamLazyParamsToOutputStreamDirectly() {
  String soyFileContent =
      Joiner.on("\n")
          .join(
              "{namespace ns}",
              "",
              "{template .callee}",
              "  {@param body: html}",
              "  <div>",
              "    {$body}",
              "  </div>",
              "{/template}",
              "",
              "{template .caller}",
              "  {@param future: string}",
              "  {call .callee}",
              "    {param body kind=\"html\"}",
              "      static-content{sp}",
              "      {$future}",
              "    {/param}",
              "  {/call}",
              "{/template}");
  final StringBuilder outputSb = new StringBuilder();
  final AtomicReference<String> outputAtFutureGetTime = new AtomicReference<>();
  AbstractFuture<String> future =
      new AbstractFuture<String>() {
        {
          set("future-content");
        }

        @Override
        public String get() throws InterruptedException, ExecutionException {
          outputAtFutureGetTime.set(outputSb.toString());
          return super.get();
        }
      };
  SoyRecord data = SoyValueConverterUtility.newDict("future", future);
  assertThat(
          renderTemplateInFile(
              SoyFileSetParserBuilder.forFileContents(soyFileContent).parse(),
              "ns.caller",
              data,
              TEST_IJ_DATA,
              Predicates.<String>alwaysFalse(),
              outputSb))
      .isEqualTo("<div>static-content future-content</div>");
  assertThat(outputAtFutureGetTime.get()).isEqualTo("<div>static-content ");
}
 
開發者ID:google,項目名稱:closure-templates,代碼行數:50,代碼來源:RenderVisitorTest.java


注:本文中的com.google.common.util.concurrent.AbstractFuture類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。