当前位置: 首页>>代码示例>>Java>>正文


Java Promise.future方法代码示例

本文整理汇总了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();
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:17,代码来源:TransactionContextWrapper.java

示例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();
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:19,代码来源:MockedSnapshotStore.java

示例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);
}
 
开发者ID:traneio,项目名称:future,代码行数:10,代码来源:ScalaFutureBenchmark.java

示例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);
}
 
开发者ID:traneio,项目名称:future,代码行数:10,代码来源:ScalaFutureBenchmark.java

示例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);
}
 
开发者ID:traneio,项目名称:future,代码行数:10,代码来源:ScalaFutureBenchmark.java

示例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);
}
 
开发者ID:traneio,项目名称:future,代码行数:10,代码来源:ScalaFutureBenchmark.java

示例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;
    }
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:36,代码来源:TransactionChainProxy.java

示例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);
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:29,代码来源:TransactionProxy.java

示例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();
}
 
开发者ID:ranoble,项目名称:Megapode,代码行数:9,代码来源:ConcurrantCallable.java

示例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();
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:54,代码来源:TransactionChainProxy.java

示例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;
}
 
开发者ID:ranoble,项目名称:Megapode,代码行数:7,代码来源:WidgetBase.java

示例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();
}
 
开发者ID:IDgis,项目名称:geo-publisher,代码行数:8,代码来源:Ask.java


注:本文中的scala.concurrent.Promise.future方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。