Search in sources :

Example 41 with ChannelHandler

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

the class Http2MultiplexTest method setUp.

@BeforeEach
public void setUp() {
    childChannelInitializer = new TestChannelInitializer();
    parentChannel = new EmbeddedChannel();
    frameInboundWriter = new Http2FrameInboundWriter(parentChannel);
    parentChannel.connect(new InetSocketAddress(0));
    frameWriter = Http2TestUtil.mockedFrameWriter();
    codec = newCodec(childChannelInitializer, frameWriter);
    parentChannel.pipeline().addLast(codec);
    ChannelHandler multiplexer = newMultiplexer(childChannelInitializer);
    if (multiplexer != null) {
        parentChannel.pipeline().addLast(multiplexer);
    }
    parentChannel.runPendingTasks();
    parentChannel.pipeline().fireChannelActive();
    parentChannel.writeInbound(Http2CodecUtil.connectionPrefaceBuf());
    Http2Settings settings = new Http2Settings().initialWindowSize(initialRemoteStreamWindow);
    frameInboundWriter.writeInboundSettings(settings);
    verify(frameWriter).writeSettingsAck(eqCodecCtx(), anyChannelPromise());
    frameInboundWriter.writeInboundSettingsAck();
    Http2SettingsFrame settingsFrame = parentChannel.readInbound();
    assertNotNull(settingsFrame);
    Http2SettingsAckFrame settingsAckFrame = parentChannel.readInbound();
    assertNotNull(settingsAckFrame);
    // Handshake
    verify(frameWriter).writeSettings(eqCodecCtx(), anyHttp2Settings(), anyChannelPromise());
}
Also used : InetSocketAddress(java.net.InetSocketAddress) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) ChannelHandler(io.netty.channel.ChannelHandler) Http2TestUtil.anyHttp2Settings(io.netty.handler.codec.http2.Http2TestUtil.anyHttp2Settings) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 42 with ChannelHandler

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

the class Http2StreamChannelBootstrap method init.

private void init(Channel channel) {
    ChannelPipeline p = channel.pipeline();
    ChannelHandler handler = this.handler;
    if (handler != null) {
        p.addLast(handler);
    }
    final Map.Entry<ChannelOption<?>, Object>[] optionArray;
    synchronized (options) {
        optionArray = options.entrySet().toArray(EMPTY_OPTION_ARRAY);
    }
    setChannelOptions(channel, optionArray);
    setAttributes(channel, attrs.entrySet().toArray(EMPTY_ATTRIBUTE_ARRAY));
}
Also used : ChannelHandler(io.netty.channel.ChannelHandler) ChannelPipeline(io.netty.channel.ChannelPipeline)

Example 43 with ChannelHandler

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

the class ServerBootstrap method init.

@Override
void init(Channel channel) {
    setChannelOptions(channel, newOptionsArray(), logger);
    setAttributes(channel, newAttributesArray());
    ChannelPipeline p = channel.pipeline();
    final EventLoopGroup currentChildGroup = childGroup;
    final ChannelHandler currentChildHandler = childHandler;
    final Entry<ChannelOption<?>, Object>[] currentChildOptions = newOptionsArray(childOptions);
    final Entry<AttributeKey<?>, Object>[] currentChildAttrs = newAttributesArray(childAttrs);
    p.addLast(new ChannelInitializer<Channel>() {

        @Override
        public void initChannel(final Channel ch) {
            final ChannelPipeline pipeline = ch.pipeline();
            ChannelHandler handler = config.handler();
            if (handler != null) {
                pipeline.addLast(handler);
            }
            ch.eventLoop().execute(new Runnable() {

                @Override
                public void run() {
                    pipeline.addLast(new ServerBootstrapAcceptor(ch, currentChildGroup, currentChildHandler, currentChildOptions, currentChildAttrs));
                }
            });
        }
    });
}
Also used : Entry(java.util.Map.Entry) EventLoopGroup(io.netty.channel.EventLoopGroup) ServerChannel(io.netty.channel.ServerChannel) Channel(io.netty.channel.Channel) ChannelHandler(io.netty.channel.ChannelHandler) ChannelPipeline(io.netty.channel.ChannelPipeline)

