Search in sources :

Example 41 with LengthFieldBasedFrameDecoder

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

the class TerasologyServerPipelineFactory method initChannel.

@Override
protected void initChannel(Channel ch) throws Exception {
    ChannelPipeline p = ch.pipeline();
    p.addLast(MetricRecordingHandler.NAME, new MetricRecordingHandler());
    p.addLast("inflateDecoder", new Lz4FrameDecoder());
    p.addLast("lengthFrameDecoder", new LengthFieldBasedFrameDecoder(8388608, 0, 3, 0, 3));
    p.addLast("protobufDecoder", new ProtobufDecoder(NetData.NetMessage.getDefaultInstance()));
    p.addLast("deflateEncoder", new Lz4FrameEncoder(true));
    p.addLast("frameLengthEncoder", new LengthFieldPrepender(3));
    p.addLast("protobufEncoder", new ProtobufEncoder());
    p.addLast("authenticationHandler", new ServerHandshakeHandler());
    p.addLast("connectionHandler", new ServerConnectionHandler(networkSystem));
    p.addLast("handler", new ServerHandler(networkSystem));
}
Also used : Lz4FrameEncoder(io.netty.handler.codec.compression.Lz4FrameEncoder) ProtobufEncoder(io.netty.handler.codec.protobuf.ProtobufEncoder) ServerConnectionHandler(org.terasology.engine.network.internal.ServerConnectionHandler) ServerHandshakeHandler(org.terasology.engine.network.internal.ServerHandshakeHandler) MetricRecordingHandler(org.terasology.engine.network.internal.MetricRecordingHandler) ProtobufDecoder(io.netty.handler.codec.protobuf.ProtobufDecoder) ServerHandler(org.terasology.engine.network.internal.ServerHandler) LengthFieldPrepender(io.netty.handler.codec.LengthFieldPrepender) LengthFieldBasedFrameDecoder(io.netty.handler.codec.LengthFieldBasedFrameDecoder) ChannelPipeline(io.netty.channel.ChannelPipeline) Lz4FrameDecoder(io.netty.handler.codec.compression.Lz4FrameDecoder)

Example 42 with LengthFieldBasedFrameDecoder

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

the class CatchUpClientChannelPipeline method initChannel.

