Search in sources :

Example 26 with LengthFieldBasedFrameDecoder

use of io.netty.handler.codec.LengthFieldBasedFrameDecoder in project iris by chicc999.

the class NettyTransport method handler.

protected ChannelHandler handler() {
    return new ChannelInitializer() {

        @Override
        protected void initChannel(Channel ch) throws Exception {
            ch.pipeline().addLast(new LengthFieldBasedFrameDecoder(config.getFrameMaxSize(), 0, 4, 0, 4));
            ch.pipeline().addLast(new CommandDecoder());
            ch.pipeline().addLast(new CommandEncoder());
            ch.pipeline().addLast(new IdleStateHandler(0, 0, config.getChannelMaxIdleTime(), TimeUnit.MILLISECONDS));
            ch.pipeline().addLast(dispatcherHandler);
            ch.pipeline().addLast(connectionHandler);
        }
    };
}
Also used : CommandDecoder(pers.cy.iris.commons.network.protocol.CommandDecoder) IdleStateHandler(io.netty.handler.timeout.IdleStateHandler) CommandEncoder(pers.cy.iris.commons.network.protocol.CommandEncoder) LengthFieldBasedFrameDecoder(io.netty.handler.codec.LengthFieldBasedFrameDecoder)

Example 27 with LengthFieldBasedFrameDecoder

use of io.netty.handler.codec.LengthFieldBasedFrameDecoder in project netty by netty.

the class LengthFieldBasedFrameDecoderTest method testFailFastTooLongFrameRecovery.

@Test
public void testFailFastTooLongFrameRecovery() throws Exception {
    EmbeddedChannel ch = new EmbeddedChannel(new LengthFieldBasedFrameDecoder(5, 0, 4, 0, 4));
    for (int i = 0; i < 2; i++) {
        try {
            assertTrue(ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { 0, 0, 0, 2 })));
            fail(DecoderException.class.getSimpleName() + " must be raised.");
        } catch (TooLongFrameException e) {
        // Expected
        }
        ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { 0, 0, 0, 0, 0, 1, 'A' }));
        ByteBuf buf = ch.readInbound();
        assertEquals("A", buf.toString(CharsetUtil.ISO_8859_1));
        buf.release();
    }
}
Also used : TooLongFrameException(io.netty.handler.codec.TooLongFrameException) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) ByteBuf(io.netty.buffer.ByteBuf) LengthFieldBasedFrameDecoder(io.netty.handler.codec.LengthFieldBasedFrameDecoder) Test(org.junit.jupiter.api.Test)

Example 28 with LengthFieldBasedFrameDecoder

use of io.netty.handler.codec.LengthFieldBasedFrameDecoder in project zipkin by openzipkin.

the class NettyScribeServer method start.

void start() {
    bossGroup = EventLoopGroups.newEventLoopGroup(1);
    EventLoopGroup workerGroup = CommonPools.workerGroup();
    ServerBootstrap b = new ServerBootstrap();
    try {
        channel = b.group(bossGroup, workerGroup).channel(EventLoopGroups.serverChannelType(bossGroup)).childHandler(new ChannelInitializer<SocketChannel>() {

            @Override
            protected void initChannel(SocketChannel ch) {
                ch.pipeline().addLast(new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4, 0, 4)).addLast(new ScribeInboundHandler(scribe));
            }
        }).bind(port).syncUninterruptibly().channel();
    } catch (Throwable t) {
        propagateIfFatal(t);
        throw new RuntimeException("Could not start scribe server.", t);
    }
}
Also used : SocketChannel(io.netty.channel.socket.SocketChannel) EventLoopGroup(io.netty.channel.EventLoopGroup) LengthFieldBasedFrameDecoder(io.netty.handler.codec.LengthFieldBasedFrameDecoder) ServerBootstrap(io.netty.bootstrap.ServerBootstrap)

Example 29 with LengthFieldBasedFrameDecoder

use of io.netty.handler.codec.LengthFieldBasedFrameDecoder in project pravega by pravega.

the class AdminConnectionListener method createEncodingStack.

