Java Code Examples for org.apache.flink.shaded.netty4.io.netty.channel.EventLoopGroup#isShutdown()

The following examples show how to use org.apache.flink.shaded.netty4.io.netty.channel.EventLoopGroup#isShutdown() . 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: AbstractServerBase.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
/**
 * Shuts down the server and all related thread pools.
 * @return A {@link CompletableFuture} that will be completed upon termination of the shutdown process.
 */
public CompletableFuture<Void> shutdownServer() {
	CompletableFuture<Void> shutdownFuture = new CompletableFuture<>();
	if (serverShutdownFuture.compareAndSet(null, shutdownFuture)) {
		log.info("Shutting down {} @ {}", serverName, serverAddress);

		final CompletableFuture<Void> groupShutdownFuture = new CompletableFuture<>();
		if (bootstrap != null) {
			EventLoopGroup group = bootstrap.group();
			if (group != null && !group.isShutdown()) {
				group.shutdownGracefully(0L, 0L, TimeUnit.MILLISECONDS)
						.addListener(finished -> {
							if (finished.isSuccess()) {
								groupShutdownFuture.complete(null);
							} else {
								groupShutdownFuture.completeExceptionally(finished.cause());
							}
						});
			} else {
				groupShutdownFuture.complete(null);
			}
		} else {
			groupShutdownFuture.complete(null);
		}

		final CompletableFuture<Void> handlerShutdownFuture = new CompletableFuture<>();
		if (handler == null) {
			handlerShutdownFuture.complete(null);
		} else {
			handler.shutdown().whenComplete((result, throwable) -> {
				if (throwable != null) {
					handlerShutdownFuture.completeExceptionally(throwable);
				} else {
					handlerShutdownFuture.complete(null);
				}
			});
		}

		final CompletableFuture<Void> queryExecShutdownFuture = CompletableFuture.runAsync(() -> {
			if (queryExecutor != null) {
				ExecutorUtils.gracefulShutdown(10L, TimeUnit.MINUTES, queryExecutor);
			}
		});

		CompletableFuture.allOf(
				queryExecShutdownFuture, groupShutdownFuture, handlerShutdownFuture
		).whenComplete((result, throwable) -> {
			if (throwable != null) {
				shutdownFuture.completeExceptionally(throwable);
			} else {
				shutdownFuture.complete(null);
			}
		});
	}
	return serverShutdownFuture.get();
}
 
Example 2
Source File: AbstractServerBase.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Shuts down the server and all related thread pools.
 * @return A {@link CompletableFuture} that will be completed upon termination of the shutdown process.
 */
public CompletableFuture<Void> shutdownServer() {
	CompletableFuture<Void> shutdownFuture = new CompletableFuture<>();
	if (serverShutdownFuture.compareAndSet(null, shutdownFuture)) {
		log.info("Shutting down {} @ {}", serverName, serverAddress);

		final CompletableFuture<Void> groupShutdownFuture = new CompletableFuture<>();
		if (bootstrap != null) {
			EventLoopGroup group = bootstrap.group();
			if (group != null && !group.isShutdown()) {
				group.shutdownGracefully(0L, 0L, TimeUnit.MILLISECONDS)
						.addListener(finished -> {
							if (finished.isSuccess()) {
								groupShutdownFuture.complete(null);
							} else {
								groupShutdownFuture.completeExceptionally(finished.cause());
							}
						});
			} else {
				groupShutdownFuture.complete(null);
			}
		} else {
			groupShutdownFuture.complete(null);
		}

		final CompletableFuture<Void> handlerShutdownFuture = new CompletableFuture<>();
		if (handler == null) {
			handlerShutdownFuture.complete(null);
		} else {
			handler.shutdown().whenComplete((result, throwable) -> {
				if (throwable != null) {
					handlerShutdownFuture.completeExceptionally(throwable);
				} else {
					handlerShutdownFuture.complete(null);
				}
			});
		}

		final CompletableFuture<Void> queryExecShutdownFuture = CompletableFuture.runAsync(() -> {
			if (queryExecutor != null) {
				ExecutorUtils.gracefulShutdown(10L, TimeUnit.MINUTES, queryExecutor);
			}
		});

		CompletableFuture.allOf(
				queryExecShutdownFuture, groupShutdownFuture, handlerShutdownFuture
		).whenComplete((result, throwable) -> {
			if (throwable != null) {
				shutdownFuture.completeExceptionally(throwable);
			} else {
				shutdownFuture.complete(null);
			}
		});
	}
	return serverShutdownFuture.get();
}
 
Example 3
Source File: AbstractServerBase.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Shuts down the server and all related thread pools.
 * @return A {@link CompletableFuture} that will be completed upon termination of the shutdown process.
 */
public CompletableFuture<Void> shutdownServer() {
	CompletableFuture<Void> shutdownFuture = new CompletableFuture<>();
	if (serverShutdownFuture.compareAndSet(null, shutdownFuture)) {
		log.info("Shutting down {} @ {}", serverName, serverAddress);

		final CompletableFuture<Void> groupShutdownFuture = new CompletableFuture<>();
		if (bootstrap != null) {
			EventLoopGroup group = bootstrap.group();
			if (group != null && !group.isShutdown()) {
				group.shutdownGracefully(0L, 0L, TimeUnit.MILLISECONDS)
						.addListener(finished -> {
							if (finished.isSuccess()) {
								groupShutdownFuture.complete(null);
							} else {
								groupShutdownFuture.completeExceptionally(finished.cause());
							}
						});
			} else {
				groupShutdownFuture.complete(null);
			}
		} else {
			groupShutdownFuture.complete(null);
		}

		final CompletableFuture<Void> handlerShutdownFuture = new CompletableFuture<>();
		if (handler == null) {
			handlerShutdownFuture.complete(null);
		} else {
			handler.shutdown().whenComplete((result, throwable) -> {
				if (throwable != null) {
					handlerShutdownFuture.completeExceptionally(throwable);
				} else {
					handlerShutdownFuture.complete(null);
				}
			});
		}

		final CompletableFuture<Void> queryExecShutdownFuture = CompletableFuture.runAsync(() -> {
			if (queryExecutor != null) {
				ExecutorUtils.gracefulShutdown(10L, TimeUnit.MINUTES, queryExecutor);
			}
		});

		CompletableFuture.allOf(
				queryExecShutdownFuture, groupShutdownFuture, handlerShutdownFuture
		).whenComplete((result, throwable) -> {
			if (throwable != null) {
				shutdownFuture.completeExceptionally(throwable);
			} else {
				shutdownFuture.complete(null);
			}
		});
	}
	return serverShutdownFuture.get();
}