/** * Register the given complete function to be called once this queue entry has been completed. * * @param completeFunction to call when the queue entry has been completed * @param executor to run the complete function */ public void onComplete( final AcceptFunction<StreamElementQueueEntry<T>> completeFunction, Executor executor) { final StreamElementQueueEntry<T> thisReference = this; getFuture().handleAsync(new BiFunction<T, Throwable, Void>() { @Override public Void apply(T t, Throwable throwable) { // call the complete function for normal completion as well as exceptional completion // see FLINK-6435 completeFunction.accept(thisReference); return null; } }, executor); }
final Future<Void> deploymentFuture = slotAllocationFuture.handle(new BiFunction<SimpleSlot, Throwable, Void>() { @Override public Void apply(SimpleSlot simpleSlot, Throwable throwable) { if (!queued && !deploymentFuture.isDone()) { markFailed(new IllegalArgumentException("The slot allocation future has not been completed yet."));
return operationResultFuture.handleAsync(new BiFunction<T, Throwable, Future<T>>() { @Override public Future<T> apply(T t, Throwable throwable) { .thenCompose(new ApplyFunction<Future<T>, Future<T>>() { @Override public Future<T> apply(Future<T> value) {
Future<BlobKey> blobKeyFuture = taskManagerFuture.thenCompose(new ApplyFunction<JobManagerMessages.TaskManagerInstance, Future<BlobKey>>() { @Override public Future<BlobKey> apply(JobManagerMessages.TaskManagerInstance value) { .thenCombine( cache, new BiFunction<BlobKey, BlobCache, Tuple2<BlobKey, BlobCache>>() { .thenComposeAsync(new ApplyFunction<Tuple2<BlobKey, BlobCache>, Future<String>>() { @Override public Future<String> apply(Tuple2<BlobKey, BlobCache> value) { logPathFuture.exceptionally(new ApplyFunction<Throwable, Void>() { @Override public Void apply(Throwable failure) { logPathFuture.thenAccept(new AcceptFunction<String>() { @Override public void accept(String filePath) {
@Override public void requestHeartbeat(final ResourceID requestOrigin, I heartbeatPayload) { if (!stopped) { log.debug("Received heartbeat request from {}.", requestOrigin); final HeartbeatTarget<O> heartbeatTarget = reportHeartbeat(requestOrigin); if (heartbeatTarget != null) { if (heartbeatPayload != null) { heartbeatListener.reportPayload(requestOrigin, heartbeatPayload); } Future<O> futurePayload = heartbeatListener.retrievePayload(); if (futurePayload != null) { Future<Void> sendHeartbeatFuture = futurePayload.thenAcceptAsync(new AcceptFunction<O>() { @Override public void accept(O retrievedPayload) { heartbeatTarget.receiveHeartbeat(getOwnResourceID(), retrievedPayload); } }, executor); sendHeartbeatFuture.exceptionally(new ApplyFunction<Throwable, Void>() { @Override public Void apply(Throwable failure) { log.warn("Could not send heartbeat to target with id {}.", requestOrigin, failure); return null; } }); } else { heartbeatTarget.receiveHeartbeat(ownResourceID, null); } } } }
private void requestSlotFromResourceManager( final AllocationID allocationID, final FlinkCompletableFuture<SimpleSlot> future, final ResourceProfile resources) { LOG.info("Requesting slot with profile {} from resource manager (request = {}).", resources, allocationID); pendingRequests.put(allocationID, new PendingRequest(allocationID, future, resources)); Future<Acknowledge> rmResponse = resourceManagerGateway.requestSlot( jobManagerLeaderId, resourceManagerLeaderId, new SlotRequest(jobId, allocationID, resources, jobManagerAddress), resourceManagerRequestsTimeout); Future<Void> slotRequestProcessingFuture = rmResponse.thenAcceptAsync(new AcceptFunction<Acknowledge>() { @Override public void accept(Acknowledge value) { slotRequestToResourceManagerSuccess(allocationID); } }, getMainThreadExecutor()); // on failure, fail the request future slotRequestProcessingFuture.exceptionallyAsync(new ApplyFunction<Throwable, Void>() { @Override public Void apply(Throwable failure) { slotRequestToResourceManagerFailed(allocationID, failure); return null; } }, getMainThreadExecutor()); }
Future<RegistrationResponse> registrationResponseFuture = jobMasterGatewayFuture.thenCombineAsync(jobLeaderIdFuture, new BiFunction<JobMasterGateway, UUID, RegistrationResponse>() { @Override public RegistrationResponse apply(final JobMasterGateway jobMasterGateway, UUID jobLeaderId) { return registrationResponseFuture.handleAsync(new BiFunction<RegistrationResponse, Throwable, RegistrationResponse>() { @Override public RegistrationResponse apply(RegistrationResponse registrationResponse, Throwable throwable) {
/** * True if the stream element queue entry has been completed; otherwise false. * * @return True if the stream element queue entry has been completed; otherwise false. */ public boolean isDone() { return getFuture().isDone(); }
@Override public void notifyPartitionConsumable(JobID jobId, ResultPartitionID partitionId, final TaskActions taskActions) { Future<Acknowledge> acknowledgeFuture = jobMasterGateway.scheduleOrUpdateConsumers( jobMasterLeaderId, partitionId, timeout); acknowledgeFuture.exceptionallyAsync(new ApplyFunction<Throwable, Void>() { @Override public Void apply(Throwable value) { LOG.error("Could not schedule or update consumers at the JobManager.", value); taskActions.failExternally(new RuntimeException("Could not notify JobManager to schedule or update consumers.", value)); return null; } }, executor); } }
/** * Sends stop RPC call. */ public void stop() { final SimpleSlot slot = assignedResource; if (slot != null) { final TaskManagerGateway taskManagerGateway = slot.getTaskManagerGateway(); Future<Acknowledge> stopResultFuture = FutureUtils.retry( new Callable<Future<Acknowledge>>() { @Override public Future<Acknowledge> call() throws Exception { return taskManagerGateway.stopTask(attemptId, timeout); } }, NUM_STOP_CALL_TRIES, executor); stopResultFuture.exceptionally(new ApplyFunction<Throwable, Void>() { @Override public Void apply(Throwable failure) { LOG.info("Stopping task was not successful.", failure); return null; } }); } }
@Override public Object call() throws Exception { return future.get(); } }, getContext().dispatcher()), getContext().dispatcher());
/** * Releases the slot represented by the given future. If the future is complete, the * slot is immediately released. Otherwise, the slot is released as soon as the future * is completed. * * <p>Note that releasing the slot means cancelling any task execution currently * associated with that slot. * * @param slotFuture The future for the slot to release. */ public static void releaseSlotFuture(Future<SimpleSlot> slotFuture) { slotFuture.handle(ReleaseSlotFunction.INSTANCE); }
slot = execAndSlot.slotFuture.getNow(null); checkNotNull(slot);
@Override public void run() { if (!stopped) { log.debug("Trigger heartbeat request."); for (HeartbeatMonitor<O> heartbeatMonitor : getHeartbeatTargets()) { Future<O> futurePayload = getHeartbeatListener().retrievePayload(); final HeartbeatTarget<O> heartbeatTarget = heartbeatMonitor.getHeartbeatTarget(); if (futurePayload != null) { Future<Void> requestHeartbeatFuture = futurePayload.thenAcceptAsync(new AcceptFunction<O>() { @Override public void accept(O payload) { heartbeatTarget.requestHeartbeat(getOwnResourceID(), payload); } }, getExecutor()); requestHeartbeatFuture.exceptionally(new ApplyFunction<Throwable, Void>() { @Override public Void apply(Throwable failure) { log.warn("Could not request the heartbeat from target {}.", heartbeatTarget, failure); return null; } }); } else { heartbeatTarget.requestHeartbeat(getOwnResourceID(), null); } } } }
/** * Registers an info message listener * * @param address address of infoMessage listener to register to this resource manager */ @RpcMethod public void registerInfoMessageListener(final String address) { if(infoMessageListeners.containsKey(address)) { log.warn("Receive a duplicate registration from info message listener on ({})", address); } else { Future<InfoMessageListenerRpcGateway> infoMessageListenerRpcGatewayFuture = getRpcService().connect(address, InfoMessageListenerRpcGateway.class); Future<Void> infoMessageListenerAcceptFuture = infoMessageListenerRpcGatewayFuture.thenAcceptAsync(new AcceptFunction<InfoMessageListenerRpcGateway>() { @Override public void accept(InfoMessageListenerRpcGateway gateway) { log.info("Receive a registration from info message listener on ({})", address); infoMessageListeners.put(address, gateway); } }, getMainThreadExecutor()); infoMessageListenerAcceptFuture.exceptionallyAsync(new ApplyFunction<Throwable, Void>() { @Override public Void apply(Throwable failure) { log.warn("Receive a registration from unreachable info message listener on ({})", address); return null; } }, getRpcService().getExecutor()); } }
/** * This method sends a CancelTask message to the instance of the assigned slot. * * The sending is tried up to NUM_CANCEL_CALL_TRIES times. */ private void sendCancelRpcCall() { final SimpleSlot slot = assignedResource; if (slot != null) { final TaskManagerGateway taskManagerGateway = slot.getTaskManagerGateway(); Future<Acknowledge> cancelResultFuture = FutureUtils.retry( new Callable<Future<Acknowledge>>() { @Override public Future<Acknowledge> call() throws Exception { return taskManagerGateway.cancelTask(attemptId, timeout); } }, NUM_CANCEL_CALL_TRIES, executor); cancelResultFuture.exceptionallyAsync(new ApplyFunction<Throwable, Void>() { @Override public Void apply(Throwable failure) { fail(new Exception("Task could not be canceled.", failure)); return null; } }, executor); } }
private WaitingConjunctFuture(Collection<? extends Future<?>> futures) { Preconditions.checkNotNull(futures, "Futures must not be null."); this.numTotal = futures.size(); if (futures.isEmpty()) { complete(null); } else { for (Future<?> future : futures) { future.handle(completionHandler); } } }
resultPartitionId); futurePartitionState.handleAsync(new BiFunction<ExecutionState, Throwable, Void>() { @Override public Void apply(ExecutionState executionState, Throwable throwable) {
return operationResultFuture.handleAsync(new BiFunction<T, Throwable, Future<T>>() { @Override public Future<T> apply(T t, Throwable throwable) { .thenCompose(new ApplyFunction<Future<T>, Future<T>>() { @Override public Future<T> apply(Future<T> value) {