private PendingRequest(KvStateID kvStateId, byte[] serializedKeyAndNamespace) { this.kvStateId = kvStateId; this.serializedKeyAndNamespace = serializedKeyAndNamespace; this.promise = Futures.promise(); } }
public ClusteredDeviceSourcesResolverImpl(String topologyId, String nodeId, ActorSystem actorSystem, SchemaSourceRegistry schemaRegistry, List<SchemaSourceRegistration<? extends SchemaSourceRepresentation>> sourceRegistrations) { this.topologyId = topologyId; this.nodeId = nodeId; this.actorSystem = actorSystem; this.schemaRegistry = schemaRegistry; this.sourceRegistrations = sourceRegistrations; resolvedSourcesPromise = Futures.promise(); }
public <T> TextBodyHandler(){ this(Futures.promise()); }
public <T> BytesBodyHandler(){ this(Futures.promise()); }
public FlinkCompletableFuture() { promise = Futures.promise(); scalaFuture = promise.future(); }
@Override public Future<YangTextSchemaSourceSerializationProxy> getYangTextSchemaSource(final SourceIdentifier identifier) { LOG.trace("Sending yang schema source for {}", identifier); final Promise<YangTextSchemaSourceSerializationProxy> promise = akka.dispatch.Futures.promise(); ListenableFuture<YangTextSchemaSource> future = repository.getSchemaSource(identifier, YangTextSchemaSource.class); Futures.addCallback(future, new FutureCallback<YangTextSchemaSource>() { @Override public void onSuccess(@Nonnull final YangTextSchemaSource result) { try { promise.success(new YangTextSchemaSourceSerializationProxy(result)); } catch (IOException e) { LOG.warn("Unable to read schema source for {}", result.getIdentifier(), e); promise.failure(e); } } @Override public void onFailure(final Throwable failure) { LOG.warn("Unable to retrieve schema source from provider", failure); promise.failure(failure); } }, MoreExecutors.directExecutor()); return promise.future(); } }
@Override public DOMStoreReadTransaction newReadOnlyTransaction() { currentState.checkReady(); TransactionProxy transactionProxy = new TransactionProxy(this, TransactionType.READ_ONLY); priorReadOnlyTxPromises.put(transactionProxy.getIdentifier(), Futures.<Object>promise()); return transactionProxy; }
@Override public Future<YangTextSchemaSourceSerializationProxy> getYangTextSchemaSource(SourceIdentifier identifier) { LOG.trace("Sending yang schema source for {}", identifier); final Promise<YangTextSchemaSourceSerializationProxy> promise = akka.dispatch.Futures.promise(); CheckedFuture<YangTextSchemaSource, ?> future = repository.getSchemaSource(identifier, YangTextSchemaSource.class); Futures.addCallback(future, new FutureCallback<YangTextSchemaSource>() { @Override public void onSuccess(YangTextSchemaSource result) { try { promise.success(new YangTextSchemaSourceSerializationProxy(result)); } catch (IOException e) { LOG.warn("Unable to read schema source for {}", result.getIdentifier(), e); promise.failure(e); } } @Override public void onFailure(Throwable t) { LOG.warn("Unable to retrieve schema source from provider", t); promise.failure(t); } }); return promise.future(); } }
Future<ActorSelection> readyTransaction() { // avoid the creation of a promise and a TransactionOperation if (transactionContext != null) { return transactionContext.readyTransaction(); } final Promise<ActorSelection> promise = Futures.promise(); enqueueTransactionOperation(new TransactionOperation() { @Override public void invoke(TransactionContext transactionContext) { promise.completeWith(transactionContext.readyTransaction()); } }); return promise.future(); }
@Override public Promise<HttpResponse> execute(HttpHost host, HttpUriRequest req) { lastAccessAt = System.currentTimeMillis(); final scala.concurrent.Promise<HttpResponse> promise = Futures.promise(); HystrixCmd cmd = new HystrixCmd(httpclient,host,req,this); cmd.observe().subscribe(new Observer<HttpResponse>() { @Override public void onCompleted() {} @Override public void onError(Throwable throwable) { promise.failure(throwable); } @Override public void onNext(HttpResponse o) { promise.success(o); } }); return Promise.wrap(promise.future()); }
private <T> Future<T> combineFutureWithPossiblePriorReadOnlyTxFutures(final Future<T> future, final TransactionIdentifier txId) { if(!priorReadOnlyTxPromises.containsKey(txId) && !priorReadOnlyTxPromises.isEmpty()) { Collection<Entry<TransactionIdentifier, Promise<Object>>> priorReadOnlyTxPromiseEntries = new ArrayList<>(priorReadOnlyTxPromises.entrySet()); if(priorReadOnlyTxPromiseEntries.isEmpty()) { return future; } List<Future<Object>> priorReadOnlyTxFutures = new ArrayList<>(priorReadOnlyTxPromiseEntries.size()); for(Entry<TransactionIdentifier, Promise<Object>> entry: priorReadOnlyTxPromiseEntries) { LOG.debug("Tx: {} - waiting on future for prior read-only Tx {}", txId, entry.getKey()); priorReadOnlyTxFutures.add(entry.getValue().future()); } Future<Iterable<Object>> combinedFutures = Futures.sequence(priorReadOnlyTxFutures, getActorContext().getClientDispatcher()); final Promise<T> returnPromise = Futures.promise(); final OnComplete<Iterable<Object>> onComplete = new OnComplete<Iterable<Object>>() { @Override public void onComplete(final Throwable failure, final Iterable<Object> notUsed) { LOG.debug("Tx: {} - prior read-only Tx futures complete", txId); // Complete the returned Promise with the original Future. returnPromise.completeWith(future); } }; combinedFutures.onComplete(onComplete, getActorContext().getClientDispatcher()); return returnPromise.future(); } else { return future; } }
@Override public Future<EventBatch> loadEventsForAggregateIdAsync(final String aggregateType, final String aggregateId, final String fromJournalId) { final Document query = new Document("rid", aggregateId); if (fromJournalId != null) query.append("jid", new Document("$gt", Long.parseLong(fromJournalId))); final ArrayList<Event> events = new ArrayList<>(); com.mongodb.async.client.FindIterable<Document> dbObjects = MongoDbOperations.doDbOperation(() -> dbasync.getCollection(aggregateType).find(query).sort(new Document("jid", 1)).limit(eventReadLimit)); final Promise<EventBatch> promise = Futures.promise(); final Future<EventBatch> theFuture = promise.future(); dbObjects.forEach(document -> events.add(deSerialize(((Binary) document.get("d")).getData())), (result, t) -> promise.success(new EventBatch(aggregateType, aggregateId, events, events.size() != eventReadLimit))); return theFuture; }
Futures.<byte[]>promise(), System.nanoTime());
ActorRef[] actors = new ActorRef[WORKER_COUNT]; for (int workerIndex = 0; workerIndex < WORKER_COUNT; workerIndex++) { Promise<Integer> promise = Futures.promise(); futures.add(promise.future()); Props actorProps = Props.create(InternalActor.class, workerIndex, promise);
@Override public Future<Messages.EventWrapperBatch> loadEventWrappersForCorrelationIdAsync(final String aggregateType, final String correlationId, final long fromJournalId) { final Document query = new Document("correlationid", correlationId); query.append("jid", new Document("$gt", fromJournalId)); final com.mongodb.async.client.FindIterable<Document> dbObjects = MongoDbOperations.doDbOperation(() -> dbasync.getCollection(aggregateType).find(query).sort(new Document("jid", 1)).limit(eventReadLimit)); final Promise<Messages.EventWrapperBatch> promise = Futures.promise(); dbObjects.map(document -> deSerialize(document,aggregateType)) .into(new ArrayList<>(), (SingleResultCallback<ArrayList>) (list, throwable) -> promise.success(Messages.EventWrapperBatch.newBuilder() .addAllEvents(list) .setAggregateType(aggregateType) .setReadAllEvents(list.size() != eventReadLimit) .build())); return promise.future(); }
@Override public Future<Messages.EventWrapperBatch> loadEventWrappersForAggregateIdAsync(final String aggregateType, final String aggregateRootId, final long fromJournalId) { final Document query = new Document("rid", aggregateRootId); query.append("jid", new Document("$gt", fromJournalId)); final com.mongodb.async.client.FindIterable<Document> dbObjects = MongoDbOperations.doDbOperation(() -> dbasync.getCollection(aggregateType).find(query).sort(new Document("jid", 1)).limit(eventReadLimit)); final Promise<Messages.EventWrapperBatch> promise = Futures.promise(); dbObjects.map(document -> deSerialize(document,aggregateType)) .into(new ArrayList<>(), (SingleResultCallback<ArrayList>) (list, throwable) -> promise.success(Messages.EventWrapperBatch.newBuilder() .addAllEvents(list) .setAggregateType(aggregateType) .setReadAllEvents(list.size() != eventReadLimit) .setAggregateRootId(aggregateRootId) .build())); return promise.future(); }
circuitBreaker = cache.get(tag); if(circuitBreaker.allowRequest()) { final scala.concurrent.Promise<HttpResponse> xPromise = Futures.promise(); if(host != null) { httpclient.execute(host, req, new NFutureCallback(circuitBreaker, xPromise));
@SuppressWarnings({ "rawtypes", "unchecked" }) private AbstractThreePhaseCommitCohort<?> createSingleCommitCohort(final String shardName, final TransactionContextWrapper contextWrapper) { LOG.debug("Tx {} Readying transaction for shard {}", getIdentifier(), shardName); final OperationCallback.Reference operationCallbackRef = new OperationCallback.Reference(OperationCallback.NO_OP_CALLBACK); final TransactionContext transactionContext = contextWrapper.getTransactionContext(); final Future future; if (transactionContext == null) { final Promise promise = akka.dispatch.Futures.promise(); contextWrapper.maybeExecuteTransactionOperation(new TransactionOperation() { @Override public void invoke(TransactionContext transactionContext) { promise.completeWith(getDirectCommitFuture(transactionContext, operationCallbackRef)); } }); future = promise.future(); } else { // avoid the creation of a promise and a TransactionOperation future = getDirectCommitFuture(transactionContext, operationCallbackRef); } return new SingleCommitCohortProxy(txContextFactory.getActorContext(), future, getIdentifier(), operationCallbackRef); }
final Promise<PrimaryShardInfo> returnPromise = Futures.promise();