Search in sources :

Example 16 with ChannelHandler

use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandler 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 17 with ChannelHandler

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

the class PushAgent method startCustomListener.

/**
 * Registers a custom point handler on a particular port.
 *
 * @param strPort      The port to listen on.
 * @param decoder      The decoder to use.
 * @param pointHandler The handler to handle parsed ReportPoints.
 * @param preprocessor Pre-processor (predicates and transform functions) for every point
 */
protected void startCustomListener(String strPort, Decoder<String> decoder, PointHandler pointHandler, @Nullable PointPreprocessor preprocessor) {
    int port = Integer.parseInt(strPort);
    ChannelHandler channelHandler = new ChannelStringHandler(decoder, pointHandler, preprocessor);
    startAsManagedThread(new StringLineIngester(channelHandler, port).withChildChannelOptions(childChannelOptions), null);
}
Also used : StringLineIngester(com.wavefront.ingester.StringLineIngester) QueuingChannelHandler(com.wavefront.agent.histogram.QueuingChannelHandler) ChannelHandler(io.netty.channel.ChannelHandler)

Example 18 with ChannelHandler

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

the class BGPDispatcherImpl method createServerBootstrap.

private synchronized ServerBootstrap createServerBootstrap(final ChannelPipelineInitializer initializer) {
    final ServerBootstrap serverBootstrap = new ServerBootstrap();
    if (Epoll.isAvailable()) {
        serverBootstrap.channel(EpollServerSocketChannel.class);
        serverBootstrap.childOption(EpollChannelOption.EPOLL_MODE, EpollMode.LEVEL_TRIGGERED);
    } else {
        serverBootstrap.channel(NioServerSocketChannel.class);
    }
    final ChannelHandler serverChannelHandler = BGPChannel.createServerChannelHandler(initializer);
    serverBootstrap.childHandler(serverChannelHandler);
    serverBootstrap.option(ChannelOption.SO_BACKLOG, SOCKET_BACKLOG_SIZE);
    serverBootstrap.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
    serverBootstrap.childOption(ChannelOption.WRITE_BUFFER_WATER_MARK, WATER_MARK);
    // Make sure we are doing round-robin processing
    serverBootstrap.option(ChannelOption.RCVBUF_ALLOCATOR, new FixedRecvByteBufAllocator(FIX_BUFFER_SIZE));
    if (serverBootstrap.config().group() == null) {
        serverBootstrap.group(this.bossGroup, this.workerGroup);
    }
    return serverBootstrap;
}
Also used : FixedRecvByteBufAllocator(io.netty.channel.FixedRecvByteBufAllocator) ChannelHandler(io.netty.channel.ChannelHandler) ServerBootstrap(io.netty.bootstrap.ServerBootstrap)

Example 19 with ChannelHandler

use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandler in project incubator-pulsar by apache.

the class ClientCnx method verifyTlsHostName.

/**
 * verifies host name provided in x509 Certificate in tls session
 *
 * it matches hostname with below scenarios
 *
 * <pre>
 *  1. Supports IPV4 and IPV6 host matching
 *  2. Supports wild card matching for DNS-name
 *  eg:
 *     HostName                     CN           Result
 * 1.  localhost                    localhost    PASS
 * 2.  localhost                    local*       PASS
 * 3.  pulsar1-broker.com           pulsar*.com  PASS
 * </pre>
 *
 * @param ctx
 * @return true if hostname is verified else return false
 */
private boolean verifyTlsHostName(String hostname, ChannelHandlerContext ctx) {
    ChannelHandler sslHandler = ctx.channel().pipeline().get("tls");
    SSLSession sslSession = null;
    if (sslHandler != null) {
        sslSession = ((SslHandler) sslHandler).engine().getSession();
        if (log.isDebugEnabled()) {
            log.debug("Verifying HostName for {}, Cipher {}, Protocols {}", hostname, sslSession.getCipherSuite(), sslSession.getProtocol());
        }
        return hostnameVerifier.verify(hostname, sslSession);
    }
    return false;
}
Also used : SSLSession(javax.net.ssl.SSLSession) ChannelHandler(io.netty.channel.ChannelHandler) SslHandler(io.netty.handler.ssl.SslHandler)

Example 20 with ChannelHandler

use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandler in project java-driver by datastax.

the class NettyOptionsTest method should_invoke_netty_options_hooks.

