org.apache.flink.shaded.netty4.io.netty.channel.EventLoopGroup Java Examples

The following examples show how to use org.apache.flink.shaded.netty4.io.netty.channel.EventLoopGroup. 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: RestServerEndpoint.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
/**
 * Stops this REST server endpoint.
 *
 * @return Future which is completed once the shut down has been finished.
 */
protected CompletableFuture<Void> shutDownInternal() {

	synchronized (lock) {

		CompletableFuture<?> channelFuture = new CompletableFuture<>();
		if (serverChannel != null) {
			serverChannel.close().addListener(finished -> {
				if (finished.isSuccess()) {
					channelFuture.complete(null);
				} else {
					channelFuture.completeExceptionally(finished.cause());
				}
			});
			serverChannel = null;
		}

		final CompletableFuture<Void> channelTerminationFuture = new CompletableFuture<>();

		channelFuture.thenRun(() -> {
			CompletableFuture<?> groupFuture = new CompletableFuture<>();
			CompletableFuture<?> childGroupFuture = new CompletableFuture<>();
			final Time gracePeriod = Time.seconds(10L);

			if (bootstrap != null) {
				final ServerBootstrapConfig config = bootstrap.config();
				final EventLoopGroup group = config.group();
				if (group != null) {
					group.shutdownGracefully(0L, gracePeriod.toMilliseconds(), TimeUnit.MILLISECONDS)
						.addListener(finished -> {
							if (finished.isSuccess()) {
								groupFuture.complete(null);
							} else {
								groupFuture.completeExceptionally(finished.cause());
							}
						});
				} else {
					groupFuture.complete(null);
				}

				final EventLoopGroup childGroup = config.childGroup();
				if (childGroup != null) {
					childGroup.shutdownGracefully(0L, gracePeriod.toMilliseconds(), TimeUnit.MILLISECONDS)
						.addListener(finished -> {
							if (finished.isSuccess()) {
								childGroupFuture.complete(null);
							} else {
								childGroupFuture.completeExceptionally(finished.cause());
							}
						});
				} else {
					childGroupFuture.complete(null);
				}

				bootstrap = null;
			} else {
				// complete the group futures since there is nothing to stop
				groupFuture.complete(null);
				childGroupFuture.complete(null);
			}

			CompletableFuture<Void> combinedFuture = FutureUtils.completeAll(Arrays.asList(groupFuture, childGroupFuture));

			combinedFuture.whenComplete(
				(Void ignored, Throwable throwable) -> {
					if (throwable != null) {
						channelTerminationFuture.completeExceptionally(throwable);
					} else {
						channelTerminationFuture.complete(null);
					}
				});
		});

		return channelTerminationFuture;
	}
}
 
Example #2
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 #3
Source File: RestServerEndpoint.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Stops this REST server endpoint.
 *
 * @return Future which is completed once the shut down has been finished.
 */
