Search in sources :

Example 1 with ProtocolV1Decoder

use of io.seata.core.rpc.netty.v1.ProtocolV1Decoder in project seata by seata.

the class NettyServerBootstrap method start.

@Override
public void start() {
    this.serverBootstrap.group(this.eventLoopGroupBoss, this.eventLoopGroupWorker).channel(NettyServerConfig.SERVER_CHANNEL_CLAZZ).option(ChannelOption.SO_BACKLOG, nettyServerConfig.getSoBackLogSize()).option(ChannelOption.SO_REUSEADDR, true).childOption(ChannelOption.SO_KEEPALIVE, true).childOption(ChannelOption.TCP_NODELAY, true).childOption(ChannelOption.SO_SNDBUF, nettyServerConfig.getServerSocketSendBufSize()).childOption(ChannelOption.SO_RCVBUF, nettyServerConfig.getServerSocketResvBufSize()).childOption(ChannelOption.WRITE_BUFFER_WATER_MARK, new WriteBufferWaterMark(nettyServerConfig.getWriteBufferLowWaterMark(), nettyServerConfig.getWriteBufferHighWaterMark())).localAddress(new InetSocketAddress(listenPort)).childHandler(new ChannelInitializer<SocketChannel>() {

        @Override
        public void initChannel(SocketChannel ch) {
            ch.pipeline().addLast(new IdleStateHandler(nettyServerConfig.getChannelMaxReadIdleSeconds(), 0, 0)).addLast(new ProtocolV1Decoder()).addLast(new ProtocolV1Encoder());
            if (channelHandlers != null) {
                addChannelPipelineLast(ch, channelHandlers);
            }
        }
    });
    try {
        ChannelFuture future = this.serverBootstrap.bind(listenPort).sync();
        LOGGER.info("Server started, listen port: {}", listenPort);
        RegistryFactory.getInstance().register(new InetSocketAddress(XID.getIpAddress(), XID.getPort()));
        initialized.set(true);
        future.channel().closeFuture().sync();
    } catch (Exception exx) {
        throw new RuntimeException(exx);
    }
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) SocketChannel(io.netty.channel.socket.SocketChannel) ProtocolV1Decoder(io.seata.core.rpc.netty.v1.ProtocolV1Decoder) InetSocketAddress(java.net.InetSocketAddress) IdleStateHandler(io.netty.handler.timeout.IdleStateHandler) WriteBufferWaterMark(io.netty.channel.WriteBufferWaterMark) ProtocolV1Encoder(io.seata.core.rpc.netty.v1.ProtocolV1Encoder)

Example 2 with ProtocolV1Decoder

use of io.seata.core.rpc.netty.v1.ProtocolV1Decoder in project seata by seata.

the class NettyClientBootstrap method start.

@Override
public void start() {
    if (this.defaultEventExecutorGroup == null) {
        this.defaultEventExecutorGroup = new DefaultEventExecutorGroup(nettyClientConfig.getClientWorkerThreads(), new NamedThreadFactory(getThreadPrefix(nettyClientConfig.getClientWorkerThreadPrefix()), nettyClientConfig.getClientWorkerThreads()));
    }
    this.bootstrap.group(this.eventLoopGroupWorker).channel(nettyClientConfig.getClientChannelClazz()).option(ChannelOption.TCP_NODELAY, true).option(ChannelOption.SO_KEEPALIVE, true).option(ChannelOption.CONNECT_TIMEOUT_MILLIS, nettyClientConfig.getConnectTimeoutMillis()).option(ChannelOption.SO_SNDBUF, nettyClientConfig.getClientSocketSndBufSize()).option(ChannelOption.SO_RCVBUF, nettyClientConfig.getClientSocketRcvBufSize());
    if (nettyClientConfig.enableNative()) {
        if (PlatformDependent.isOsx()) {
            if (LOGGER.isInfoEnabled()) {
                LOGGER.info("client run on macOS");
            }
        } else {
            bootstrap.option(EpollChannelOption.EPOLL_MODE, EpollMode.EDGE_TRIGGERED).option(EpollChannelOption.TCP_QUICKACK, true);
        }
    }
    bootstrap.handler(new ChannelInitializer<SocketChannel>() {

        @Override
        public void initChannel(SocketChannel ch) {
            ChannelPipeline pipeline = ch.pipeline();
            pipeline.addLast(new IdleStateHandler(nettyClientConfig.getChannelMaxReadIdleSeconds(), nettyClientConfig.getChannelMaxWriteIdleSeconds(), nettyClientConfig.getChannelMaxAllIdleSeconds())).addLast(new ProtocolV1Decoder()).addLast(new ProtocolV1Encoder());
            if (channelHandlers != null) {
                addChannelPipelineLast(ch, channelHandlers);
            }
        }
    });
    if (initialized.compareAndSet(false, true) && LOGGER.isInfoEnabled()) {
        LOGGER.info("NettyClientBootstrap has started");
    }
}
Also used : SocketChannel(io.netty.channel.socket.SocketChannel) ProtocolV1Decoder(io.seata.core.rpc.netty.v1.ProtocolV1Decoder) DefaultEventExecutorGroup(io.netty.util.concurrent.DefaultEventExecutorGroup) NamedThreadFactory(io.seata.common.thread.NamedThreadFactory) IdleStateHandler(io.netty.handler.timeout.IdleStateHandler) ProtocolV1Encoder(io.seata.core.rpc.netty.v1.ProtocolV1Encoder) ChannelPipeline(io.netty.channel.ChannelPipeline)

Aggregations

SocketChannel (io.netty.channel.socket.SocketChannel)2 IdleStateHandler (io.netty.handler.timeout.IdleStateHandler)2 ProtocolV1Decoder (io.seata.core.rpc.netty.v1.ProtocolV1Decoder)2 ProtocolV1Encoder (io.seata.core.rpc.netty.v1.ProtocolV1Encoder)2 ChannelFuture (io.netty.channel.ChannelFuture)1 ChannelPipeline (io.netty.channel.ChannelPipeline)1 WriteBufferWaterMark (io.netty.channel.WriteBufferWaterMark)1 DefaultEventExecutorGroup (io.netty.util.concurrent.DefaultEventExecutorGroup)1 NamedThreadFactory (io.seata.common.thread.NamedThreadFactory)1 InetSocketAddress (java.net.InetSocketAddress)1