Example 44 with ChannelHandler

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

the class UdtNetty method main.

public static void main(final String[] args) throws Exception {
    log.info("init");
    TrafficControl.delay(0);
    final AtomicBoolean isOn = new AtomicBoolean(true);
    final InetSocketAddress addr1 = UnitHelp.localSocketAddress();
    final InetSocketAddress addr2 = UnitHelp.localSocketAddress();
    final ChannelHandler handler1 = new EchoMessageHandler(rate, size);
    final ChannelHandler handler2 = new EchoMessageHandler(null, size);
    final NioEventLoopGroup group1 = new NioEventLoopGroup(1, Executors.defaultThreadFactory(), NioUdtProvider.MESSAGE_PROVIDER);
    final NioEventLoopGroup group2 = new NioEventLoopGroup(1, Executors.defaultThreadFactory(), NioUdtProvider.MESSAGE_PROVIDER);
    final Bootstrap peerBoot1 = new Bootstrap();
    peerBoot1.group(group1).channelFactory(NioUdtProvider.MESSAGE_RENDEZVOUS).localAddress(addr1).remoteAddress(addr2).handler(handler1);
    final Bootstrap peerBoot2 = new Bootstrap();
    peerBoot2.group(group2).channelFactory(NioUdtProvider.MESSAGE_RENDEZVOUS).localAddress(addr2).remoteAddress(addr1).handler(handler2);
    final ChannelFuture peerFuture1 = peerBoot1.connect();
    final ChannelFuture peerFuture2 = peerBoot2.connect();
    CustomReporter.enable(3, TimeUnit.SECONDS);
    Thread.sleep(time);
    isOn.set(false);
    Thread.sleep(1000);
    peerFuture1.channel().close().sync();
    peerFuture2.channel().close().sync();
    Thread.sleep(1000);
    group1.shutdownGracefully();
    group2.shutdownGracefully();
    Metrics.defaultRegistry().shutdown();
    TrafficControl.delay(0);
    log.info("done");
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) InetSocketAddress(java.net.InetSocketAddress) EchoMessageHandler(io.netty.test.udt.util.EchoMessageHandler) Bootstrap(io.netty.bootstrap.Bootstrap) ChannelHandler(io.netty.channel.ChannelHandler) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup)

Example 45 with ChannelHandler

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

the class AbstractBootstrapConfig method toString.

@Override
public String toString() {
    StringBuilder buf = new StringBuilder().append(StringUtil.simpleClassName(this)).append('(');
    EventLoopGroup group = group();
    if (group != null) {
        buf.append("group: ").append(StringUtil.simpleClassName(group)).append(", ");
    }
    @SuppressWarnings("deprecation") ChannelFactory<? extends C> factory = channelFactory();
    if (factory != null) {
        buf.append("channelFactory: ").append(factory).append(", ");
    }
    SocketAddress localAddress = localAddress();
    if (localAddress != null) {
        buf.append("localAddress: ").append(localAddress).append(", ");
    }
    Map<ChannelOption<?>, Object> options = options();
    if (!options.isEmpty()) {
        buf.append("options: ").append(options).append(", ");
    }
    Map<AttributeKey<?>, Object> attrs = attrs();
    if (!attrs.isEmpty()) {
        buf.append("attrs: ").append(attrs).append(", ");
    }
    ChannelHandler handler = handler();
    if (handler != null) {
        buf.append("handler: ").append(handler).append(", ");
    }
    if (buf.charAt(buf.length() - 1) == '(') {
        buf.append(')');
    } else {
        buf.setCharAt(buf.length() - 2, ')');
        buf.setLength(buf.length() - 1);
    }
    return buf.toString();
}
Also used : AttributeKey(io.netty.util.AttributeKey) EventLoopGroup(io.netty.channel.EventLoopGroup) ChannelOption(io.netty.channel.ChannelOption) ChannelHandler(io.netty.channel.ChannelHandler) SocketAddress(java.net.SocketAddress)

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