本文整理了Java中scala.concurrent.Promise
类的一些代码示例,展示了Promise
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Promise
类的具体详情如下:
包路径:scala.concurrent.Promise
类名称:Promise
暂无
代码示例来源:origin: square/retrofit
@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();
}
}
代码示例来源:origin: square/retrofit
@Override public void onResponse(Call<T> call, Response<T> response) {
if (response.isSuccessful()) {
promise.success(response.body());
} else {
promise.failure(new HttpException(response));
}
}
代码示例来源:origin: traneio/future
@Benchmark
public String setValue() throws Exception {
Promise<String> p = Promise.<String>apply();
p.success(string);
return Await.result(p.future(), inf);
}
代码示例来源:origin: org.opendaylight.netconf/netconf-topology
@Override
public Future<Set<SourceIdentifier>> getResolvedSources() {
return resolvedSourcesPromise.future();
}
}
代码示例来源:origin: org.apache.flink/flink-runtime_2.11
@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);
}
}
}
代码示例来源:origin: square/retrofit
@Override public void onResponse(Call<T> call, Response<T> response) {
promise.success(response);
}
代码示例来源:origin: square/retrofit
@Override public void onFailure(Call<T> call, Throwable t) {
promise.failure(t);
}
});
代码示例来源:origin: org.apache.flink/flink-runtime_2.11
@Override
public void handleError(Exception exception) {
if (!connectionInfo.isCompleted()) {
connectionInfo.failure(exception);
}
}
}
代码示例来源:origin: ks-no/eventstore2
@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;
}
代码示例来源:origin: com.typesafe.play/play-ahc-ws-standalone
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);
}
代码示例来源:origin: org.apache.flink/flink-runtime
private void completePromise(ActorGateway gateway) {
synchronized (lock) {
if (!futureActorGateway.isCompleted()) {
futureActorGateway.success(gateway);
}
}
}
代码示例来源:origin: org.opendaylight.controller/sal-distributed-datastore
@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));
}
}
};
代码示例来源:origin: org.apache.flink/flink-runtime_2.11
@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());
}
}
代码示例来源:origin: org.opendaylight.controller/sal-distributed-datastore
@Override
public void invoke(TransactionContext transactionContext) {
promise.completeWith(getDirectCommitFuture(transactionContext, operationCallbackRef));
}
});
代码示例来源:origin: traneio/future
@Benchmark
public Void ensurePromiseN() throws Exception {
Promise<Void> p = Promise.<Void>apply();
Future<Void> f = p.future();
for (int i = 0; i < N.n; i++)
f = f.transform(ensureF, ec);
p.success(null);
return Await.result(f, inf);
}
代码示例来源:origin: org.apache.flink/flink-runtime
public Future<ActorGateway> getActorGatewayFuture() {
return futureActorGateway.future();
}
}
代码示例来源:origin: org.apache.flink/flink-runtime
@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);
}
}
}
代码示例来源:origin: com.typesafe.play/play_2.10
/**
* Completes the promise with a value.
*
* @param a The value to complete with
*/
public void success(A a) {
this.promise.success(a);
}
代码示例来源:origin: square/retrofit
@Override public void onFailure(Call<T> call, Throwable t) {
promise.failure(t);
}
});
代码示例来源:origin: org.apache.flink/flink-runtime_2.10
@Override
public void handleError(Exception exception) {
if (!connectionInfo.isCompleted()) {
connectionInfo.failure(exception);
}
}
}
内容来源于网络,如有侵权,请联系作者删除!