@Override public Future<Response<T>> adapt(Call<T> call) { Promise<Response<T>> promise = Promise.apply(); call.enqueue(new Callback<T>() { @Override public void onResponse(Call<T> call, Response<T> response) { promise.success(response); } @Override public void onFailure(Call<T> call, Throwable t) { promise.failure(t); } }); return promise.future(); } }
@Override public Future<Set<SourceIdentifier>> getResolvedSources() { return resolvedSourcesPromise.future(); } }
@Override public void notifyLeaderAddress(String leaderAddress, UUID leaderSessionID) { if (leaderAddress != null && !leaderAddress.equals("") && !connectionInfo.isCompleted()) { try { final LeaderConnectionInfo leaderConnectionInfo = new LeaderConnectionInfo(leaderAddress, leaderSessionID); connectionInfo.success(leaderConnectionInfo); } catch (FlinkException e) { connectionInfo.failure(e); } } }
@Override public void onResponse(Call<T> call, Response<T> response) { promise.success(response); }
@Override public void onFailure(Call<T> call, Throwable t) { promise.failure(t); } });
@Override public void handleError(Exception exception) { if (!connectionInfo.isCompleted()) { connectionInfo.failure(exception); } } }
@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; }
CompletionStage<StandaloneWSResponse> execute(Request request) { final Promise<StandaloneWSResponse> scalaPromise = scala.concurrent.Promise$.MODULE$.apply(); AsyncCompletionHandler<Response> handler = new ResponseAsyncCompletionHandler(scalaPromise); try { asyncHttpClient.executeRequest(request, handler); } catch (RuntimeException exception) { scalaPromise.failure(exception); } Future<StandaloneWSResponse> future = scalaPromise.future(); return FutureConverters.toJava(future); }
private void completePromise(ActorGateway gateway) { synchronized (lock) { if (!futureActorGateway.isCompleted()) { futureActorGateway.success(gateway); } } }
@Override public void onComplete(final Throwable failure, final Object notUsed) { if (failure != null) { // A Ready Future failed so fail the returned Promise. LOG.error("Tx: {} - ready future failed for previous Tx {}", txId, previousTransactionId); returnPromise.failure(failure); } else { LOG.debug("Tx: {} - previous Tx {} readied - proceeding to FindPrimaryShard", txId, previousTransactionId); // Send the FindPrimaryShard message and use the resulting Future to complete the // returned Promise. returnPromise.completeWith(parent.findPrimaryShard(shardName, txId)); } } };
@Override public void notifyLeaderAddress(final String leaderAddress, final UUID leaderSessionID) { if(leaderAddress != null && !leaderAddress.equals("") && !futureActorGateway.isCompleted()) { AkkaUtils.getActorRefFuture(leaderAddress, actorSystem, timeout) .map(new Mapper<ActorRef, ActorGateway>() { public ActorGateway apply(ActorRef ref) { return new AkkaActorGateway(ref, leaderSessionID); } }, actorSystem.dispatcher()) .onComplete(new OnComplete<ActorGateway>() { @Override public void onComplete(Throwable failure, ActorGateway success) throws Throwable { if (failure == null) { completePromise(success); } else { LOG.debug("Could not retrieve the leader for address " + leaderAddress + ".", failure); } } }, actorSystem.dispatcher()); } }
@Override public void invoke(TransactionContext transactionContext) { promise.completeWith(getDirectCommitFuture(transactionContext, operationCallbackRef)); } });
public Future<ActorGateway> getActorGatewayFuture() { return futureActorGateway.future(); } }
@Override public void notifyLeaderAddress(String leaderAddress, UUID leaderSessionID) { if (leaderAddress != null && !leaderAddress.equals("") && !connectionInfo.isCompleted()) { try { final LeaderConnectionInfo leaderConnectionInfo = new LeaderConnectionInfo(leaderAddress, leaderSessionID); connectionInfo.success(leaderConnectionInfo); } catch (FlinkException e) { connectionInfo.failure(e); } } }
/** * Completes the promise with a value. * * @param a The value to complete with */ public void success(A a) { this.promise.success(a); }
@Override public void onFailure(Call<T> call, Throwable t) { promise.failure(t); } });
@Override public void handleError(Exception exception) { if (!connectionInfo.isCompleted()) { connectionInfo.failure(exception); } } }