本文整理汇总了Java中scala.concurrent.Promise.future方法的典型用法代码示例。如果您正苦于以下问题:Java Promise.future方法的具体用法?Java Promise.future怎么用?Java Promise.future使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scala.concurrent.Promise
的用法示例。
在下文中一共展示了Promise.future方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readyTransaction
import scala.concurrent.Promise; //导入方法依赖的package包/类
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 newTransactionContext) {
promise.completeWith(newTransactionContext.readyTransaction());
}
});
return promise.future();
}
示例2: transform
import scala.concurrent.Promise; //导入方法依赖的package包/类
private <T> Future<T> transform(final Future<Object> future) {
final Promise<T> promise = new scala.concurrent.impl.Promise.DefaultPromise<>();
future.onComplete(new OnComplete<Object>() {
@Override
public void onComplete(final Throwable failure, final Object success) throws Throwable {
if (success instanceof Throwable) {
promise.failure((Throwable) success);
return;
}
if (success == Void.TYPE) {
promise.success(null);
return;
}
promise.success((T) success);
}
}, context().dispatcher());
return promise.future();
}
示例3: mapPromiseN
import scala.concurrent.Promise; //导入方法依赖的package包/类
@Benchmark
public String mapPromiseN() throws Exception {
Promise<String> p = Promise.<String>apply();
Future<String> f = p.future();
for (int i = 0; i < N.n; i++)
f = f.map(mapF, ec);
p.success(string);
return Await.result(f, inf);
}
示例4: flatMapPromiseN
import scala.concurrent.Promise; //导入方法依赖的package包/类
@Benchmark
public String flatMapPromiseN() throws Exception {
Promise<String> p = Promise.<String>apply();
Future<String> f = p.future();
for (int i = 0; i < N.n; i++)
f = f.flatMap(flatMapF, ec);
p.success(string);
return Await.result(f, inf);
}
示例5: ensurePromiseN
import scala.concurrent.Promise; //导入方法依赖的package包/类
@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);
}
示例6: setValueN
import scala.concurrent.Promise; //导入方法依赖的package包/类
@Benchmark
public String setValueN() throws Exception {
Promise<String> p = Promise.<String>apply();
Future<String> f = p.future();
for (int i = 0; i < N.n; i++)
f = f.map(mapF, ec);
p.success(string);
return Await.result(f, inf);
}
示例7: combineFutureWithPossiblePriorReadOnlyTxFutures
import scala.concurrent.Promise; //导入方法依赖的package包/类
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;
}
}
示例8: createSingleCommitCohort
import scala.concurrent.Promise; //导入方法依赖的package包/类
@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(final TransactionContext newTransactionContext) {
promise.completeWith(getDirectCommitFuture(newTransactionContext, 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);
}
示例9: await
import scala.concurrent.Promise; //导入方法依赖的package包/类
public Future<Object> await(){
final Promise<Object> waiter = Futures.promise();
if (taskList.isEmpty()){
waiter.success(null);
}
awaitListeners.add(waiter);
return waiter.future();
}
示例10: findPrimaryShard
import scala.concurrent.Promise; //导入方法依赖的package包/类
/**
* This method is overridden to ensure the previous Tx's ready operations complete
* before we initiate the next Tx in the chain to avoid creation failures if the
* previous Tx's ready operations haven't completed yet.
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
protected Future<PrimaryShardInfo> findPrimaryShard(final String shardName, final TransactionIdentifier txId) {
// Read current state atomically
final State localState = currentState;
// There are no outstanding futures, shortcut
Future<?> previous = localState.previousFuture();
if (previous == null) {
return combineFutureWithPossiblePriorReadOnlyTxFutures(parent.findPrimaryShard(shardName, txId), txId);
}
final String previousTransactionId;
if (localState instanceof Pending) {
previousTransactionId = ((Pending) localState).getIdentifier().toString();
LOG.debug("Tx: {} - waiting for ready futures with pending Tx {}", txId, previousTransactionId);
} else {
previousTransactionId = "";
LOG.debug("Waiting for ready futures on chain {}", getHistoryId());
}
previous = combineFutureWithPossiblePriorReadOnlyTxFutures(previous, txId);
// Add a callback for completion of the combined Futures.
final Promise<PrimaryShardInfo> returnPromise = Futures.promise();
final OnComplete onComplete = new OnComplete() {
@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));
}
}
};
previous.onComplete(onComplete, getActorContext().getClientDispatcher());
return returnPromise.future();
}
示例11: delayUntilComplete
import scala.concurrent.Promise; //导入方法依赖的package包/类
public Promise<Object> delayUntilComplete(){
Promise<Object> waiter = Futures.promise();
Future<Object> setterFuture = waiter.future();
addTaskToMonitoredList(setterFuture);
return waiter;
}
示例12: askWithSender
import scala.concurrent.Promise; //导入方法依赖的package包/类
public static Future<AskResponse<Object>> askWithSender(ActorRefFactory refFactory, ActorSelection actorSelection, Object message, Timeout timeout) {
Promise<AskResponse<Object>> promise = Futures.promise();
actorSelection.tell(message, refFactory.actorOf(Props.create(Ask.class, promise, timeout)));
return promise.future();
}