Refine search
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); }
@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); }
@Override public boolean isDone() { return scalaFuture.isCompleted(); }
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); } }
@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; }
@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()); } }
actorSystem.terminate().onComplete( new OnComplete<Terminated>() { public void onComplete(Throwable failure, Terminated result) { AkkaUtils.getTimeout(config).toMillis(), TimeUnit.MILLISECONDS, futureExecutor,
final Future<OrderHistory> aggResult = aggregate.map( new Mapper<Iterable<Object>, OrderHistory>() { public OrderHistory apply(Iterable<Object> coll) {
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() ); }
@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); } }
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; }
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); }
@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; }
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); }
@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()); }
@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()); }
if (cachedFuture.isCompleted() && cachedFuture.value().get().isFailure()) {
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); } }
@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 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()); } }