protected CompletableFuture<Void> shutDownInternal() {

	synchronized (lock) {

		CompletableFuture<?> channelFuture = new CompletableFuture<>();
		if (serverChannel != null) {
			serverChannel.close().addListener(finished -> {
				if (finished.isSuccess()) {
					channelFuture.complete(null);
				} else {
					channelFuture.completeExceptionally(finished.cause());
				}
			});
			serverChannel = null;
		}

		final CompletableFuture<Void> channelTerminationFuture = new CompletableFuture<>();

		channelFuture.thenRun(() -> {
			CompletableFuture<?> groupFuture = new CompletableFuture<>();
			CompletableFuture<?> childGroupFuture = new CompletableFuture<>();
			final Time gracePeriod = Time.seconds(10L);

			if (bootstrap != null) {
				final ServerBootstrapConfig config = bootstrap.config();
				final EventLoopGroup group = config.group();
				if (group != null) {
					group.shutdownGracefully(0L, gracePeriod.toMilliseconds(), TimeUnit.MILLISECONDS)
						.addListener(finished -> {
							if (finished.isSuccess()) {
								groupFuture.complete(null);
							} else {
								groupFuture.completeExceptionally(finished.cause());
							}
						});
				} else {
					groupFuture.complete(null);
				}

				final EventLoopGroup childGroup = config.childGroup();
				if (childGroup != null) {
					childGroup.shutdownGracefully(0L, gracePeriod.toMilliseconds(), TimeUnit.MILLISECONDS)
						.addListener(finished -> {
							if (finished.isSuccess()) {
								childGroupFuture.complete(null);
							} else {
								childGroupFuture.completeExceptionally(finished.cause());
							}
						});
				} else {
					childGroupFuture.complete(null);
				}

				bootstrap = null;
			} else {
				// complete the group futures since there is nothing to stop
				groupFuture.complete(null);
				childGroupFuture.complete(null);
			}

			CompletableFuture<Void> combinedFuture = FutureUtils.completeAll(Arrays.asList(groupFuture, childGroupFuture));

			combinedFuture.whenComplete(
				(Void ignored, Throwable throwable) -> {
					if (throwable != null) {
						channelTerminationFuture.completeExceptionally(throwable);
					} else {
						channelTerminationFuture.complete(null);
					}
				});
		});

		return channelTerminationFuture;
	}
}
 
Example #4
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 #5
Source File: RestServerEndpoint.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Stops this REST server endpoint.
 *
 * @return Future which is completed once the shut down has been finished.
 */
protected CompletableFuture<Void> shutDownInternal() {

	synchronized (lock) {

		CompletableFuture<?> channelFuture = new CompletableFuture<>();
		if (serverChannel != null) {
			serverChannel.close().addListener(finished -> {
				if (finished.isSuccess()) {
					channelFuture.complete(null);
				} else {
					channelFuture.completeExceptionally(finished.cause());
				}
			});
			serverChannel = null;
		}

		final CompletableFuture<Void> channelTerminationFuture = new CompletableFuture<>();

		channelFuture.thenRun(() -> {
			CompletableFuture<?> groupFuture = new CompletableFuture<>();
			CompletableFuture<?> childGroupFuture = new CompletableFuture<>();
			final Time gracePeriod = Time.seconds(10L);

			if (bootstrap != null) {
				final ServerBootstrapConfig config = bootstrap.config();
				final EventLoopGroup group = config.group();
				if (group != null) {
					group.shutdownGracefully(0L, gracePeriod.toMilliseconds(), TimeUnit.MILLISECONDS)
						.addListener(finished -> {
							if (finished.isSuccess()) {
								groupFuture.complete(null);
							} else {
								groupFuture.completeExceptionally(finished.cause());
							}
						});
				} else {
					groupFuture.complete(null);
				}

				final EventLoopGroup childGroup = config.childGroup();
				if (childGroup != null) {
					childGroup.shutdownGracefully(0L, gracePeriod.toMilliseconds(), TimeUnit.MILLISECONDS)
						.addListener(finished -> {
							if (finished.isSuccess()) {
								childGroupFuture.complete(null);
							} else {
								childGroupFuture.completeExceptionally(finished.cause());
							}
						});
				} else {
					childGroupFuture.complete(null);
				}

				bootstrap = null;
			} else {
				// complete the group futures since there is nothing to stop
				groupFuture.complete(null);
				childGroupFuture.complete(null);
			}

			CompletableFuture<Void> combinedFuture = FutureUtils.completeAll(Arrays.asList(groupFuture, childGroupFuture));

			combinedFuture.whenComplete(
				(Void ignored, Throwable throwable) -> {
					if (throwable != null) {
						channelTerminationFuture.completeExceptionally(throwable);
					} else {
						channelTerminationFuture.complete(null);
					}
				});
		});

		return channelTerminationFuture;
	}
}
 
Example #6
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();
}