Search in sources :

Example 11 with ChannelInitializer

use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelInitializer in project java by wavefrontHQ.

the class PushAgent method startOpenTsdbListener.

protected void startOpenTsdbListener(final String strPort) {
    if (prefix != null && !prefix.isEmpty()) {
        preprocessors.forPort(strPort).forReportPoint().addTransformer(new ReportPointAddPrefixTransformer(prefix));
    }
    preprocessors.forPort(strPort).forReportPoint().addFilter(new ReportPointTimestampInRangeFilter(dataBackfillCutoffHours, dataPrefillCutoffHours));
    final int port = Integer.parseInt(strPort);
    final PostPushDataTimedTask[] flushTasks = getFlushTasks(strPort);
    ChannelInitializer initializer = new ChannelInitializer<SocketChannel>() {

        @Override
        public void initChannel(SocketChannel ch) throws Exception {
            final ChannelHandler handler = new OpenTSDBPortUnificationHandler(new OpenTSDBDecoder("unknown", customSourceTags), new PointHandlerImpl(strPort, pushValidationLevel, pushBlockedSamples, flushTasks), preprocessors.forPort(strPort));
            ChannelPipeline pipeline = ch.pipeline();
            pipeline.addLast(new PlainTextOrHttpFrameDecoder(handler));
        }
    };
    startAsManagedThread(new TcpIngester(initializer, port).withChildChannelOptions(childChannelOptions), "listener-plaintext-opentsdb-" + port);
}
Also used : SocketChannel(io.netty.channel.socket.SocketChannel) QueuingChannelHandler(com.wavefront.agent.histogram.QueuingChannelHandler) ChannelHandler(io.netty.channel.ChannelHandler) ChannelPipeline(io.netty.channel.ChannelPipeline) ReportPointAddPrefixTransformer(com.wavefront.agent.preprocessor.ReportPointAddPrefixTransformer) ReportPointTimestampInRangeFilter(com.wavefront.agent.preprocessor.ReportPointTimestampInRangeFilter) ChannelInitializer(io.netty.channel.ChannelInitializer) OpenTSDBDecoder(com.wavefront.ingester.OpenTSDBDecoder) TcpIngester(com.wavefront.ingester.TcpIngester)

Example 12 with ChannelInitializer

use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelInitializer in project jackrabbit-oak by apache.

the class ForwardHandler method channelActive.

@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
    group = new NioEventLoopGroup(0, r -> {
        return new Thread(r, String.format("forward-handler-%d", threadNumber.getAndIncrement()));
    });
    Bootstrap b = new Bootstrap().group(group).channel(NioSocketChannel.class).handler(new ChannelInitializer<SocketChannel>() {

        @Override
        public void initChannel(SocketChannel ch) throws Exception {
            if (flipPosition >= 0) {
                ch.pipeline().addLast(new FlipHandler(flipPosition));
            }
            if (skipBytes > 0) {
                ch.pipeline().addLast(new SkipHandler(skipPosition, skipBytes));
            }
            ch.pipeline().addLast(new BackwardHandler(ctx.channel()));
        }
    });
    remote = b.connect(targetHost, targetPort).sync().channel();
}
Also used : NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) EventLoopGroup(io.netty.channel.EventLoopGroup) Logger(org.slf4j.Logger) ChannelInitializer(io.netty.channel.ChannelInitializer) ChannelInboundHandlerAdapter(io.netty.channel.ChannelInboundHandlerAdapter) LoggerFactory(org.slf4j.LoggerFactory) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) TimeUnit(java.util.concurrent.TimeUnit) Channel(io.netty.channel.Channel) Bootstrap(io.netty.bootstrap.Bootstrap) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SocketChannel(io.netty.channel.socket.SocketChannel) NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) SocketChannel(io.netty.channel.socket.SocketChannel) Bootstrap(io.netty.bootstrap.Bootstrap) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup)

Example 13 with ChannelInitializer

use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelInitializer in project jocean-http by isdom.

the class Nettys4Test method createLocalConnection4Http.

public static Pair<Channel, Channel> createLocalConnection4Http(final String addr) throws Exception {
    final BlockingQueue<Channel> serverChannels = new ArrayBlockingQueue<Channel>(1);
    final Bootstrap clientbootstrap = new Bootstrap().group(Nettys4Test.EVENTLOOP4CLIENT).channel(LocalChannel.class).handler(new ChannelInitializer<Channel>() {

        @Override
        protected void initChannel(final Channel ch) throws Exception {
            Nettys.applyHandler(ch.pipeline(), HttpHandlers.LOGGING);
            Nettys.applyHandler(ch.pipeline(), HttpHandlers.HTTPCLIENT);
        }
    }).remoteAddress(new LocalAddress(addr));
    final Channel acceptorChannel = new ServerBootstrap().group(EVENTLOOP4BOSS, EVENTLOOP4SERVER).channel(LocalServerChannel.class).childHandler(new ChannelInitializer<Channel>() {

        @Override
        protected void initChannel(final Channel ch) throws Exception {
            Nettys.applyHandler(ch.pipeline(), HttpHandlers.LOGGING);
            Nettys.applyHandler(ch.pipeline(), HttpHandlers.HTTPSERVER);
            serverChannels.offer(ch);
        }
    }).localAddress(new LocalAddress(addr)).bind().sync().channel();
    try {
        final Channel client = clientbootstrap.connect().sync().channel();
        final Channel server = serverChannels.take();
        return Pair.of(client, server);
    } finally {
        acceptorChannel.close().sync();
    }
}
Also used : LocalAddress(io.netty.channel.local.LocalAddress) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) LocalServerChannel(io.netty.channel.local.LocalServerChannel) LocalServerChannel(io.netty.channel.local.LocalServerChannel) LocalChannel(io.netty.channel.local.LocalChannel) Channel(io.netty.channel.Channel) Bootstrap(io.netty.bootstrap.Bootstrap) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) ChannelInitializer(io.netty.channel.ChannelInitializer) ServerBootstrap(io.netty.bootstrap.ServerBootstrap)