static void initChannel(SocketChannel ch, CatchUpResponseHandler handler, LogProvider logProvider, Monitors monitors) throws Exception {
    CatchupClientProtocol protocol = new CatchupClientProtocol();
    ChannelPipeline pipeline = ch.pipeline();
    pipeline.addLast(new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4, 0, 4));
    pipeline.addLast(new LengthFieldPrepender(4));
    pipeline.addLast(new VersionDecoder(logProvider));
    pipeline.addLast(new VersionPrepender());
    pipeline.addLast(new TxPullRequestEncoder());
    pipeline.addLast(new GetStoreRequestEncoder());
    pipeline.addLast(new CoreSnapshotRequestEncoder());
    pipeline.addLast(new GetStoreIdRequestEncoder());
    pipeline.addLast(new ResponseMessageTypeEncoder());
    pipeline.addLast(new RequestMessageTypeEncoder());
    pipeline.addLast(new ClientMessageTypeHandler(protocol, logProvider));
    RequestDecoderDispatcher<CatchupClientProtocol.State> decoderDispatcher = new RequestDecoderDispatcher<>(protocol, logProvider);
    decoderDispatcher.register(CatchupClientProtocol.State.STORE_ID, new GetStoreIdResponseDecoder());
    decoderDispatcher.register(CatchupClientProtocol.State.TX_PULL_RESPONSE, new TxPullResponseDecoder());
    decoderDispatcher.register(CatchupClientProtocol.State.CORE_SNAPSHOT, new CoreSnapshotDecoder());
    decoderDispatcher.register(CatchupClientProtocol.State.STORE_COPY_FINISHED, new StoreCopyFinishedResponseDecoder());
    decoderDispatcher.register(CatchupClientProtocol.State.TX_STREAM_FINISHED, new TxStreamFinishedResponseDecoder());
    decoderDispatcher.register(CatchupClientProtocol.State.FILE_HEADER, new FileHeaderDecoder());
    decoderDispatcher.register(CatchupClientProtocol.State.FILE_CONTENTS, new FileChunkDecoder());
    pipeline.addLast(decoderDispatcher);
    pipeline.addLast(new TxPullResponseHandler(protocol, handler));
    pipeline.addLast(new CoreSnapshotResponseHandler(protocol, handler));
    pipeline.addLast(new StoreCopyFinishedResponseHandler(protocol, handler));
    pipeline.addLast(new TxStreamFinishedResponseHandler(protocol, handler));
    pipeline.addLast(new FileHeaderHandler(protocol, handler, logProvider));
    pipeline.addLast(new FileChunkHandler(protocol, handler));
    pipeline.addLast(new GetStoreIdResponseHandler(protocol, handler));
    pipeline.addLast(new ExceptionLoggingHandler(logProvider.getLog(CatchUpClient.class)));
    pipeline.addLast(new ExceptionMonitoringHandler(monitors.newMonitor(ExceptionMonitoringHandler.Monitor.class, CatchUpClient.class)));
    pipeline.addLast(new ExceptionSwallowingHandler());
}
Also used : CoreSnapshotRequestEncoder(org.neo4j.causalclustering.core.state.snapshot.CoreSnapshotRequestEncoder) ExceptionSwallowingHandler(org.neo4j.causalclustering.handlers.ExceptionSwallowingHandler) VersionPrepender(org.neo4j.causalclustering.VersionPrepender) TxPullResponseDecoder(org.neo4j.causalclustering.catchup.tx.TxPullResponseDecoder) StoreCopyFinishedResponseDecoder(org.neo4j.causalclustering.catchup.storecopy.StoreCopyFinishedResponseDecoder) LengthFieldPrepender(io.netty.handler.codec.LengthFieldPrepender) ExceptionLoggingHandler(org.neo4j.causalclustering.handlers.ExceptionLoggingHandler) TxPullRequestEncoder(org.neo4j.causalclustering.catchup.tx.TxPullRequestEncoder) TxPullResponseHandler(org.neo4j.causalclustering.catchup.tx.TxPullResponseHandler) StoreCopyFinishedResponseHandler(org.neo4j.causalclustering.catchup.storecopy.StoreCopyFinishedResponseHandler) FileChunkDecoder(org.neo4j.causalclustering.catchup.storecopy.FileChunkDecoder) LengthFieldBasedFrameDecoder(io.netty.handler.codec.LengthFieldBasedFrameDecoder) GetStoreIdResponseDecoder(org.neo4j.causalclustering.catchup.storecopy.GetStoreIdResponseDecoder) GetStoreRequestEncoder(org.neo4j.causalclustering.catchup.storecopy.GetStoreRequestEncoder) CoreSnapshotDecoder(org.neo4j.causalclustering.core.state.snapshot.CoreSnapshotDecoder) FileHeaderHandler(org.neo4j.causalclustering.catchup.storecopy.FileHeaderHandler) VersionDecoder(org.neo4j.causalclustering.VersionDecoder) TxStreamFinishedResponseDecoder(org.neo4j.causalclustering.catchup.tx.TxStreamFinishedResponseDecoder) ChannelPipeline(io.netty.channel.ChannelPipeline) TxStreamFinishedResponseHandler(org.neo4j.causalclustering.catchup.tx.TxStreamFinishedResponseHandler) ExceptionMonitoringHandler(org.neo4j.causalclustering.handlers.ExceptionMonitoringHandler) FileHeaderDecoder(org.neo4j.causalclustering.catchup.storecopy.FileHeaderDecoder) GetStoreIdRequestEncoder(org.neo4j.causalclustering.catchup.storecopy.GetStoreIdRequestEncoder) GetStoreIdResponseHandler(org.neo4j.causalclustering.catchup.storecopy.GetStoreIdResponseHandler) CoreSnapshotResponseHandler(org.neo4j.causalclustering.core.state.snapshot.CoreSnapshotResponseHandler) FileChunkHandler(org.neo4j.causalclustering.catchup.storecopy.FileChunkHandler)

Example 43 with LengthFieldBasedFrameDecoder

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

the class RaftServer method startNettyServer.

