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


Java CompletableFuture.isDone方法代码示例

本文整理汇总了Java中java.util.concurrent.CompletableFuture.isDone方法的典型用法代码示例。如果您正苦于以下问题:Java CompletableFuture.isDone方法的具体用法?Java CompletableFuture.isDone怎么用?Java CompletableFuture.isDone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.concurrent.CompletableFuture的用法示例。


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

示例1: completeResponse

import java.util.concurrent.CompletableFuture; //导入方法依赖的package包/类
/**
 * Completes the first uncompleted CF on list, and removes it. If there is no
 * uncompleted CF then creates one (completes it) and adds to list
 */
void completeResponse(Response resp) {
    synchronized (response_cfs) {
        CompletableFuture<Response> cf;
        int cfs_len = response_cfs.size();
        for (int i=0; i<cfs_len; i++) {
            cf = response_cfs.get(i);
            if (!cf.isDone()) {
                Log.logTrace("Completing response (streamid={0}): {1}",
                             streamid, cf);
                cf.complete(resp);
                response_cfs.remove(cf);
                return;
            } // else we found the previous response: just leave it alone.
        }
        cf = MinimalFuture.completedFuture(resp);
        Log.logTrace("Created completed future (streamid={0}): {1}",
                     streamid, cf);
        response_cfs.add(cf);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:Stream.java

示例2: close

import java.util.concurrent.CompletableFuture; //导入方法依赖的package包/类
@Override
public void close() {
    state.set(State.STOPPED);
    if (!initialValueFuture.isDone()) {
        initialValueFuture.cancel(false);
    }

    // Cancel any scheduled operations.
    final ScheduledFuture<?> currentScheduleFuture = this.currentScheduleFuture;
    if (currentScheduleFuture != null && !currentScheduleFuture.isDone()) {
        currentScheduleFuture.cancel(false);
    }
    final CompletableFuture<?> currentWatchFuture = this.currentWatchFuture;
    if (currentWatchFuture != null && !currentWatchFuture.isDone()) {
        currentWatchFuture.cancel(false);
    }
}
 
开发者ID:line,项目名称:centraldogma,代码行数:18,代码来源:AbstractWatcher.java

示例3: supportsCompletableFuturesAsReturnTypeWrapper

import java.util.concurrent.CompletableFuture; //导入方法依赖的package包/类
/**
 * Here we demonstrate the usage of {@link CompletableFuture} as a result wrapper for asynchronous repository query
 * methods. Note, that we need to disable the surrounding transaction to be able to asynchronously read the written
 * data from from another thread within the same test method.
 */
@Test
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public void supportsCompletableFuturesAsReturnTypeWrapper() throws Exception {

	repository.save(new Customer("Customer1", "Foo"));
	repository.save(new Customer("Customer2", "Bar"));

	CompletableFuture<Void> future = repository.readAllBy().thenAccept(customers -> {

		assertThat(customers, hasSize(2));
		customers.forEach(customer -> log.info(customer.toString()));
		log.info("Completed!");
	});

	while (!future.isDone()) {
		log.info("Waiting for the CompletableFuture to finish...");
		TimeUnit.MILLISECONDS.sleep(500);
	}

	future.get();

	log.info("Done!");
}
 
开发者ID:Just-Fun,项目名称:spring-data-examples,代码行数:29,代码来源:Java8IntegrationTests.java

示例4: testFindDetails

import java.util.concurrent.CompletableFuture; //导入方法依赖的package包/类
@Test
public void testFindDetails() throws InterruptedException, ExecutionException  {
    CompletableFuture<Concept> f0 = conceptService.findRoot();
    while (!f0.isDone()) {
        Thread.sleep(20);
    }
    Concept c = f0.get();
    assertNotNull(c);

    CompletableFuture<Optional<ConceptDetails>> f1 = conceptService.findDetails(c.getName());
    while (!f1.isDone()) {
        Thread.sleep(20);
    }
    Optional<ConceptDetails> cd = f1.get();
    assertTrue(cd.isPresent());


    CompletableFuture<Optional<ConceptDetails>> f2 = conceptService.findDetails("Pandalus platyceros");
    while (!f2.isDone()) {
        Thread.sleep(20);
    }
    Optional<ConceptDetails> n = f2.get();
    assertTrue(n.isPresent());
}
 
开发者ID:mbari-media-management,项目名称:vars-annotation,代码行数:25,代码来源:CachedConceptServiceTest.java

示例5: completeResponseExceptionally

import java.util.concurrent.CompletableFuture; //导入方法依赖的package包/类
/**
 * same as above but for errors
 */
void completeResponseExceptionally(Throwable t) {
    synchronized (response_cfs) {
        // use index to avoid ConcurrentModificationException
        // caused by removing the CF from within the loop.
        for (int i = 0; i < response_cfs.size(); i++) {
            CompletableFuture<Response> cf = response_cfs.get(i);
            if (!cf.isDone()) {
                cf.completeExceptionally(t);
                response_cfs.remove(i);
                return;
            }
        }
        response_cfs.add(MinimalFuture.failedFuture(t));
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:Stream.java

示例6: latestValue

import java.util.concurrent.CompletableFuture; //导入方法依赖的package包/类
/**
 * Returns the latest value of {@code watchFile()} result.
 *
 * @param defaultValue the default value which is returned when the value is not available yet
 */
@Nullable
default T latestValue(@Nullable T defaultValue) {
    final CompletableFuture<Latest<T>> initialValueFuture = initialValueFuture();
    if (initialValueFuture.isDone() && !initialValueFuture.isCompletedExceptionally()) {
        return latest().value();
    } else {
        return defaultValue;
    }
}
 
开发者ID:line,项目名称:centraldogma,代码行数:15,代码来源:Watcher.java

示例7: watchRepository

import java.util.concurrent.CompletableFuture; //导入方法依赖的package包/类
/**
 * Awaits and retrieves the latest revision of the commit that changed the file that matches the specified
 * {@code pathPattern} since the specified {@code lastKnownRevision}. This will wait until the specified
 * {@code timeoutMillis} passes. If there's no change during the time, the returned future will be
 * exceptionally completed with the {@link CancellationException}.
 */
public CompletableFuture<Revision> watchRepository(Repository repo, Revision lastKnownRevision,
                                                   String pathPattern, long timeoutMillis) {
    final CompletableFuture<Revision> result = repo.watch(lastKnownRevision, pathPattern);
    if (result.isDone()) {
        return result;
    }

    scheduleTimeout(result, timeoutMillis);
    return result;
}
 
开发者ID:line,项目名称:centraldogma,代码行数:17,代码来源:WatchService.java

示例8: watchFile

import java.util.concurrent.CompletableFuture; //导入方法依赖的package包/类
/**
 * Awaits and retrieves the latest revision of the commit that changed the file that matches the specified
 * {@link Query} since the specified {@code lastKnownRevision}. This will wait until the specified
 * {@code timeoutMillis} passes. If there's no change during the time, the returned future will be
 * exceptionally completed with the {@link CancellationException}.
 */
public <T> CompletableFuture<QueryResult<T>> watchFile(Repository repo, Revision lastKnownRevision,
                                                       Query<T> query, long timeoutMillis) {
    final CompletableFuture<QueryResult<T>> result = repo.watch(lastKnownRevision, query);
    if (result.isDone()) {
        return result;
    }

    scheduleTimeout(result, timeoutMillis);
    return result;
}
 
开发者ID:line,项目名称:centraldogma,代码行数:17,代码来源:WatchService.java

示例9: futureOf

import java.util.concurrent.CompletableFuture; //导入方法依赖的package包/类
@Override
public CompletableFuture<ClusterTopology> futureOf(Predicate<ClusterTopology> predicate) {
    ArgAssert.notNull(predicate, "Predicate");

    CompletableFuture<ClusterTopology> future = new CompletableFuture<>();

    ClusterEventListener listener = new ClusterEventListener() {
        @Override
        public void onEvent(ClusterEvent event) {
            InitializationContext localCtx = requireContext();

            if (future.isDone()) {
                localCtx.cluster().removeListener(this);
            } else if (predicate.test(event.topology())) {
                localCtx.cluster().removeListener(this);

                future.complete(event.topology());
            } else if (event.type() == ClusterEventType.LEAVE) {
                localCtx.cluster().removeListener(this);

                future.cancel(false);
            }
        }
    };

    guard.lockRead();

    try {
        if (guard.isInitialized()) {
            requireContext().cluster().addListenerAsync(listener);
        } else {
            deferredListeners.add(new DeferredListener(listener, null));
        }
    } finally {
        guard.unlockRead();
    }

    return future;
}
 
开发者ID:hekate-io,项目名称:hekate,代码行数:40,代码来源:DefaultClusterService.java

示例10: completeReplyExceptionally

import java.util.concurrent.CompletableFuture; //导入方法依赖的package包/类
private void completeReplyExceptionally(Throwable t, String event) {
  appendStreamObservers.compareAndSet(this, null);
  final Map<Long, CompletableFuture<RaftClientReply>> map = replies.getAndSet(null);
  if (map == null) {
    return;
  }
  for (Map.Entry<Long, CompletableFuture<RaftClientReply>> entry : map.entrySet()) {
    final CompletableFuture<RaftClientReply> f = entry.getValue();
    if (!f.isDone()) {
      f.completeExceptionally(t != null? t
          : new IOException(getName() + ": Stream " + event
              + ": no reply for async request cid=" + entry.getKey()));
    }
  }
}
 
开发者ID:apache,项目名称:incubator-ratis,代码行数:16,代码来源:RaftClientProtocolClient.java

示例11: acceptAndWait

import java.util.concurrent.CompletableFuture; //导入方法依赖的package包/类
/**
 * Creates a transceiver and waits for receiving a stop signal. The method blocks until the future passed
 * to the preparation consumer is completed. It's up to the consumer on which event the transceiver should stop
 * @param address
 *  the address to listen for packets
 * @param listenPort
 *  the port to listen for packets (UDP)
 * @param prepare
 *  a consumer that gets the instance of the transceiver in order to setup proper actions on receiving events
 */
public static void acceptAndWait(InetAddress address, int listenPort, BiConsumer<SignalTransceiver, CompletableFuture<Event>> prepare){
    try (SignalTransceiver com = SignalTransceiver.create(address, listenPort).start()) {
        CompletableFuture<Event> stopListening = new CompletableFuture<>();
        prepare.accept(com, stopListening);
        while (!stopListening.isDone() || stopListening.isCancelled()) {
            Thread.sleep(150);
        }
    } catch (Exception e) {
        throw new RuntimeException("Failure to receive signals", e);
    }
}
 
开发者ID:gmuecke,项目名称:boutique-de-jus,代码行数:22,代码来源:SignalTransceiver.java

示例12: testValueFactoryExecutedOnlyOnceConcurrent

import java.util.concurrent.CompletableFuture; //导入方法依赖的package包/类
/**
 * Verifies that multiple concurrent calls to {@link AsyncLazy#getValueAsync()} do not result in multiple
 * invocations of the value factory.
 */
private void testValueFactoryExecutedOnlyOnceConcurrent(boolean specifyJtf) {
	// use our own so we don't get main thread deadlocks, which isn't the point of this test.
	JoinableFutureFactory jtf = specifyJtf ? new JoinableFutureContext().getFactory() : null;
	CompletableFuture<Void> cts = Async.delayAsync(ASYNC_DELAY);
	while (!cts.isDone()) {
		// for debugging purposes only
		AtomicBoolean valueFactoryResumed = new AtomicBoolean(false);
		AtomicBoolean valueFactoryExecuted = new AtomicBoolean(false);
		AsyncLazy<GenericParameterHelper> lazy = new AsyncLazy<>(
			() -> {
				Assert.assertFalse(valueFactoryExecuted.get());
				valueFactoryExecuted.set(true);
				return Async.awaitAsync(
					Async.yieldAsync(),
					() -> {
						valueFactoryResumed.set(true);
						return CompletableFuture.completedFuture(new GenericParameterHelper(5));
					});
			},
			jtf);

		List<GenericParameterHelper> results = TestUtilities.<GenericParameterHelper>concurrencyTest(() -> lazy.getValueAsync().join());

		Assert.assertEquals(5, results.get(0).getData());
		for (int i = 1; i < results.size(); i++) {
			Assert.assertSame(results.get(0), results.get(i));
		}
	}
}
 
开发者ID:tunnelvisionlabs,项目名称:java-threading,代码行数:34,代码来源:AsyncLazyTest.java

示例13: testFetchConceptTree

import java.util.concurrent.CompletableFuture; //导入方法依赖的package包/类
@Test
public void testFetchConceptTree() throws InterruptedException, ExecutionException {
    CompletableFuture<Concept> f = conceptService.findRoot();
    while (!f.isDone()) {
        Thread.sleep(20);
    }
    Concept c = f.get();
    assertNotNull(c);
}
 
开发者ID:mbari-media-management,项目名称:vars-annotation,代码行数:10,代码来源:CachedConceptServiceTest.java

示例14: testFetchConceptTree

import java.util.concurrent.CompletableFuture; //导入方法依赖的package包/类
@Test
public void testFetchConceptTree() throws InterruptedException, ExecutionException {
    CompletableFuture<Concept> f = conceptService.findRoot();
    while (!f.isDone()) {
        Thread.sleep(20);
    }
    Concept c = f.get();
    assertNotNull(c);

}
 
开发者ID:mbari-media-management,项目名称:vars-annotation,代码行数:11,代码来源:KBConceptServiceTest.java

示例15: getResponseAsync

import java.util.concurrent.CompletableFuture; //导入方法依赖的package包/类
@Override
CompletableFuture<Response> getResponseAsync(Executor executor) {
    CompletableFuture<Response> cf = pushCF.whenComplete((v, t) -> pushGroup.pushError(t));
    if(executor!=null && !cf.isDone()) {
        cf  = cf.thenApplyAsync( r -> r, executor);
    }
    return cf;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:Stream.java


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