本文整理了Java中scala.concurrent.Future
类的一些代码示例,展示了Future
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Future
类的具体详情如下:
包路径:scala.concurrent.Future
类名称:Future
暂无
代码示例来源:origin: org.deeplearning4j/deeplearning4j-scaleout-akka
public static <T> void throwExceptionIfExists(Future<T> f,ExecutionContext context) {
f.onComplete(new OnComplete<T>() {
@Override
public void onComplete(Throwable arg0, T arg1) throws Throwable {
if(arg0 != null)
throw arg0;
}
}, context);
}
代码示例来源:origin: org.apache.flink/flink-runtime_2.10
@Override
public <R> Future<R> thenApplyAsync(final ApplyFunction<? super T, ? extends R> applyFunction, Executor executor) {
Preconditions.checkNotNull(scalaFuture);
Preconditions.checkNotNull(applyFunction);
Preconditions.checkNotNull(executor);
scala.concurrent.Future<R> mappedFuture = scalaFuture.map(new Mapper<T, R>() {
@Override
public R apply(T value) {
return applyFunction.apply(value);
}
}, createExecutionContext(executor));
return new FlinkFuture<>(mappedFuture);
}
代码示例来源:origin: org.apache.flink/flink-runtime_2.10
@Override
public boolean isDone() {
return scalaFuture.isCompleted();
}
代码示例来源:origin: org.apache.flink/flink-runtime_2.11
private CompletableFuture<TransientBlobKey> requestTaskManagerLog(TaskManagerMessages.RequestTaskManagerLog request, Time timeout) {
Preconditions.checkNotNull(request);
Preconditions.checkNotNull(timeout);
scala.concurrent.Future<TransientBlobKey> blobKeyFuture = actorGateway
.ask(
request,
new FiniteDuration(timeout.getSize(), timeout.getUnit()))
.mapTo(ClassTag$.MODULE$.<TransientBlobKey>apply(TransientBlobKey.class));
return FutureUtils.toJava(blobKeyFuture);
}
}
代码示例来源:origin: org.apache.flink/flink-runtime_2.10
@Override
public <R> Future<R> handleAsync(final BiFunction<? super T, Throwable, ? extends R> biFunction, Executor executor) {
Preconditions.checkNotNull(scalaFuture);
Preconditions.checkNotNull(biFunction);
Preconditions.checkNotNull(executor);
final ExecutionContext executionContext = createExecutionContext(executor);
final CompletableFuture<R> resultFuture = new FlinkCompletableFuture<>();
scalaFuture.onComplete(new OnComplete<T>() {
@Override
public void onComplete(Throwable failure, T success) throws Throwable {
final R result = biFunction.apply(success, failure);
resultFuture.complete(result);
}
}, executionContext);
return resultFuture;
}
代码示例来源: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: apache/flink
actorSystem.terminate().onComplete(
new OnComplete<Terminated>() {
public void onComplete(Throwable failure, Terminated result) {
AkkaUtils.getTimeout(config).toMillis(),
TimeUnit.MILLISECONDS,
futureExecutor,
代码示例来源:origin: write2munish/Akka-Essentials
final Future<OrderHistory> aggResult = aggregate.map(
new Mapper<Iterable<Object>, OrderHistory>() {
public OrderHistory apply(Iterable<Object> coll) {
代码示例来源:origin: ks-no/eventstore2
private void readAggregateEvents(RetrieveAggregateEventsAsync retreiveAggregateEvents) {
final ActorRef sender = sender();
final ActorRef self = self();
final Future<EventBatch> future = storage.loadEventsForAggregateIdAsync(retreiveAggregateEvents.getAggregateType(), retreiveAggregateEvents.getAggregateId(), retreiveAggregateEvents.getFromJournalId());
future.onSuccess(new OnSuccess<EventBatch>() {
@Override
public void onSuccess(EventBatch result) throws Throwable {
sender.tell(result, self);
}
}, getContext().dispatcher());
future.onFailure(new OnFailure() {
@Override
public void onFailure(Throwable failure) throws Throwable {
log.error("failed to read events from journalstorage {} ", retreiveAggregateEvents, failure);
}
}, getContext().dispatcher()
);
}
代码示例来源:origin: baekjunlim/AkkaStarting
@Override
public void onReceive(Object message) throws Exception {
if (message instanceof Integer) {
Future<Object> future = Patterns.ask(child, message, timeout);
// onSuccess, onComplete, onFailure 등은 blocking 동작이 아니다.
future.onSuccess(new SaySuccess<Object>(), ec);
future.onComplete(new SayComplete<Object>(), ec);
future.onFailure(new SayFailure<Object>(), ec);
} else if (message instanceof String) {
log.info("NonblockingActor received a messasge: " + message);
}
}
代码示例来源:origin: org.opendaylight.controller/sal-distributed-datastore
final TransactionContextWrapper newTransactionContextWrapper(final TransactionProxy parent, final String shardName) {
final TransactionContextWrapper transactionContextWrapper =
new TransactionContextWrapper(parent.getIdentifier(), actorContext);
Future<PrimaryShardInfo> findPrimaryFuture = findPrimaryShard(shardName, parent.getIdentifier());
if(findPrimaryFuture.isCompleted()) {
Try<PrimaryShardInfo> maybe = findPrimaryFuture.value().get();
if(maybe.isSuccess()) {
onFindPrimaryShardSuccess(maybe.get(), parent, shardName, transactionContextWrapper);
} else {
onFindPrimaryShardFailure(maybe.failed().get(), parent, shardName, transactionContextWrapper);
}
} else {
findPrimaryFuture.onComplete(new OnComplete<PrimaryShardInfo>() {
@Override
public void onComplete(final Throwable failure, final PrimaryShardInfo primaryShardInfo) {
if (failure == null) {
onFindPrimaryShardSuccess(primaryShardInfo, parent, shardName, transactionContextWrapper);
} else {
onFindPrimaryShardFailure(failure, parent, shardName, transactionContextWrapper);
}
}
}, actorContext.getClientDispatcher());
}
return transactionContextWrapper;
}
代码示例来源:origin: wxyyxc1992/Backend-Boilerplates
public void run() {
ask(frontend,
new TransformationJob("hello-" + counter.incrementAndGet()),
timeout).onSuccess(new OnSuccess<Object>() {
public void onSuccess(Object result) {
System.out.println(result);
}
}, ec);
}
代码示例来源:origin: org.opendaylight.controller/sal-distributed-datastore
@Override
public ListenableFuture<Void> abort() {
dataTree.startAbort(this);
state = State.ABORTED;
final Optional<Future<Iterable<Object>>> maybeAborts = userCohorts.abort();
if (!maybeAborts.isPresent()) {
return VOID_FUTURE;
}
final Future<Iterable<Object>> aborts = maybeAborts.get();
if (aborts.isCompleted()) {
return VOID_FUTURE;
}
final SettableFuture<Void> ret = SettableFuture.create();
aborts.onComplete(new OnComplete<Iterable<Object>>() {
@Override
public void onComplete(final Throwable failure, final Iterable<Object> objs) {
if (failure != null) {
ret.setException(failure);
} else {
ret.set(null);
}
}
}, ExecutionContexts.global());
return ret;
}
代码示例来源:origin: org.apache.flink/flink-runtime-web_2.10
private void logErrorOnFailure(Future<Object> future, final String message) {
future.onFailure(new OnFailure() {
@Override
public void onFailure(Throwable failure) throws Throwable {
LOG.debug(message, failure);
}
}, ctx);
}
代码示例来源:origin: keeps/roda
@Override
public void onReceive(Object message) {
Timeout timeout = new Timeout(5, TimeUnit.SECONDS);
Future<Object> f = ask(masterProxy, message, timeout);
final ExecutionContext ec = getContext().system().dispatcher();
Future<Object> res = f.map(new Mapper<Object, Object>() {
@Override
public Object apply(Object msg) {
if (msg instanceof Master.Ack)
return Ok.getInstance();
else
return super.apply(msg);
}
}, ec).recover(new Recover<Object>() {
@Override
public Object recover(Throwable failure) throws Throwable {
return NotOk.getInstance();
}
}, ec);
pipe(res, ec).to(getSender());
}
代码示例来源:origin: opendaylight/controller
@Test(expected = SchemaSourceException.class)
public void testGetNonExistentYangTextSchemaSource() throws Exception {
Mockito.when(mockedLocalRepository.getSchemaSource(ID, YangTextSchemaSource.class)).thenReturn(
Futures.immediateFailedCheckedFuture(
new SchemaSourceException("Source is not provided")));
Future<YangTextSchemaSourceSerializationProxy> retrievedSourceFuture =
remoteRepository.getYangTextSchemaSource(ID);
assertTrue(retrievedSourceFuture.isCompleted());
Await.result(retrievedSourceFuture, FiniteDuration.Zero());
}
代码示例来源:origin: org.apache.flink/flink-runtime_2.10
if (cachedFuture.isCompleted() &&
cachedFuture.value().get().isFailure()) {
代码示例来源:origin: org.apache.flink/flink-runtime_2.10
private Future<BlobKey> requestTaskManagerLog(TaskManagerMessages.RequestTaskManagerLog request, Time timeout) {
Preconditions.checkNotNull(request);
Preconditions.checkNotNull(timeout);
scala.concurrent.Future<BlobKey> blobKeyFuture = actorGateway
.ask(
request,
new FiniteDuration(timeout.getSize(), timeout.getUnit()))
.mapTo(ClassTag$.MODULE$.<BlobKey>apply(BlobKey.class));
return new FlinkFuture<>(blobKeyFuture);
}
}
代码示例来源:origin: com.alibaba.blink/flink-runtime
@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.apache.flink/flink-runtime_2.10
@Override
public void notifyLeaderAddress(String leaderAddress, final UUID leaderSessionID) {
if (LOG.isDebugEnabled()) {
LOG.debug("Received leader address notification {}:{}", leaderAddress, leaderSessionID);
}
if (leaderAddress == null) {
jobManagerFuture = UNKNOWN_JOB_MANAGER;
} else {
jobManagerFuture = AkkaUtils.getActorRefFuture(leaderAddress, actorSystem, askTimeout)
.map(new Mapper<ActorRef, ActorGateway>() {
@Override
public ActorGateway apply(ActorRef actorRef) {
return new AkkaActorGateway(actorRef, leaderSessionID);
}
}, actorSystem.dispatcher());
}
}
内容来源于网络,如有侵权,请联系作者删除!