private void startNettyServer() {
    workerGroup = new NioEventLoopGroup(0, threadFactory);
    log.info("Starting server at: " + listenAddress);
    ServerBootstrap bootstrap = new ServerBootstrap().group(workerGroup).channel(NioServerSocketChannel.class).option(ChannelOption.SO_REUSEADDR, true).localAddress(listenAddress.socketAddress()).childHandler(new ChannelInitializer<SocketChannel>() {

        @Override
        protected void initChannel(SocketChannel ch) throws Exception {
            ChannelPipeline pipeline = ch.pipeline();
            pipeline.addLast(new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4, 0, 4));
            pipeline.addLast(new LengthFieldPrepender(4));
            pipeline.addLast(new VersionDecoder(logProvider));
            pipeline.addLast(new VersionPrepender());
            pipeline.addLast(new RaftMessageDecoder(marshal));
            pipeline.addLast(new RaftMessageHandler());
            pipeline.addLast(new ExceptionLoggingHandler(log));
            pipeline.addLast(new ExceptionMonitoringHandler(monitors.newMonitor(ExceptionMonitoringHandler.Monitor.class, RaftServer.class)));
            pipeline.addLast(new ExceptionSwallowingHandler());
        }
    });
    try {
        channel = bootstrap.bind().syncUninterruptibly().channel();
    } catch (Exception e) {
        //noinspection ConstantConditions
        if (e instanceof BindException) {
            userLog.error("Address is already bound for setting: " + setting + " with value: " + listenAddress);
            log.error("Address is already bound for setting: " + setting + " with value: " + listenAddress, e);
            throw e;
        }
    }
}
Also used : SocketChannel(io.netty.channel.socket.SocketChannel) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) ExceptionSwallowingHandler(org.neo4j.causalclustering.handlers.ExceptionSwallowingHandler) VersionPrepender(org.neo4j.causalclustering.VersionPrepender) BindException(java.net.BindException) LengthFieldPrepender(io.netty.handler.codec.LengthFieldPrepender) VersionDecoder(org.neo4j.causalclustering.VersionDecoder) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) BindException(java.net.BindException) ChannelPipeline(io.netty.channel.ChannelPipeline) ExceptionMonitoringHandler(org.neo4j.causalclustering.handlers.ExceptionMonitoringHandler) RaftMessageDecoder(org.neo4j.causalclustering.messaging.marshalling.RaftMessageDecoder) ExceptionLoggingHandler(org.neo4j.causalclustering.handlers.ExceptionLoggingHandler) LengthFieldBasedFrameDecoder(io.netty.handler.codec.LengthFieldBasedFrameDecoder) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup)

Example 44 with LengthFieldBasedFrameDecoder

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

the class CatchupServer method start.

