Java Code Examples for java.util.concurrent.RunnableFuture#isDone()

The following examples show how to use java.util.concurrent.RunnableFuture#isDone() . 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: StateBackendTestBase.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
protected Future<SnapshotResult<KeyedStateHandle>> runSnapshotAsync(
	ExecutorService executorService,
	RunnableFuture<SnapshotResult<KeyedStateHandle>> snapshotRunnableFuture) throws Exception {

	if (!snapshotRunnableFuture.isDone()) {
		CompletableFuture<SnapshotResult<KeyedStateHandle>> completableFuture = new CompletableFuture<>();
		executorService.submit(() -> {
			try {
				snapshotRunnableFuture.run();
				completableFuture.complete(snapshotRunnableFuture.get());
			} catch (Exception e) {
				completableFuture.completeExceptionally(e);
			}
		});
		return completableFuture;
	}
	return CompletableFuture.completedFuture(snapshotRunnableFuture.get());
}
 
Example 2
Source File: StateBackendTestBase.java    From flink with Apache License 2.0 6 votes vote down vote up
protected Future<SnapshotResult<KeyedStateHandle>> runSnapshotAsync(
	ExecutorService executorService,
	RunnableFuture<SnapshotResult<KeyedStateHandle>> snapshotRunnableFuture) throws Exception {

	if (!snapshotRunnableFuture.isDone()) {
		CompletableFuture<SnapshotResult<KeyedStateHandle>> completableFuture = new CompletableFuture<>();
		executorService.submit(() -> {
			try {
				snapshotRunnableFuture.run();
				completableFuture.complete(snapshotRunnableFuture.get());
			} catch (Exception e) {
				completableFuture.completeExceptionally(e);
			}
		});
		return completableFuture;
	}
	return CompletableFuture.completedFuture(snapshotRunnableFuture.get());
}
 
Example 3
Source File: StateBackendTestBase.java    From flink with Apache License 2.0 6 votes vote down vote up
protected Future<SnapshotResult<KeyedStateHandle>> runSnapshotAsync(
	ExecutorService executorService,
	RunnableFuture<SnapshotResult<KeyedStateHandle>> snapshotRunnableFuture) throws Exception {

	if (!snapshotRunnableFuture.isDone()) {
		CompletableFuture<SnapshotResult<KeyedStateHandle>> completableFuture = new CompletableFuture<>();
		executorService.submit(() -> {
			try {
				snapshotRunnableFuture.run();
				completableFuture.complete(snapshotRunnableFuture.get());
			} catch (Exception e) {
				completableFuture.completeExceptionally(e);
			}
		});
		return completableFuture;
	}
	return CompletableFuture.completedFuture(snapshotRunnableFuture.get());
}
 
Example 4
Source File: StateBackendTestContext.java    From flink with Apache License 2.0 5 votes vote down vote up
@Nonnull
RunnableFuture<SnapshotResult<KeyedStateHandle>> triggerSnapshot() throws Exception {
	RunnableFuture<SnapshotResult<KeyedStateHandle>> snapshotRunnableFuture =
		keyedStateBackend.snapshot(682375462392L, 10L,
			checkpointStreamFactory, checkpointOptions);
	if (!snapshotRunnableFuture.isDone()) {
		snapshotRunnableFuture.run();
	}
	return snapshotRunnableFuture;
}
 
Example 5
Source File: FutureUtils.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * Run the given {@code RunnableFuture} if it is not done, and then retrieves its result.
 * @param future to run if not done and get
 * @param <T> type of the result
 * @return the result after running the future
 * @throws ExecutionException if a problem occurred
 * @throws InterruptedException if the current thread has been interrupted
 */
public static <T> T runIfNotDoneAndGet(RunnableFuture<T> future) throws ExecutionException, InterruptedException {

	if (null == future) {
		return null;
	}

	if (!future.isDone()) {
		future.run();
	}

	return future.get();
}
 
Example 6
Source File: StateBackendMigrationTestBase.java    From flink with Apache License 2.0 5 votes vote down vote up
private OperatorStateHandle runSnapshot(
	RunnableFuture<SnapshotResult<OperatorStateHandle>> snapshotRunnableFuture) throws Exception {

	if (!snapshotRunnableFuture.isDone()) {
		snapshotRunnableFuture.run();
	}

	return snapshotRunnableFuture.get().getJobManagerOwnedSnapshot();
}
 
