List of usage examples for com.google.common.util.concurrent ListenableFuture isDone
boolean isDone();
From source file:org.apache.qpid.server.txn.AsyncAutoCommitTransaction.java
private void addFuture(final ListenableFuture<Void> future, final Action action) { if (action != null) { if (future.isDone()) { action.postCommit();/*from ww w. j ava 2 s .co m*/ } else { _futureRecorder.recordFuture(future, action); } } }
From source file:com.facebook.presto.connector.thrift.ThriftIndexPageSource.java
private ListenableFuture<PrestoThriftPageResult> getAndRemoveNextCompletedRequest() { Iterator<ListenableFuture<PrestoThriftPageResult>> iterator = dataRequests.iterator(); while (iterator.hasNext()) { ListenableFuture<PrestoThriftPageResult> future = iterator.next(); if (future.isDone()) { iterator.remove();//from www .j a v a 2s . c om return future; } } throw new IllegalStateException("No completed splits in the queue"); }
From source file:c5db.replication.C5GeneralizedReplicator.java
/** * This method assumes that the receiptFuture is "done". If the future is set with a value, * return its value, the ReplicatorReceipt. On the other hand, if it is an exception, set * the completionFuture with that exception and return null. A null return value guarantees * the completionFuture has been set with an exception. *//* w w w .j a v a 2s. co m*/ @Nullable private ReplicatorReceipt getReceiptOrSetException(ReceiptWithCompletionFuture receiptWithCompletionFuture) { ListenableFuture<ReplicatorReceipt> receiptFuture = receiptWithCompletionFuture.receiptFuture; SettableFuture<?> completionFuture = receiptWithCompletionFuture.completionFuture; assert receiptFuture.isDone(); try { ReplicatorReceipt receipt = C5Futures.getUninterruptibly(receiptFuture); if (receipt == null) { completionFuture.setException(new IOException("replicator returned a null receipt")); } return receipt; } catch (ExecutionException e) { completionFuture.setException(e); return null; } }
From source file:io.prestosql.operator.PartitionedOutputOperator.java
@Override public ListenableFuture<?> isBlocked() { ListenableFuture<?> blocked = partitionFunction.isFull(); return blocked.isDone() ? NOT_BLOCKED : blocked; }
From source file:io.prestosql.operator.BenchmarkHashBuildAndJoinOperators.java
private JoinBridgeManager<PartitionedLookupSourceFactory> benchmarkBuildHash(BuildContext buildContext, List<Integer> outputChannels) { DriverContext driverContext = buildContext.createTaskContext().addPipelineContext(0, true, true, false) .addDriverContext();/* w w w . java 2 s . c o m*/ JoinBridgeManager<PartitionedLookupSourceFactory> lookupSourceFactoryManager = JoinBridgeManager .lookupAllAtOnce(new PartitionedLookupSourceFactory(buildContext.getTypes(), outputChannels.stream().map(buildContext.getTypes()::get).collect(toImmutableList()), buildContext.getHashChannels().stream().map(buildContext.getTypes()::get).collect( toImmutableList()), 1, requireNonNull(ImmutableMap.of(), "layout is null"), false)); HashBuilderOperatorFactory hashBuilderOperatorFactory = new HashBuilderOperatorFactory( HASH_BUILD_OPERATOR_ID, TEST_PLAN_NODE_ID, lookupSourceFactoryManager, outputChannels, buildContext.getHashChannels(), buildContext.getHashChannel(), Optional.empty(), Optional.empty(), ImmutableList.of(), 10_000, new PagesIndex.TestingFactory(false), false, SingleStreamSpillerFactory.unsupportedSingleStreamSpillerFactory()); Operator operator = hashBuilderOperatorFactory.createOperator(driverContext); for (Page page : buildContext.getBuildPages()) { operator.addInput(page); } operator.finish(); LookupSourceFactory lookupSourceFactory = lookupSourceFactoryManager.getJoinBridge(Lifespan.taskWide()); ListenableFuture<LookupSourceProvider> lookupSourceProvider = lookupSourceFactory .createLookupSourceProvider(); if (!lookupSourceProvider.isDone()) { throw new AssertionError("Expected lookup source provider to be ready"); } getFutureValue(lookupSourceProvider).close(); return lookupSourceFactoryManager; }
From source file:zipkin.storage.cassandra.DeduplicatingExecutor.java
/** * Upon success, the statement's result will be remembered and returned for all subsequent * executions with the same key, subject to a local TTL. * * <p>The results of failed statements are forgotten based on the supplied key. * * @param statement what to conditionally execute * @param key determines equivalence of the bound statement * @return future of work initiated by this or a previous request *//*from w w w .j a v a 2 s. c o m*/ ListenableFuture<Void> maybeExecuteAsync(BoundStatement statement, Object key) { BoundStatementKey cacheKey = new BoundStatementKey(statement, key); try { ListenableFuture<Void> result = cache.get(new BoundStatementKey(statement, key)); // A future could be constructed directly (i.e. immediate future), get the value to // see if it was exceptional. If so, the catch block will invalidate that key. if (result.isDone()) result.get(); return result; } catch (UncheckedExecutionException | ExecutionException e) { cache.invalidate(cacheKey); return Futures.immediateFailedFuture(e.getCause()); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new AssertionError(); } }
From source file:org.springframework.cassandra.core.session.DefaultBridgedReactiveSession.java
@Override public Mono<PreparedStatement> prepare(RegularStatement statement) { Assert.notNull(statement, "Statement must not be null"); return Mono.defer(() -> { try {/*from ww w. j a v a 2 s . c o m*/ if (logger.isDebugEnabled()) { logger.debug("Preparing Statement [{}]", statement); } CompletableFuture<PreparedStatement> future = new CompletableFuture<>(); ListenableFuture<PreparedStatement> resultSetFuture = session.prepareAsync(statement); resultSetFuture.addListener(() -> { if (resultSetFuture.isDone()) { try { future.complete(resultSetFuture.get()); } catch (Exception e) { future.completeExceptionally(e); } } }, Runnable::run); return Mono.fromFuture(future); } catch (Exception e) { return Mono.error(e); } }).subscribeOn(scheduler); }
From source file:org.apache.druid.query.lookup.KafkaLookupExtractorFactory.java
@Override public boolean close() { synchronized (started) { if (!started.get() || executorService.isShutdown()) { LOG.info("Already shutdown, ignoring"); return !started.get(); }/*from w w w . ja v a 2s . com*/ started.set(false); executorService.shutdown(); if (consumerConnector != null) { consumerConnector.shutdown(); } final ListenableFuture<?> future = this.future; if (future != null) { if (!future.isDone() && !future.cancel(false)) { LOG.error("Error cancelling future for topic [%s]", getKafkaTopic()); return false; } } cacheHandler.close(); return true; } }
From source file:io.druid.query.lookup.KafkaLookupExtractorFactory.java
@Override public boolean close() { synchronized (started) { if (!started.get() || executorService.isShutdown()) { LOG.info("Already shutdown, ignoring"); return !started.get(); }//from w w w .ja v a 2 s. c om started.set(false); executorService.shutdown(); if (consumerConnector != null) { consumerConnector.shutdown(); } final ListenableFuture<?> future = this.future; if (future != null) { if (!future.isDone() && !future.cancel(false)) { LOG.error("Error cancelling future for topic [%s]", getKafkaTopic()); return false; } } if (!cacheManager.delete(factoryId)) { LOG.error("Error removing [%s] for topic [%s] from cache", factoryId, getKafkaTopic()); return false; } return true; } }
From source file:io.prestosql.operator.ExchangeClient.java
public WorkProcessor<SerializedPage> pages() { return WorkProcessor.create(() -> { SerializedPage page = pollPage(); if (page == null) { if (isFinished()) { return ProcessState.finished(); }/*from w w w .j av a 2s . c o m*/ ListenableFuture<?> blocked = isBlocked(); if (!blocked.isDone()) { return ProcessState.blocked(blocked); } return ProcessState.yield(); } return ProcessState.ofResult(page); }); }