@Override
public synchronized void start() throws Throwable {
    if (channel != null) {
        return;
    }
    workerGroup = new NioEventLoopGroup(0, threadFactory);
    ServerBootstrap bootstrap = new ServerBootstrap().group(workerGroup).channel(NioServerSocketChannel.class).localAddress(listenAddress.socketAddress()).childHandler(new ChannelInitializer<SocketChannel>() {

        @Override
        protected void initChannel(SocketChannel ch) {
            CatchupServerProtocol protocol = new CatchupServerProtocol();
            ChannelPipeline pipeline = ch.pipeline();
            pipeline.addLast(new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4, 0, 4));
            pipeline.addLast(new LengthFieldPrepender(4));
            pipeline.addLast(new VersionDecoder(logProvider));
            pipeline.addLast(new VersionPrepender());
            pipeline.addLast(new ResponseMessageTypeEncoder());
            pipeline.addLast(new RequestMessageTypeEncoder());
            pipeline.addLast(new TxPullResponseEncoder());
            pipeline.addLast(new CoreSnapshotEncoder());
            pipeline.addLast(new GetStoreIdResponseEncoder());
            pipeline.addLast(new StoreCopyFinishedResponseEncoder());
            pipeline.addLast(new TxStreamFinishedResponseEncoder());
            pipeline.addLast(new FileChunkEncoder());
            pipeline.addLast(new FileHeaderEncoder());
            pipeline.addLast(new ServerMessageTypeHandler(protocol, logProvider));
            pipeline.addLast(decoders(protocol));
            pipeline.addLast(new TxPullRequestHandler(protocol, storeIdSupplier, dataSourceAvailabilitySupplier, transactionIdStoreSupplier, logicalTransactionStoreSupplier, txPullBatchSize, monitors, logProvider));
            pipeline.addLast(new ChunkedWriteHandler());
            pipeline.addLast(new GetStoreRequestHandler(protocol, dataSourceSupplier, checkPointerSupplier, fs, pageCache, logProvider, storeCopyCheckPointMutex));
            pipeline.addLast(new GetStoreIdRequestHandler(protocol, storeIdSupplier));
            if (coreState != null) {
                pipeline.addLast(new CoreSnapshotRequestHandler(protocol, coreState));
            }
            pipeline.addLast(new ExceptionLoggingHandler(log));
            pipeline.addLast(new ExceptionMonitoringHandler(monitors.newMonitor(ExceptionMonitoringHandler.Monitor.class, CatchupServer.class)));
            pipeline.addLast(new ExceptionSwallowingHandler());
        }
    });
    try {
        channel = bootstrap.bind().syncUninterruptibly().channel();
    } catch (Exception e) {
        //noinspection ConstantConditions
        if (e instanceof BindException) {
            userLog.error("Address is already bound for setting: " + CausalClusteringSettings.transaction_listen_address + " with value: " + listenAddress);
            log.error("Address is already bound for setting: " + CausalClusteringSettings.transaction_listen_address + " with value: " + listenAddress, e);
            throw e;
        }
    }
}
Also used : SocketChannel(io.netty.channel.socket.SocketChannel) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) ExceptionSwallowingHandler(org.neo4j.causalclustering.handlers.ExceptionSwallowingHandler) VersionPrepender(org.neo4j.causalclustering.VersionPrepender) TxStreamFinishedResponseEncoder(org.neo4j.causalclustering.catchup.tx.TxStreamFinishedResponseEncoder) GetStoreIdResponseEncoder(org.neo4j.causalclustering.catchup.storecopy.GetStoreIdResponseEncoder) LengthFieldPrepender(io.netty.handler.codec.LengthFieldPrepender) CoreSnapshotRequestHandler(org.neo4j.causalclustering.core.state.snapshot.CoreSnapshotRequestHandler) ExceptionLoggingHandler(org.neo4j.causalclustering.handlers.ExceptionLoggingHandler) FileHeaderEncoder(org.neo4j.causalclustering.catchup.storecopy.FileHeaderEncoder) LengthFieldBasedFrameDecoder(io.netty.handler.codec.LengthFieldBasedFrameDecoder) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) TxPullRequestHandler(org.neo4j.causalclustering.catchup.tx.TxPullRequestHandler) GetStoreRequestHandler(org.neo4j.causalclustering.catchup.storecopy.GetStoreRequestHandler) FileChunkEncoder(org.neo4j.causalclustering.catchup.storecopy.FileChunkEncoder) BindException(java.net.BindException) VersionDecoder(org.neo4j.causalclustering.VersionDecoder) TxPullResponseEncoder(org.neo4j.causalclustering.catchup.tx.TxPullResponseEncoder) StoreCopyFinishedResponseEncoder(org.neo4j.causalclustering.catchup.storecopy.StoreCopyFinishedResponseEncoder) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) ChannelPipeline(io.netty.channel.ChannelPipeline) BindException(java.net.BindException) ExceptionMonitoringHandler(org.neo4j.causalclustering.handlers.ExceptionMonitoringHandler) CoreSnapshotEncoder(org.neo4j.causalclustering.core.state.snapshot.CoreSnapshotEncoder) ChunkedWriteHandler(io.netty.handler.stream.ChunkedWriteHandler) GetStoreIdRequestHandler(org.neo4j.causalclustering.catchup.storecopy.GetStoreIdRequestHandler)

Example 45 with LengthFieldBasedFrameDecoder

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

the class ServerCnxTest method resetChannel.

private void resetChannel() throws Exception {
    int MaxMessageSize = 5 * 1024 * 1024;
    if (channel != null && channel.isActive()) {
        serverCnx.close();
        channel.close().get();
    }
    serverCnx = new ServerCnx(brokerService);
    channel = new EmbeddedChannel(new LengthFieldBasedFrameDecoder(MaxMessageSize, 0, 4, 0, 4), serverCnx);
}
Also used : EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) 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