Example 7
Source File: StateBackendMigrationTestBase.java    From flink with Apache License 2.0 5 votes vote down vote up
private KeyedStateHandle runSnapshot(
	RunnableFuture<SnapshotResult<KeyedStateHandle>> snapshotRunnableFuture,
	SharedStateRegistry sharedStateRegistry) throws Exception {

	if (!snapshotRunnableFuture.isDone()) {
		snapshotRunnableFuture.run();
	}

	SnapshotResult<KeyedStateHandle> snapshotResult = snapshotRunnableFuture.get();
	KeyedStateHandle jobManagerOwnedSnapshot = snapshotResult.getJobManagerOwnedSnapshot();
	if (jobManagerOwnedSnapshot != null) {
		jobManagerOwnedSnapshot.registerSharedStates(sharedStateRegistry);
	}
	return jobManagerOwnedSnapshot;
}
 
Example 8
Source File: StateBackendTestBase.java    From flink with Apache License 2.0 5 votes vote down vote up
protected KeyedStateHandle runSnapshot(
	RunnableFuture<SnapshotResult<KeyedStateHandle>> snapshotRunnableFuture,
	SharedStateRegistry sharedStateRegistry) throws Exception {

	if (!snapshotRunnableFuture.isDone()) {
		snapshotRunnableFuture.run();
	}

	SnapshotResult<KeyedStateHandle> snapshotResult = snapshotRunnableFuture.get();
	KeyedStateHandle jobManagerOwnedSnapshot = snapshotResult.getJobManagerOwnedSnapshot();
	if (jobManagerOwnedSnapshot != null) {
		jobManagerOwnedSnapshot.registerSharedStates(sharedStateRegistry);
	}
	return jobManagerOwnedSnapshot;
}
 
Example 9
Source File: FutureUtils.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Run the given {@code RunnableFuture} if it is not done, and then retrieves its result.
 * @param future to run if not done and get
 * @param <T> type of the result
 * @return the result after running the future
 * @throws ExecutionException if a problem occurred
 * @throws InterruptedException if the current thread has been interrupted
 */
public static <T> T runIfNotDoneAndGet(RunnableFuture<T> future) throws ExecutionException, InterruptedException {

	if (null == future) {
		return null;
	}

	if (!future.isDone()) {
		future.run();
	}

	return future.get();
}
 
Example 10
Source File: StateBackendTestContext.java    From flink with Apache License 2.0 5 votes vote down vote up
@Nonnull
RunnableFuture<SnapshotResult<KeyedStateHandle>> triggerSnapshot() throws Exception {
	RunnableFuture<SnapshotResult<KeyedStateHandle>> snapshotRunnableFuture =
		keyedStateBackend.snapshot(682375462392L, 10L,
			checkpointStreamFactory, checkpointOptions);
	if (!snapshotRunnableFuture.isDone()) {
		snapshotRunnableFuture.run();
	}
	return snapshotRunnableFuture;
}
 
Example 11
Source File: StateBackendMigrationTestBase.java    From flink with Apache License 2.0 5 votes vote down vote up
private OperatorStateHandle runSnapshot(
	RunnableFuture<SnapshotResult<OperatorStateHandle>> snapshotRunnableFuture) throws Exception {

	if (!snapshotRunnableFuture.isDone()) {
		snapshotRunnableFuture.run();
	}

	return snapshotRunnableFuture.get().getJobManagerOwnedSnapshot();
}
 
Example 12
Source File: StateBackendMigrationTestBase.java    From flink with Apache License 2.0 5 votes vote down vote up
private KeyedStateHandle runSnapshot(
	RunnableFuture<SnapshotResult<KeyedStateHandle>> snapshotRunnableFuture,
	SharedStateRegistry sharedStateRegistry) throws Exception {

	if (!snapshotRunnableFuture.isDone()) {
		snapshotRunnableFuture.run();
	}

	SnapshotResult<KeyedStateHandle> snapshotResult = snapshotRunnableFuture.get();
	KeyedStateHandle jobManagerOwnedSnapshot = snapshotResult.getJobManagerOwnedSnapshot();
	if (jobManagerOwnedSnapshot != null) {
		jobManagerOwnedSnapshot.registerSharedStates(sharedStateRegistry);
	}
	return jobManagerOwnedSnapshot;
}
 
