Java Code Examples for org.apache.flink.runtime.concurrent.FutureUtils#orTimeout()

The following examples show how to use org.apache.flink.runtime.concurrent.FutureUtils#orTimeout() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TaskManagerRunner.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
public void onFatalError(Throwable exception) {
	LOG.error("Fatal error occurred while executing the TaskManager. Shutting it down...", exception);

	if (ExceptionUtils.isJvmFatalOrOutOfMemoryError(exception)) {
		terminateJVM();
	} else {
		closeAsync();

		FutureUtils.orTimeout(terminationFuture, FATAL_ERROR_SHUTDOWN_TIMEOUT_MS, TimeUnit.MILLISECONDS);

		terminationFuture.whenComplete(
			(Void ignored, Throwable throwable) -> {
				terminateJVM();
			});
	}
}
 
Example 2
Source File: TaskManagerRunner.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void onFatalError(Throwable exception) {
	LOG.error("Fatal error occurred while executing the TaskManager. Shutting it down...", exception);

	if (ExceptionUtils.isJvmFatalOrOutOfMemoryError(exception)) {
		terminateJVM();
	} else {
		closeAsync();

		FutureUtils.orTimeout(terminationFuture, FATAL_ERROR_SHUTDOWN_TIMEOUT_MS, TimeUnit.MILLISECONDS);

		terminationFuture.whenComplete(
			(Void ignored, Throwable throwable) -> {
				terminateJVM();
			});
	}
}
 
Example 3
Source File: TaskManagerRunner.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void onFatalError(Throwable exception) {
	Throwable enrichedException = TaskManagerExceptionUtils.tryEnrichTaskManagerError(exception);
	LOG.error("Fatal error occurred while executing the TaskManager. Shutting it down...", enrichedException);

	// In case of the Metaspace OutOfMemoryError, we expect that the graceful shutdown is possible,
	// as it does not usually require more class loading to fail again with the Metaspace OutOfMemoryError.
	if (ExceptionUtils.isJvmFatalOrOutOfMemoryError(enrichedException) &&
			!ExceptionUtils.isMetaspaceOutOfMemoryError(enrichedException)) {
		terminateJVM();
	} else {
		closeAsync();

		FutureUtils.orTimeout(terminationFuture, FATAL_ERROR_SHUTDOWN_TIMEOUT_MS, TimeUnit.MILLISECONDS);

		terminationFuture.whenComplete(
			(Void ignored, Throwable throwable) -> terminateJVM());
	}
}
 
Example 4
Source File: CompletedOperationCache.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public CompletableFuture<Void> closeAsync() {
	return FutureUtils.orTimeout(
		asyncWaitForResultsToBeAccessed(),
		COMPLETED_OPERATION_RESULT_CACHE_DURATION_SECONDS,
		TimeUnit.SECONDS);
}
 
Example 5
Source File: Scheduler.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public CompletableFuture<LogicalSlot> allocateSlot(
		SlotRequestId slotRequestId,
		ScheduledUnit task,
		SlotProfile slotProfile,
		boolean allowQueued,
		Time allocationTimeout) {

	try {
		final Object ret = scheduleTask(task, allowQueued, slotProfile.getPreferredLocations());

		if (ret instanceof SimpleSlot) {
			return CompletableFuture.completedFuture((SimpleSlot) ret);
		}
		else if (ret instanceof CompletableFuture) {
			@SuppressWarnings("unchecked")
			CompletableFuture<LogicalSlot> typed = (CompletableFuture<LogicalSlot>) ret;
			return FutureUtils.orTimeout(typed, allocationTimeout.toMilliseconds(), TimeUnit.MILLISECONDS);
		}
		else {
			// this should never happen, simply guard this case with an exception
			throw new RuntimeException();
		}
	} catch (NoResourceAvailableException e) {
		return FutureUtils.completedExceptionally(e);
	}
}
 
Example 6
Source File: CompletedOperationCache.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public CompletableFuture<Void> closeAsync() {
	return FutureUtils.orTimeout(
		asyncWaitForResultsToBeAccessed(),
		COMPLETED_OPERATION_RESULT_CACHE_DURATION_SECONDS,
		TimeUnit.SECONDS);
}
 
Example 7
Source File: CompletedOperationCache.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public CompletableFuture<Void> closeAsync() {
	return FutureUtils.orTimeout(
		asyncWaitForResultsToBeAccessed(),
		COMPLETED_OPERATION_RESULT_CACHE_DURATION_SECONDS,
		TimeUnit.SECONDS);
}