use of org.apache.flink.shaded.netty4.io.netty.util.concurrent.Future in project zeebe by camunda-cloud.
the class NettyMessagingService method bind.
/**
* Recursively binds the given bootstrap to the given interfaces.
*
* @param bootstrap the bootstrap to bind
* @param addressIterator an iterator of Addresses to which to bind
* @param future the future to completed once the bootstrap has been bound to all provided
* interfaces
*/
private void bind(final ServerBootstrap bootstrap, final Iterator<Address> addressIterator, final CompletableFuture<Void> future) {
if (addressIterator.hasNext()) {
final Address address = addressIterator.next();
bootstrap.bind(address.host(), address.port()).addListener((ChannelFutureListener) f -> {
if (f.isSuccess()) {
log.info("TCP server listening for connections on {}", address);
serverChannel = f.channel();
bind(bootstrap, addressIterator, future);
} else {
log.warn("Failed to bind TCP server to port {} due to {}", address, f.cause());
future.completeExceptionally(f.cause());
}
});
} else {
future.complete(null);
}
}
use of org.apache.flink.shaded.netty4.io.netty.util.concurrent.Future in project zeebe by camunda-cloud.
the class NettyMessagingService method bootstrapClient.
/**
* Bootstraps a new channel to the given address.
*
* @param address the address to which to connect
* @return a future to be completed with the connected channel
*/
private CompletableFuture<Channel> bootstrapClient(final Address address) {
final CompletableFuture<Channel> future = new OrderedFuture<>();
final InetAddress resolvedAddress = address.address(true);
if (resolvedAddress == null) {
future.completeExceptionally(new IllegalStateException("Failed to bootstrap client (address " + address.toString() + " cannot be resolved)"));
return future;
}
final Bootstrap bootstrap = new Bootstrap();
bootstrap.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
bootstrap.option(ChannelOption.WRITE_BUFFER_WATER_MARK, new WriteBufferWaterMark(10 * 32 * 1024, 10 * 64 * 1024));
bootstrap.option(ChannelOption.SO_RCVBUF, 1024 * 1024);
bootstrap.option(ChannelOption.SO_SNDBUF, 1024 * 1024);
bootstrap.option(ChannelOption.SO_KEEPALIVE, true);
bootstrap.option(ChannelOption.TCP_NODELAY, true);
bootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 1000);
bootstrap.group(clientGroup);
// TODO: Make this faster:
// http://normanmaurer.me/presentations/2014-facebook-eng-netty/slides.html#37.0
bootstrap.channel(clientChannelClass);
bootstrap.remoteAddress(resolvedAddress, address.port());
bootstrap.handler(new BasicClientChannelInitializer(future));
final Channel channel = bootstrap.connect().addListener(onConnect -> {
if (!onConnect.isSuccess()) {
future.completeExceptionally(new ConnectException(String.format("Failed to connect channel for address %s", address)));
}
}).channel();
// immediately ensure we're notified of the channel being closed. the common case is that the
// channel is closed after we've handled the request (and response in the case of a
// sendAndReceive operation), so the future is already completed by then. If it isn't, then the
// channel was closed too early, which should be handled as a failure from the consumer point
// of view.
channel.closeFuture().addListener(onClose -> future.completeExceptionally(new ConnectException(String.format("Channel %s for address %s was closed unexpectedly before the request was handled", channel, address))));
return future;
}
use of org.apache.flink.shaded.netty4.io.netty.util.concurrent.Future in project pegasus-java-client by XiaoMi.
the class ClusterManager method close.
@Override
public void close() {
if (enableCounter) {
MetricsManager.finish();
}
metaSession.closeSession();
for (Map.Entry<rpc_address, ReplicaSession> entry : replicaSessions.entrySet()) {
entry.getValue().closeSession();
}
Future metaGroupFuture = metaGroup.shutdownGracefully();
Future replicaGroupFuture = replicaGroup.shutdownGracefully();
Future tableGroupFuture = tableGroup.shutdownGracefully();
Future timeoutTaskGroupFuture = timeoutTaskGroup.shutdownGracefully();
try {
metaGroupFuture.sync();
logger.info("meta group has closed");
} catch (Exception ex) {
logger.warn("close meta group failed: ", ex);
}
try {
replicaGroupFuture.sync();
logger.info("replica group has closed");
} catch (Exception ex) {
logger.warn("close replica group failed: ", ex);
}
try {
tableGroupFuture.sync();
logger.info("table group has closed");
} catch (Exception ex) {
logger.warn("close table group failed: ", ex);
}
try {
timeoutTaskGroupFuture.sync();
logger.info("timeout task group has closed");
} catch (Exception ex) {
logger.warn("close timeout task group failed: ", ex);
}
logger.info("cluster manager has closed");
}
use of org.apache.flink.shaded.netty4.io.netty.util.concurrent.Future in project bazel-buildfarm by bazelbuild.
the class HttpBlobStore method acquireDownloadChannel.
@SuppressWarnings("FutureReturnValueIgnored")
private Future<Channel> acquireDownloadChannel() {
Promise<Channel> channelReady = eventLoop.next().newPromise();
channelPool.acquire().addListener((Future<Channel> channelAcquired) -> {
if (!channelAcquired.isSuccess()) {
channelReady.setFailure(channelAcquired.cause());
return;
}
try {
Channel ch = channelAcquired.getNow();
ChannelPipeline p = ch.pipeline();
if (!isChannelPipelineEmpty(p)) {
channelReady.setFailure(new IllegalStateException("Channel pipeline is not empty."));
return;
}
ch.pipeline().addFirst("read-timeout-handler", new ReadTimeoutHandler(timeoutMillis));
p.addLast(new HttpClientCodec());
synchronized (credentialsLock) {
p.addLast(new HttpDownloadHandler(creds));
}
channelReady.setSuccess(ch);
} catch (Throwable t) {
channelReady.setFailure(t);
}
});
return channelReady;
}
use of org.apache.flink.shaded.netty4.io.netty.util.concurrent.Future in project bazel-buildfarm by bazelbuild.
the class HttpBlobStore method getAfterCredentialRefresh.
@SuppressWarnings("FutureReturnValueIgnored")
private void getAfterCredentialRefresh(DownloadCommand cmd, SettableFuture<Boolean> outerF) {
acquireDownloadChannel().addListener((Future<Channel> chP) -> {
if (!chP.isSuccess()) {
outerF.setException(chP.cause());
return;
}
Channel ch = chP.getNow();
ch.writeAndFlush(cmd).addListener((f) -> {
try {
if (f.isSuccess()) {
outerF.set(true);
} else {
Throwable cause = f.cause();
if (cause instanceof HttpException) {
HttpResponse response = ((HttpException) cause).response();
if (cacheMiss(response.status())) {
outerF.set(false);
return;
}
}
outerF.setException(cause);
}
} finally {
releaseDownloadChannel(ch);
}
});
});
}
Aggregations