Search in sources :

Example 1 with NettySimpleMessageHandler

use of com.ctrip.xpipe.netty.NettySimpleMessageHandler in project x-pipe by ctripcorp.

the class NettyKeyedPoolClientFactory method doStart.

@Override
protected void doStart() throws Exception {
    eventLoopGroup = new NioEventLoopGroup(eventLoopThreads, XpipeThreadFactory.create("NettyKeyedPoolClientFactory"));
    b.group(eventLoopGroup).channel(NioSocketChannel.class).option(ChannelOption.TCP_NODELAY, true).handler(new ChannelInitializer<SocketChannel>() {

        @Override
        public void initChannel(SocketChannel ch) throws Exception {
            ChannelPipeline p = ch.pipeline();
            p.addLast(new LoggingHandler());
            p.addLast(new NettySimpleMessageHandler());
            p.addLast(new NettyClientHandler());
        }
    });
}
Also used : NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) SocketChannel(io.netty.channel.socket.SocketChannel) LoggingHandler(io.netty.handler.logging.LoggingHandler) NettySimpleMessageHandler(com.ctrip.xpipe.netty.NettySimpleMessageHandler) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) ChannelPipeline(io.netty.channel.ChannelPipeline)

Example 2 with NettySimpleMessageHandler

use of com.ctrip.xpipe.netty.NettySimpleMessageHandler in project x-pipe by ctripcorp.

the class PsyncLatencyTest method startGetLatency.

private void startGetLatency() {
    EventLoopGroup eventLoopGroup = new NioEventLoopGroup();
    Bootstrap b = new Bootstrap();
    b.group(eventLoopGroup).channel(NioSocketChannel.class).option(ChannelOption.TCP_NODELAY, true).handler(new ChannelInitializer<SocketChannel>() {

        @Override
        public void initChannel(SocketChannel ch) throws Exception {
            ChannelPipeline p = ch.pipeline();
            p.addLast(new LoggingHandler(LogLevel.DEBUG));
            p.addLast(new NettySimpleMessageHandler());
            p.addLast(new ReceiveMessageHandler(runId, offset));
        }
    });
    b.connect(dest);
}
Also used : NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) SocketChannel(io.netty.channel.socket.SocketChannel) LoggingHandler(io.netty.handler.logging.LoggingHandler) EventLoopGroup(io.netty.channel.EventLoopGroup) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) Bootstrap(io.netty.bootstrap.Bootstrap) NettySimpleMessageHandler(com.ctrip.xpipe.netty.NettySimpleMessageHandler) ReceiveMessageHandler(com.ctrip.xpipe.redis.keeper.simple.latency.netty.ReceiveMessageHandler) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) ChannelPipeline(io.netty.channel.ChannelPipeline)

Example 3 with NettySimpleMessageHandler

use of com.ctrip.xpipe.netty.NettySimpleMessageHandler in project x-pipe by ctripcorp.

the class DefaultRedisKeeperServer method startServer.

protected void startServer() throws InterruptedException {
    ServerBootstrap b = new ServerBootstrap();
    b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class).handler(new LoggingHandler(LogLevel.INFO)).childHandler(new ChannelInitializer<SocketChannel>() {

        @Override
        public void initChannel(SocketChannel ch) throws Exception {
            ChannelPipeline p = ch.pipeline();
            p.addLast(new LoggingHandler(LogLevel.DEBUG));
            p.addLast(new NettySimpleMessageHandler());
            p.addLast(new NettyMasterHandler(DefaultRedisKeeperServer.this, new CommandHandlerManager(), keeperConfig.getTrafficReportIntervalMillis()));
        }
    });
    serverSocketChannel = (ServerSocketChannel) b.bind(currentKeeperMeta.getPort()).sync().channel();
}
Also used : NettyMasterHandler(com.ctrip.xpipe.redis.keeper.netty.NettyMasterHandler) SocketChannel(io.netty.channel.socket.SocketChannel) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) ServerSocketChannel(io.netty.channel.socket.ServerSocketChannel) LoggingHandler(io.netty.handler.logging.LoggingHandler) NettySimpleMessageHandler(com.ctrip.xpipe.netty.NettySimpleMessageHandler) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) XpipeRuntimeException(com.ctrip.xpipe.exception.XpipeRuntimeException) RedisSlavePromotionException(com.ctrip.xpipe.redis.keeper.exception.RedisSlavePromotionException) IOException(java.io.IOException) ChannelPipeline(io.netty.channel.ChannelPipeline) CommandHandlerManager(com.ctrip.xpipe.redis.keeper.handler.CommandHandlerManager)

