Search in sources :

Example 91 with Future

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);
    }
}
Also used : DefaultThreadFactory(io.netty.util.concurrent.DefaultThreadFactory) Address(io.atomix.utils.net.Address) ChannelInboundHandlerAdapter(io.netty.channel.ChannelInboundHandlerAdapter) BiFunction(java.util.function.BiFunction) LoggerFactory(org.slf4j.LoggerFactory) TimeoutException(java.util.concurrent.TimeoutException) MessagingConfig(io.atomix.cluster.messaging.MessagingConfig) InetAddress(java.net.InetAddress) Duration(java.time.Duration) Map(java.util.Map) SocketChannel(io.netty.channel.socket.SocketChannel) ChannelInitializer(io.netty.channel.ChannelInitializer) Collection(java.util.Collection) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) PooledByteBufAllocator(io.netty.buffer.PooledByteBufAllocator) Collectors(java.util.stream.Collectors) ServerChannel(io.netty.channel.ServerChannel) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) Executors(java.util.concurrent.Executors) List(java.util.List) Optional(java.util.Optional) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) WriteBufferWaterMark(io.netty.channel.WriteBufferWaterMark) ChannelOption(io.netty.channel.ChannelOption) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CompletableFuture(java.util.concurrent.CompletableFuture) ManagedMessagingService(io.atomix.cluster.messaging.ManagedMessagingService) OptionalInt(java.util.OptionalInt) Function(java.util.function.Function) ArrayList(java.util.ArrayList) EpollSocketChannel(io.netty.channel.epoll.EpollSocketChannel) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) Threads.namedThreads(io.atomix.utils.concurrent.Threads.namedThreads) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ByteBuf(io.netty.buffer.ByteBuf) EpollServerSocketChannel(io.netty.channel.epoll.EpollServerSocketChannel) ChannelFutureListener(io.netty.channel.ChannelFutureListener) EpollEventLoopGroup(io.netty.channel.epoll.EpollEventLoopGroup) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) BiConsumer(java.util.function.BiConsumer) StringUtil(io.camunda.zeebe.util.StringUtil) ConnectException(java.net.ConnectException) ZlibCodecFactory(io.netty.handler.codec.compression.ZlibCodecFactory) EventLoopGroup(io.netty.channel.EventLoopGroup) Logger(org.slf4j.Logger) SslContext(io.netty.handler.ssl.SslContext) Iterator(java.util.Iterator) Executor(java.util.concurrent.Executor) MessagingService(io.atomix.cluster.messaging.MessagingService) Throwables(com.google.common.base.Throwables) SnappyFrameEncoder(io.netty.handler.codec.compression.SnappyFrameEncoder) ZlibWrapper(io.netty.handler.codec.compression.ZlibWrapper) SnappyFrameDecoder(io.netty.handler.codec.compression.SnappyFrameDecoder) Maps(com.google.common.collect.Maps) Epoll(io.netty.channel.epoll.Epoll) Channel(io.netty.channel.Channel) TimeUnit(java.util.concurrent.TimeUnit) Bootstrap(io.netty.bootstrap.Bootstrap) AtomicLong(java.util.concurrent.atomic.AtomicLong) SslProvider(io.netty.handler.ssl.SslProvider) SimpleChannelInboundHandler(io.netty.channel.SimpleChannelInboundHandler) OrderedFuture(io.atomix.utils.concurrent.OrderedFuture) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) SslContextBuilder(io.netty.handler.ssl.SslContextBuilder) MessagingException(io.atomix.cluster.messaging.MessagingException) Future(io.netty.util.concurrent.Future) Address(io.atomix.utils.net.Address) InetAddress(java.net.InetAddress)

Example 92 with Future

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));
}
Also used : HttpHeaderValues(io.netty.handler.codec.http.HttpHeaderValues) REQUEST_ID(io.helidon.webclient.WebClientRequestBuilderImpl.REQUEST_ID) DataChunk(io.helidon.common.http.DataChunk) Set(java.util.Set) HttpMethod(io.netty.handler.codec.http.HttpMethod) GenericFutureListener(io.netty.util.concurrent.GenericFutureListener) CompletableFuture(java.util.concurrent.CompletableFuture) Logger(java.util.logging.Logger) Unpooled(io.netty.buffer.Unpooled) LastHttpContent(io.netty.handler.codec.http.LastHttpContent) Channel(io.netty.channel.Channel) DefaultHttpContent(io.netty.handler.codec.http.DefaultHttpContent) DefaultHttpRequest(io.netty.handler.codec.http.DefaultHttpRequest) DefaultLastHttpContent(io.netty.handler.codec.http.DefaultLastHttpContent) Flow(java.util.concurrent.Flow) ChannelFutureListener(io.netty.channel.ChannelFutureListener) HttpHeaderNames(io.netty.handler.codec.http.HttpHeaderNames) Http(io.helidon.common.http.Http) Future(io.netty.util.concurrent.Future) HttpUtil(io.netty.handler.codec.http.HttpUtil) DefaultHttpContent(io.netty.handler.codec.http.DefaultHttpContent)

Example 93 with Future

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;
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) Future(io.netty.util.concurrent.Future) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup)

Example 94 with Future

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();
        }
    }
}
Also used : ThePacket(sonoyuncu.impl.event.ThePacket) ChannelFuture(io.netty.channel.ChannelFuture) Future(io.netty.util.concurrent.Future) GenericFutureListener(io.netty.util.concurrent.GenericFutureListener)

Example 95 with Future

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());
                }
            }
        });
    }
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) LoggingHandler(io.netty.handler.logging.LoggingHandler) LocalAddress(io.netty.channel.local.LocalAddress) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) DefaultThreadFactory(io.netty.util.concurrent.DefaultThreadFactory) ChannelFuture(io.netty.channel.ChannelFuture) CompletableFuture(io.termd.core.util.CompletableFuture) Future(io.netty.util.concurrent.Future) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup)

Aggregations

Future (io.netty.util.concurrent.Future)177 Channel (io.netty.channel.Channel)61 ChannelFuture (io.netty.channel.ChannelFuture)58 InetSocketAddress (java.net.InetSocketAddress)45 ArrayList (java.util.ArrayList)45 IOException (java.io.IOException)44 GenericFutureListener (io.netty.util.concurrent.GenericFutureListener)42 CompletableFuture (java.util.concurrent.CompletableFuture)40 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)35 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)34 List (java.util.List)34 ChannelFutureListener (io.netty.channel.ChannelFutureListener)31 EventLoopGroup (io.netty.channel.EventLoopGroup)30 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)30 FutureListener (io.netty.util.concurrent.FutureListener)28 Logger (org.slf4j.Logger)28 LoggerFactory (org.slf4j.LoggerFactory)28 TimeUnit (java.util.concurrent.TimeUnit)27 Bootstrap (io.netty.bootstrap.Bootstrap)25 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)25