Search in sources :

Example 1 with RaftMessageDecoder

use of org.neo4j.causalclustering.messaging.marshalling.RaftMessageDecoder 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)

Aggregations

ServerBootstrap (io.netty.bootstrap.ServerBootstrap)1 ChannelPipeline (io.netty.channel.ChannelPipeline)1 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)1 SocketChannel (io.netty.channel.socket.SocketChannel)1 NioServerSocketChannel (io.netty.channel.socket.nio.NioServerSocketChannel)1 LengthFieldBasedFrameDecoder (io.netty.handler.codec.LengthFieldBasedFrameDecoder)1 LengthFieldPrepender (io.netty.handler.codec.LengthFieldPrepender)1 BindException (java.net.BindException)1 VersionDecoder (org.neo4j.causalclustering.VersionDecoder)1 VersionPrepender (org.neo4j.causalclustering.VersionPrepender)1 ExceptionLoggingHandler (org.neo4j.causalclustering.handlers.ExceptionLoggingHandler)1 ExceptionMonitoringHandler (org.neo4j.causalclustering.handlers.ExceptionMonitoringHandler)1 ExceptionSwallowingHandler (org.neo4j.causalclustering.handlers.ExceptionSwallowingHandler)1 RaftMessageDecoder (org.neo4j.causalclustering.messaging.marshalling.RaftMessageDecoder)1