Example 14 with ChannelInitializer

use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelInitializer in project LogHub by fbacchella.

the class ClientFactory method addHandlers.

@Override
public void addHandlers(ChannelConsumer<Bootstrap, Channel, SA> source) {
    ChannelHandler handler = new ChannelInitializer<CC>() {

        @Override
        public void initChannel(CC ch) throws Exception {
            try {
                source.addHandlers(ch.pipeline());
            } catch (Exception e) {
                logger.error("Netty handler failed: {}", e.getMessage());
                logger.throwing(Level.DEBUG, e);
            }
        }
    };
    bootstrap.handler(handler);
}
Also used : ChannelHandler(io.netty.channel.ChannelHandler) ChannelInitializer(io.netty.channel.ChannelInitializer)

Example 15 with ChannelInitializer

use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelInitializer in project bgpcep by opendaylight.

the class PCCDispatcherImpl method createClient.

@Override
@SuppressWarnings("unchecked")
public Future<PCEPSession> createClient(final InetSocketAddress remoteAddress, final long reconnectTime, final PCEPSessionListenerFactory listenerFactory, final PCEPSessionNegotiatorFactory negotiatorFactory, final KeyMapping keys, final InetSocketAddress localAddress, final BigInteger dbVersion) {
    final Bootstrap b = new Bootstrap();
    b.group(this.workerGroup);
    b.localAddress(localAddress);
    setChannelFactory(b, keys);
    b.option(ChannelOption.SO_KEEPALIVE, true);
    b.option(ChannelOption.SO_REUSEADDR, true);
    b.option(ChannelOption.RCVBUF_ALLOCATOR, new io.netty.channel.FixedRecvByteBufAllocator(1));
    final long retryTimer = reconnectTime == -1 ? 0 : reconnectTime;
    final PCCReconnectPromise promise = new PCCReconnectPromise(remoteAddress, (int) retryTimer, CONNECT_TIMEOUT, b);
    final ChannelInitializer<SocketChannel> channelInitializer = new ChannelInitializer<SocketChannel>() {

        @Override
        protected void initChannel(final SocketChannel ch) {
            ch.pipeline().addLast(PCCDispatcherImpl.this.factory.getDecoders());
            ch.pipeline().addLast("negotiator", negotiatorFactory.getSessionNegotiator(new PCEPSessionNegotiatorFactoryDependencies() {

                @Override
                public PCEPSessionListenerFactory getListenerFactory() {
                    return listenerFactory;
                }

                @Override
                public PCEPPeerProposal getPeerProposal() {
                    return new PCCPeerProposal(dbVersion);
                }
            }, ch, promise));
            ch.pipeline().addLast(PCCDispatcherImpl.this.factory.getEncoders());
            ch.pipeline().addLast(new ChannelInboundHandlerAdapter() {

                @Override
                public void channelInactive(final ChannelHandlerContext ctx) {
                    if (promise.isCancelled()) {
                        return;
                    }
                    if (!promise.isInitialConnectFinished()) {
                        LOG.debug("Connection to {} was dropped during negotiation, reattempting", remoteAddress);
                        return;
                    }
                    LOG.debug("Reconnecting after connection to {} was dropped", remoteAddress);
                    PCCDispatcherImpl.this.createClient(remoteAddress, reconnectTime, listenerFactory, negotiatorFactory, keys, localAddress, dbVersion);
                }
            });
        }
    };
    b.handler(channelInitializer);
    promise.connect();
    return promise;
}
Also used : NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) EpollSocketChannel(io.netty.channel.epoll.EpollSocketChannel) SocketChannel(io.netty.channel.socket.SocketChannel) PCEPSessionNegotiatorFactoryDependencies(org.opendaylight.protocol.pcep.PCEPSessionNegotiatorFactoryDependencies) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) Bootstrap(io.netty.bootstrap.Bootstrap) ChannelInitializer(io.netty.channel.ChannelInitializer) ChannelInboundHandlerAdapter(io.netty.channel.ChannelInboundHandlerAdapter)

Aggregations

ChannelInitializer (io.netty.channel.ChannelInitializer)85 Channel (io.netty.channel.Channel)58 Bootstrap (io.netty.bootstrap.Bootstrap)42 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)39 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)36 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)32 InetSocketAddress (java.net.InetSocketAddress)32 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)31 ChannelFuture (io.netty.channel.ChannelFuture)29 ChannelPipeline (io.netty.channel.ChannelPipeline)26 EventLoopGroup (io.netty.channel.EventLoopGroup)26 LocalServerChannel (io.netty.channel.local.LocalServerChannel)21 NioServerSocketChannel (io.netty.channel.socket.nio.NioServerSocketChannel)21 LocalChannel (io.netty.channel.local.LocalChannel)20 SocketChannel (io.netty.channel.socket.SocketChannel)18 ChannelInboundHandlerAdapter (io.netty.channel.ChannelInboundHandlerAdapter)17 SslHandler (io.netty.handler.ssl.SslHandler)17 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)14 CountDownLatch (java.util.concurrent.CountDownLatch)12 ChannelHandler (io.netty.channel.ChannelHandler)11