private void should_invoke_netty_options_hooks(int hosts, int coreConnections) throws Exception {
    NettyOptions nettyOptions = mock(NettyOptions.class, CALLS_REAL_METHODS.get());
    EventLoopGroup eventLoopGroup = new NioEventLoopGroup();
    Timer timer = new HashedWheelTimer();
    doReturn(eventLoopGroup).when(nettyOptions).eventLoopGroup(any(ThreadFactory.class));
    doReturn(timer).when(nettyOptions).timer(any(ThreadFactory.class));
    final ChannelHandler handler = mock(ChannelHandler.class);
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            SocketChannel channel = (SocketChannel) invocation.getArguments()[0];
            channel.pipeline().addLast("test-handler", handler);
            return null;
        }
    }).when(nettyOptions).afterChannelInitialized(any(SocketChannel.class));
    Cluster cluster = register(Cluster.builder().addContactPoints(getContactPoints().get(0)).withPort(ccm().getBinaryPort()).withPoolingOptions(new PoolingOptions().setConnectionsPerHost(HostDistance.LOCAL, coreConnections, coreConnections)).withNettyOptions(nettyOptions).build());
    // when
    // force session creation to populate pools
    cluster.connect();
    int expectedNumberOfCalls = TestUtils.numberOfLocalCoreConnections(cluster) * hosts + 1;
    // If the driver supports a more recent protocol version than C*, the negotiation at startup
    // will open an additional connection for each protocol version tried.
    ProtocolVersion version = ProtocolVersion.NEWEST_SUPPORTED;
    ProtocolVersion usedVersion = ccm().getProtocolVersion();
    while (version != usedVersion && version != null) {
        version = version.getLowerSupported();
        expectedNumberOfCalls++;
    }
    cluster.close();
    // then
    verify(nettyOptions, times(1)).eventLoopGroup(any(ThreadFactory.class));
    verify(nettyOptions, times(1)).channelClass();
    verify(nettyOptions, times(1)).timer(any(ThreadFactory.class));
    // per-connection hooks will be called coreConnections * hosts + 1 times:
    // the extra call is for the control connection
    verify(nettyOptions, times(expectedNumberOfCalls)).afterBootstrapInitialized(any(Bootstrap.class));
    verify(nettyOptions, times(expectedNumberOfCalls)).afterChannelInitialized(any(SocketChannel.class));
    verify(handler, times(expectedNumberOfCalls)).handlerAdded(any(ChannelHandlerContext.class));
    verify(handler, times(expectedNumberOfCalls)).handlerRemoved(any(ChannelHandlerContext.class));
    verify(nettyOptions, times(1)).onClusterClose(eventLoopGroup);
    verify(nettyOptions, times(1)).onClusterClose(timer);
    verifyNoMoreInteractions(nettyOptions);
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) SocketChannel(io.netty.channel.socket.SocketChannel) HashedWheelTimer(io.netty.util.HashedWheelTimer) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) ChannelHandler(io.netty.channel.ChannelHandler) Answer(org.mockito.stubbing.Answer) EventLoopGroup(io.netty.channel.EventLoopGroup) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) HashedWheelTimer(io.netty.util.HashedWheelTimer) Timer(io.netty.util.Timer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Bootstrap(io.netty.bootstrap.Bootstrap) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup)

Aggregations

ChannelHandler (io.netty.channel.ChannelHandler)216 Test (org.junit.Test)88 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)44 Channel (io.netty.channel.Channel)27 ChannelPipeline (io.netty.channel.ChannelPipeline)26 SslHandler (io.netty.handler.ssl.SslHandler)25 Test (org.junit.jupiter.api.Test)24 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)23 ChannelInboundHandlerAdapter (io.netty.channel.ChannelInboundHandlerAdapter)21 FilterChainMatchingHandler (io.grpc.xds.FilterChainMatchingProtocolNegotiators.FilterChainMatchingHandler)20 ChannelFuture (io.netty.channel.ChannelFuture)20 FilterChainSelector (io.grpc.xds.FilterChainMatchingProtocolNegotiators.FilterChainMatchingHandler.FilterChainSelector)19 ChannelHandlerAdapter (io.netty.channel.ChannelHandlerAdapter)18 InetSocketAddress (java.net.InetSocketAddress)18 DownstreamTlsContext (io.grpc.xds.EnvoyServerProtoData.DownstreamTlsContext)17 FilterChain (io.grpc.xds.EnvoyServerProtoData.FilterChain)17 LineBasedFrameDecoder (io.netty.handler.codec.LineBasedFrameDecoder)16 AtomicReference (java.util.concurrent.atomic.AtomicReference)16 TcpIngester (com.wavefront.ingester.TcpIngester)15 ByteBuf (io.netty.buffer.ByteBuf)13