@Override
public List<ChannelHandler> createEncodingStack(String connectionName) {
    List<ChannelHandler> stack = new ArrayList<>();
    stack.add(new ExceptionLoggingHandler(connectionName));
    stack.add(new CommandEncoder(null, NO_OP_METRIC_NOTIFIER));
    stack.add(new LengthFieldBasedFrameDecoder(MAX_WIRECOMMAND_SIZE, 4, 4));
    stack.add(new CommandDecoder());
    return stack;
}
Also used : CommandDecoder(io.pravega.shared.protocol.netty.CommandDecoder) ExceptionLoggingHandler(io.pravega.shared.protocol.netty.ExceptionLoggingHandler) ArrayList(java.util.ArrayList) ChannelHandler(io.netty.channel.ChannelHandler) CommandEncoder(io.pravega.shared.protocol.netty.CommandEncoder) LengthFieldBasedFrameDecoder(io.netty.handler.codec.LengthFieldBasedFrameDecoder)

Example 30 with LengthFieldBasedFrameDecoder

use of io.netty.handler.codec.LengthFieldBasedFrameDecoder in project pravega by pravega.

the class AppendTest method createChannel.

static EmbeddedChannel createChannel(StreamSegmentStore store) {
    ServerConnectionInboundHandler lsh = new ServerConnectionInboundHandler();
    EmbeddedChannel channel = new EmbeddedChannel(new ExceptionLoggingHandler(""), new CommandEncoder(null, MetricNotifier.NO_OP_METRIC_NOTIFIER), new LengthFieldBasedFrameDecoder(MAX_WIRECOMMAND_SIZE, 4, 4), new CommandDecoder(), new AppendDecoder(), lsh);
    lsh.setRequestProcessor(AppendProcessor.defaultBuilder().store(store).connection(new TrackedConnection(lsh)).nextRequestProcessor(new PravegaRequestProcessor(store, mock(TableStore.class), lsh)).build());
    return channel;
}
Also used : AppendDecoder(io.pravega.shared.protocol.netty.AppendDecoder) CommandDecoder(io.pravega.shared.protocol.netty.CommandDecoder) ServerConnectionInboundHandler(io.pravega.segmentstore.server.host.handler.ServerConnectionInboundHandler) PravegaRequestProcessor(io.pravega.segmentstore.server.host.handler.PravegaRequestProcessor) ExceptionLoggingHandler(io.pravega.shared.protocol.netty.ExceptionLoggingHandler) TrackedConnection(io.pravega.segmentstore.server.host.handler.TrackedConnection) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) CommandEncoder(io.pravega.shared.protocol.netty.CommandEncoder) LengthFieldBasedFrameDecoder(io.netty.handler.codec.LengthFieldBasedFrameDecoder)

Aggregations

LengthFieldBasedFrameDecoder (io.netty.handler.codec.LengthFieldBasedFrameDecoder)68 SocketChannel (io.netty.channel.socket.SocketChannel)35 LengthFieldPrepender (io.netty.handler.codec.LengthFieldPrepender)35 ChannelPipeline (io.netty.channel.ChannelPipeline)30 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)25 Bootstrap (io.netty.bootstrap.Bootstrap)19 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)19 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)19 NioServerSocketChannel (io.netty.channel.socket.nio.NioServerSocketChannel)18 ChannelFuture (io.netty.channel.ChannelFuture)14 EventLoopGroup (io.netty.channel.EventLoopGroup)14 Channel (io.netty.channel.Channel)13 StringEncoder (io.netty.handler.codec.string.StringEncoder)13 StringDecoder (io.netty.handler.codec.string.StringDecoder)12 SslContext (io.netty.handler.ssl.SslContext)12 EpollEventLoopGroup (io.netty.channel.epoll.EpollEventLoopGroup)9 CommandDecoder (io.pravega.shared.protocol.netty.CommandDecoder)8 CommandEncoder (io.pravega.shared.protocol.netty.CommandEncoder)8 IOException (java.io.IOException)8 ExceptionLoggingHandler (io.pravega.shared.protocol.netty.ExceptionLoggingHandler)7