Example 4 with NettySimpleMessageHandler

use of com.ctrip.xpipe.netty.NettySimpleMessageHandler in project x-pipe by ctripcorp.

the class NettyClientFactory method doStart.

@Override
protected void doStart() throws Exception {
    eventLoopGroup = new NioEventLoopGroup(1);
    b.group(eventLoopGroup).channel(NioSocketChannel.class).option(ChannelOption.TCP_NODELAY, true).handler(new ChannelInitializer<SocketChannel>() {

        @Override
        public void initChannel(SocketChannel ch) throws Exception {
            ChannelPipeline p = ch.pipeline();
            p.addLast(new LoggingHandler());
            p.addLast(new NettySimpleMessageHandler());
            p.addLast(new NettyClientHandler());
        }
    });
}
Also used : NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) SocketChannel(io.netty.channel.socket.SocketChannel) LoggingHandler(io.netty.handler.logging.LoggingHandler) NettySimpleMessageHandler(com.ctrip.xpipe.netty.NettySimpleMessageHandler) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) ChannelPipeline(io.netty.channel.ChannelPipeline)

Example 5 with NettySimpleMessageHandler

use of com.ctrip.xpipe.netty.NettySimpleMessageHandler in project x-pipe by ctripcorp.

the class AbstractRedisMasterReplication method connectWithMaster.

protected void connectWithMaster() {
    if (!(getLifecycleState().isStarting() || getLifecycleState().isStarted())) {
        logger.info("[connectWithMaster][do not connect, is stopped!!]{}", redisMaster.masterEndPoint());
        return;
    }
    Bootstrap b = new Bootstrap();
    b.group(nioEventLoopGroup).channel(NioSocketChannel.class).option(ChannelOption.TCP_NODELAY, true).option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT).handler(new ChannelInitializer<SocketChannel>() {

        @Override
        public void initChannel(SocketChannel ch) throws Exception {
            ChannelPipeline p = ch.pipeline();
            p.addLast(new LoggingHandler(LogLevel.DEBUG));
            p.addLast(new NettySimpleMessageHandler());
            p.addLast(createHandler());
        }
    });
    doConnect(b);
}
Also used : NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) SocketChannel(io.netty.channel.socket.SocketChannel) LoggingHandler(io.netty.handler.logging.LoggingHandler) Bootstrap(io.netty.bootstrap.Bootstrap) NettySimpleMessageHandler(com.ctrip.xpipe.netty.NettySimpleMessageHandler) CommandExecutionException(com.ctrip.xpipe.command.CommandExecutionException) IOException(java.io.IOException) XpipeException(com.ctrip.xpipe.exception.XpipeException)

Aggregations

NettySimpleMessageHandler (com.ctrip.xpipe.netty.NettySimpleMessageHandler)6 SocketChannel (io.netty.channel.socket.SocketChannel)6 LoggingHandler (io.netty.handler.logging.LoggingHandler)6 ChannelPipeline (io.netty.channel.ChannelPipeline)5 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)5 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)4 Bootstrap (io.netty.bootstrap.Bootstrap)3 EventLoopGroup (io.netty.channel.EventLoopGroup)2 IOException (java.io.IOException)2 CommandExecutionException (com.ctrip.xpipe.command.CommandExecutionException)1 XpipeException (com.ctrip.xpipe.exception.XpipeException)1 XpipeRuntimeException (com.ctrip.xpipe.exception.XpipeRuntimeException)1 RedisSlavePromotionException (com.ctrip.xpipe.redis.keeper.exception.RedisSlavePromotionException)1 CommandHandlerManager (com.ctrip.xpipe.redis.keeper.handler.CommandHandlerManager)1 NettyMasterHandler (com.ctrip.xpipe.redis.keeper.netty.NettyMasterHandler)1 ReceiveMessageHandler (com.ctrip.xpipe.redis.keeper.simple.latency.netty.ReceiveMessageHandler)1 SetMessageHandler (com.ctrip.xpipe.redis.keeper.simple.latency.netty.SetMessageHandler)1 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)1 ServerSocketChannel (io.netty.channel.socket.ServerSocketChannel)1 NioServerSocketChannel (io.netty.channel.socket.nio.NioServerSocketChannel)1