@Override public Void apply(Acknowledge acknowledge, Throwable throwable) { if (acknowledge != null) { completableFuture.complete(acknowledge); } else { completableFuture.completeExceptionally(throwable); } return null; } });
@Override public Collection<OUT> get() throws Exception { return resultFuture.get(); }
/** * Cancels the given slot request. * * @param pendingSlotRequest to cancel */ private void cancelPendingSlotRequest(PendingSlotRequest pendingSlotRequest) { CompletableFuture<Acknowledge> request = pendingSlotRequest.getRequestFuture(); if (null != request) { request.cancel(false); } }
@Override public void collect(Throwable error) { resultFuture.completeExceptionally(error); } }
@Override public void collect(Collection<OUT> result) { resultFuture.complete(result); }
completableFuture.handleAsync(new BiFunction<Acknowledge, Throwable, Void>() { @Override public Void apply(Acknowledge acknowledge, Throwable throwable) {
void discard(Throwable cause) { if (!isDiscarded) { pendingTasks.clear(); stackTracesByTask.clear(); stackTraceFuture.completeExceptionally(new RuntimeException("Discarded", cause)); isDiscarded = true; } }
@Override public void postStop() throws Exception { super.postStop(); // IMPORTANT: This only works if we don't use a restarting supervisor strategy. Otherwise // we would complete the future and let the actor system restart the actor with a completed // future. // Complete the termination future so that others know that we've stopped. terminationFuture.complete(null); }
public void stop() throws Exception { running = false; leaderRetrievalService.stop(); cancelTimeout(); leaderIdFuture.completeExceptionally(new Exception("Job leader id service has been stopped.")); }
private void onTerminalState(JobStatus status) { try { CheckpointCoordinator coord = this.checkpointCoordinator; this.checkpointCoordinator = null; if (coord != null) { coord.shutdown(status); } } catch (Exception e) { LOG.error("Error while cleaning up after execution", e); } finally { terminationFuture.complete(status); } }
@VisibleForTesting public JobStatus waitUntilTerminal() throws InterruptedException { try { return terminationFuture.get(); } catch (ExecutionException e) { // this should never happen // it would be a bug, so we don't expect this to be handled and throw // an unchecked exception here throw new RuntimeException(e); } }
/** * Rejects the pending slot request by failing the request future with a * {@link SlotAllocationException}. * * @param pendingSlotRequest to reject * @param cause of the rejection */ private void rejectPendingSlotRequest(PendingSlotRequest pendingSlotRequest, Exception cause) { CompletableFuture<Acknowledge> request = pendingSlotRequest.getRequestFuture(); if (null != request) { request.completeExceptionally(new SlotAllocationException(cause)); } else { LOG.debug("Cannot reject pending slot request {}, since no request has been sent.", pendingSlotRequest.getAllocationId()); } }
void completePromiseAndDiscard() { if (isComplete()) { isDiscarded = true; long endTime = System.currentTimeMillis(); StackTraceSample stackTraceSample = new StackTraceSample( sampleId, startTime, endTime, stackTracesByTask); stackTraceFuture.complete(stackTraceSample); } else { throw new IllegalStateException("Not completed yet"); } }
completionFuture.completeExceptionally(t);
@Override public void accept(RegistrationResponse result) { if (!isCanceled()) { if (result instanceof RegistrationResponse.Success) { // registration successful! Success success = (Success) result; completionFuture.complete(Tuple2.of(gateway, success)); } else { // registration refused or unknown if (result instanceof RegistrationResponse.Decline) { RegistrationResponse.Decline decline = (RegistrationResponse.Decline) result; log.info("Registration at {} was declined: {}", targetName, decline.getReason()); } else { log.error("Received unknown response to registration attempt: {}", result); } log.info("Pausing and re-attempting registration in {} ms", delayOnRefusedRegistration); registerLater(gateway, 1, initialRegistrationTimeout, delayOnRefusedRegistration); } } } }, rpcService.getExecutor());
completionFuture.completeExceptionally(t);
if (queued.getFuture() != null) { try { queued.getFuture().complete(newSlot);