Example 13
Source File: StateBackendTestBase.java    From flink with Apache License 2.0 5 votes vote down vote up
protected KeyedStateHandle runSnapshot(
	RunnableFuture<SnapshotResult<KeyedStateHandle>> snapshotRunnableFuture,
	SharedStateRegistry sharedStateRegistry) throws Exception {

	if (!snapshotRunnableFuture.isDone()) {
		snapshotRunnableFuture.run();
	}

	SnapshotResult<KeyedStateHandle> snapshotResult = snapshotRunnableFuture.get();
	KeyedStateHandle jobManagerOwnedSnapshot = snapshotResult.getJobManagerOwnedSnapshot();
	if (jobManagerOwnedSnapshot != null) {
		jobManagerOwnedSnapshot.registerSharedStates(sharedStateRegistry);
	}
	return jobManagerOwnedSnapshot;
}
 
Example 14
Source File: FutureUtils.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Run the given {@code RunnableFuture} if it is not done, and then retrieves its result.
 * @param future to run if not done and get
 * @param <T> type of the result
 * @return the result after running the future
 * @throws ExecutionException if a problem occurred
 * @throws InterruptedException if the current thread has been interrupted
 */
public static <T> T runIfNotDoneAndGet(RunnableFuture<T> future) throws ExecutionException, InterruptedException {

	if (null == future) {
		return null;
	}

	if (!future.isDone()) {
		future.run();
	}

	return future.get();
}
 
Example 15
Source File: StateBackendTestContext.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Nonnull
RunnableFuture<SnapshotResult<KeyedStateHandle>> triggerSnapshot() throws Exception {
	RunnableFuture<SnapshotResult<KeyedStateHandle>> snapshotRunnableFuture =
		keyedStateBackend.snapshot(682375462392L, 10L,
			checkpointStorageLocation, CheckpointOptions.forCheckpointWithDefaultLocation());
	if (!snapshotRunnableFuture.isDone()) {
		snapshotRunnableFuture.run();
	}
	return snapshotRunnableFuture;
}
 
Example 16
Source File: StateBackendMigrationTestBase.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private OperatorStateHandle runSnapshot(
	RunnableFuture<SnapshotResult<OperatorStateHandle>> snapshotRunnableFuture) throws Exception {

	if (!snapshotRunnableFuture.isDone()) {
		snapshotRunnableFuture.run();
	}

	return snapshotRunnableFuture.get().getJobManagerOwnedSnapshot();
}
 
Example 17
Source File: StateBackendMigrationTestBase.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private KeyedStateHandle runSnapshot(
	RunnableFuture<SnapshotResult<KeyedStateHandle>> snapshotRunnableFuture,
	SharedStateRegistry sharedStateRegistry) throws Exception {

	if (!snapshotRunnableFuture.isDone()) {
		snapshotRunnableFuture.run();
	}

	SnapshotResult<KeyedStateHandle> snapshotResult = snapshotRunnableFuture.get();
	KeyedStateHandle jobManagerOwnedSnapshot = snapshotResult.getJobManagerOwnedSnapshot();
	if (jobManagerOwnedSnapshot != null) {
		jobManagerOwnedSnapshot.registerSharedStates(sharedStateRegistry);
	}
	return jobManagerOwnedSnapshot;
}
 
Example 18
Source File: StateBackendTestBase.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
protected KeyedStateHandle runSnapshot(
	RunnableFuture<SnapshotResult<KeyedStateHandle>> snapshotRunnableFuture,
	SharedStateRegistry sharedStateRegistry) throws Exception {

	if (!snapshotRunnableFuture.isDone()) {
		snapshotRunnableFuture.run();
	}

	SnapshotResult<KeyedStateHandle> snapshotResult = snapshotRunnableFuture.get();
	KeyedStateHandle jobManagerOwnedSnapshot = snapshotResult.getJobManagerOwnedSnapshot();
	if (jobManagerOwnedSnapshot != null) {
		jobManagerOwnedSnapshot.registerSharedStates(sharedStateRegistry);
	}
	return jobManagerOwnedSnapshot;
}