use of org.apache.flink.shaded.netty4.io.netty.util.concurrent.Future in project zeebe by camunda.
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 helidon by oracle.
the class RequestContentSubscriber method sendData.
private void sendData(DataChunk data) {
LOGGER.finest(() -> "(client reqID: " + requestId + ") Sending data chunk");
DefaultHttpContent httpContent = new DefaultHttpContent(Unpooled.wrappedBuffer(data.data()));
channel.write(true, httpContent, f -> f.addListener(future -> {
data.release();
subscription.request(1);
LOGGER.finest(() -> "(client reqID: " + requestId + ") Data chunk sent with result: " + future.isSuccess());
}).addListener(completeOnFailureListener("(client reqID: " + requestId + ") Failure when sending a content!")).addListener(ChannelFutureListener.CLOSE_ON_FAILURE));
}
use of org.apache.flink.shaded.netty4.io.netty.util.concurrent.Future in project glowroot by glowroot.
the class EventLoopGroups method create.
// copy of io.grpc.netty.Utils.DefaultEventLoopGroupResource with some modification
static EventLoopGroup create(String name) {
final ExecutorService executor = Executors.newSingleThreadExecutor(new ThreadFactoryBuilder().setDaemon(true).setNameFormat(name).build());
NioEventLoopGroup nioEventLoopGroup = new NioEventLoopGroup(1, executor);
nioEventLoopGroup.terminationFuture().addListener(new GenericFutureListener<Future</*@Nullable*/
Object>>() {
@Override
public void operationComplete(Future</*@Nullable*/
Object> future) throws Exception {
executor.shutdown();
if (!executor.awaitTermination(10, SECONDS)) {
throw new IllegalStateException("Could not terminate executor");
}
}
});
return nioEventLoopGroup;
}
use of org.apache.flink.shaded.netty4.io.netty.util.concurrent.Future in project SonOyuncuClient by cppool.
the class NetworkManager method sendPacket.
public void sendPacket(Packet packetIn) {
final ThePacket eventPacket = new ThePacket(packetIn, false);
if (eventPacket.cancelled)
return;
if (this.isChannelOpen()) {
this.flushOutboundQueue();
this.dispatchPacket(eventPacket.packet, (GenericFutureListener<? extends Future<? super Void>>[]) null);
} else {
this.readWriteLock.writeLock().lock();
try {
this.outboundPacketsQueue.add(new NetworkManager.InboundHandlerTuplePacketListener(packetIn, (GenericFutureListener[]) null));
} finally {
this.readWriteLock.writeLock().unlock();
}
}
}
use of org.apache.flink.shaded.netty4.io.netty.util.concurrent.Future in project arthas by alibaba.
the class NettyWebsocketTtyBootstrap method start.
public void start(Consumer<TtyConnection> handler, final Consumer<Throwable> doneHandler) {
group = new NioEventLoopGroup(new DefaultThreadFactory("arthas-NettyWebsocketTtyBootstrap", true));
if (this.port > 0) {
ServerBootstrap b = new ServerBootstrap();
b.group(group).channel(NioServerSocketChannel.class).handler(new LoggingHandler(LogLevel.INFO)).childHandler(new TtyServerInitializer(channelGroup, handler, workerGroup, httpSessionManager));
final ChannelFuture f = b.bind(host, port);
f.addListener(new GenericFutureListener<Future<? super Void>>() {
@Override
public void operationComplete(Future<? super Void> future) throws Exception {
if (future.isSuccess()) {
channel = f.channel();
doneHandler.accept(null);
} else {
doneHandler.accept(future.cause());
}
}
});
}
// listen local address in VM communication
ServerBootstrap b2 = new ServerBootstrap();
b2.group(group).channel(LocalServerChannel.class).handler(new LoggingHandler(LogLevel.INFO)).childHandler(new LocalTtyServerInitializer(channelGroup, handler, workerGroup));
ChannelFuture bindLocalFuture = b2.bind(new LocalAddress(ArthasConstants.NETTY_LOCAL_ADDRESS));
if (this.port < 0) {
// 保证回调doneHandler
bindLocalFuture.addListener(new GenericFutureListener<Future<? super Void>>() {
@Override
public void operationComplete(Future<? super Void> future) throws Exception {
if (future.isSuccess()) {
doneHandler.accept(null);
} else {
doneHandler.accept(future.cause());
}
}
});
}
}
Aggregations