Search in sources :

Example 51 with ChannelPipeline

use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelPipeline 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 52 with ChannelPipeline

use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelPipeline in project aerospike-client-java by aerospike.

the class NettyCommand method executeCommand.

private void executeCommand(long deadline, int tstate) {
    state = AsyncCommand.CHANNEL_INIT;
    iteration++;
    try {
        node = command.getNode(cluster);
        node.validateErrorCount();
        conn = (NettyConnection) node.getAsyncConnection(eventState.index, null);
        if (conn != null) {
            setTimeoutTask(deadline, tstate);
            InboundHandler handler = (InboundHandler) conn.channel.pipeline().last();
            handler.setCommand(this);
            writeCommand();
            return;
        }
        connectInProgress = true;
        if (command.policy.connectTimeout > 0) {
            timeoutState = new TimeoutState(deadline, tstate);
            deadline = timeoutState.start + TimeUnit.MILLISECONDS.toNanos(command.policy.connectTimeout);
            timeoutTask.cancel();
            eventLoop.timer.addTimeout(timeoutTask, deadline);
        } else {
            setTimeoutTask(deadline, tstate);
        }
        final InboundHandler handler = new InboundHandler(this);
        Bootstrap b = new Bootstrap();
        initBootstrap(b, cluster, eventLoop);
        b.handler(new ChannelInitializer<SocketChannel>() {

            @Override
            public void initChannel(SocketChannel ch) {
                if (state != AsyncCommand.CHANNEL_INIT) {
                    // Timeout occurred. Close channel.
                    try {
                        ch.close();
                    } catch (Throwable e) {
                    }
                    connectInProgress = false;
                    return;
                }
                state = AsyncCommand.CONNECT;
                conn = new NettyConnection(ch);
                node.connectionOpened(eventLoop.index);
                connectInProgress = false;
                ChannelPipeline p = ch.pipeline();
                if (cluster.tlsPolicy != null && !cluster.tlsPolicy.forLoginOnly) {
                    state = AsyncCommand.TLS_HANDSHAKE;
                    cluster.nettyTlsContext.addHandler(ch, p);
                }
                p.addLast(handler);
            }
        });
        b.connect(node.getAddress());
        eventState.errors = 0;
    } catch (AerospikeException.Connection ac) {
        eventState.errors++;
        onNetworkError(ac);
    } catch (AerospikeException.Backoff ab) {
        eventState.errors++;
        onBackoffError(ab);
    } catch (AerospikeException ae) {
        // Fail without retry on non-connection errors.
        eventState.errors++;
        onFatalError(ae);
    } catch (Throwable e) {
        // Fail without retry on unknown errors.
        eventState.errors++;
        onFatalError(new AerospikeException(e));
    }
}
Also used : AerospikeException(com.aerospike.client.AerospikeException) NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) EpollSocketChannel(io.netty.channel.epoll.EpollSocketChannel) KQueueSocketChannel(io.netty.channel.kqueue.KQueueSocketChannel) SocketChannel(io.netty.channel.socket.SocketChannel) IOUringSocketChannel(io.netty.incubator.channel.uring.IOUringSocketChannel) Bootstrap(io.netty.bootstrap.Bootstrap) ChannelPipeline(io.netty.channel.ChannelPipeline)

Example 53 with ChannelPipeline

use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelPipeline in project aerospike-client-java by aerospike.

the class NettyConnector method finish.

private final void finish() {
    try {
        // Assign normal InboundHandler to connection.
        SocketChannel channel = conn.channel;
        channel.config().setAutoRead(false);
        ChannelPipeline p = channel.pipeline();
        p.removeLast();
        if (cluster.keepAlive == null) {
            p.addLast(new NettyCommand.InboundHandler());
        } else {
            AsyncPool pool = node.getAsyncPool(eventState.index);
            p.addLast(new NettyCommand.InboundHandler(pool));
        }
        conn.updateLastUsed();
        success();
    } catch (Throwable e) {
        Log.error("NettyConnector fatal error: " + Util.getStackTrace(e));
        throw e;
    }
}
Also used : SocketChannel(io.netty.channel.socket.SocketChannel) ChannelPipeline(io.netty.channel.ChannelPipeline) AsyncPool(com.aerospike.client.cluster.Node.AsyncPool)

Example 54 with ChannelPipeline

use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelPipeline in project aerospike-client-java by aerospike.

the class NettyRecover method recover.

private final void recover() {
    // System.out.println("" + tranId + " connection drained");
    if (state == AsyncCommand.COMPLETE) {
        return;
    }
    state = AsyncCommand.COMPLETE;
    try {
        // Assign normal InboundHandler to connection.
        SocketChannel channel = conn.channel;
        channel.config().setAutoRead(false);
        ChannelPipeline p = channel.pipeline();
        p.removeLast();
        if (cluster.keepAlive == null) {
            p.addLast(new NettyCommand.InboundHandler());
        } else {
            AsyncPool pool = node.getAsyncPool(eventState.index);
            p.addLast(new NettyCommand.InboundHandler(pool));
        }
        // Put connection into pool.
        conn.updateLastUsed();
        node.putAsyncConnection(conn, eventLoop.index);
        // Close recovery command.
        close(true);
    } catch (Throwable e) {
        if (!eventState.closed) {
            Log.error("NettyRecover recover failed: " + Util.getStackTrace(e));
        }
    }
}
Also used : SocketChannel(io.netty.channel.socket.SocketChannel) ChannelPipeline(io.netty.channel.ChannelPipeline) AsyncPool(com.aerospike.client.cluster.Node.AsyncPool)

Example 55 with ChannelPipeline

use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelPipeline in project rocketmq-externals by apache.

the class MQTTBridge method init.

private void init() {
    bossGroup = new NioEventLoopGroup(MQTTBridgeConfiguration.threadNumOfBossGroup());
    workerGroup = new NioEventLoopGroup(MQTTBridgeConfiguration.threadNumOfWorkerGroup());
    serverBootstrap = new ServerBootstrap();
    serverBootstrap.group(bossGroup, workerGroup).localAddress(MQTTBridgeConfiguration.port()).channel(NioServerSocketChannel.class).option(ChannelOption.SO_BACKLOG, MQTTBridgeConfiguration.socketBacklog()).childHandler(new ChannelInitializer<SocketChannel>() {

        @Override
        protected void initChannel(SocketChannel ch) throws Exception {
            ChannelPipeline pipeline = ch.pipeline();
            pipeline.addLast("mqtt-decoder", new MqttDecoder());
            pipeline.addLast("mqtt-encoder", MqttEncoder.INSTANCE);
            pipeline.addLast("channel-idle-handler", new MqttIdleHandler());
            pipeline.addLast("message-dispatcher", messageDispatcher);
            pipeline.addLast("connection-manager", connectionHandler);
        }
    });
    subscriptionStore = new InMemorySubscriptionStore();
    clientManager = new ClientManagerImpl();
    messageDispatcher = new MessageDispatcher(clientManager);
    connectionHandler = new MqttConnectionHandler(clientManager, subscriptionStore);
    registerMessageHandlers();
}
Also used : SocketChannel(io.netty.channel.socket.SocketChannel) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) MqttDecoder(io.netty.handler.codec.mqtt.MqttDecoder) ClientManagerImpl(org.apache.rocketmq.iot.connection.client.impl.ClientManagerImpl) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) ChannelPipeline(io.netty.channel.ChannelPipeline) MqttIdleHandler(org.apache.rocketmq.iot.protocol.mqtt.handler.MqttIdleHandler) MessageDispatcher(org.apache.rocketmq.iot.protocol.mqtt.handler.MessageDispatcher) MqttConnectionHandler(org.apache.rocketmq.iot.protocol.mqtt.handler.MqttConnectionHandler) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) InMemorySubscriptionStore(org.apache.rocketmq.iot.storage.subscription.impl.InMemorySubscriptionStore)

Aggregations

ChannelPipeline (io.netty.channel.ChannelPipeline)370 SocketChannel (io.netty.channel.socket.SocketChannel)107 Channel (io.netty.channel.Channel)90 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)90 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)80 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)78 Bootstrap (io.netty.bootstrap.Bootstrap)77 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)69 ChannelFuture (io.netty.channel.ChannelFuture)68 NioServerSocketChannel (io.netty.channel.socket.nio.NioServerSocketChannel)62 HttpObjectAggregator (io.netty.handler.codec.http.HttpObjectAggregator)62 EventLoopGroup (io.netty.channel.EventLoopGroup)54 SslHandler (io.netty.handler.ssl.SslHandler)52 InetSocketAddress (java.net.InetSocketAddress)49 HttpServerCodec (io.netty.handler.codec.http.HttpServerCodec)43 LoggingHandler (io.netty.handler.logging.LoggingHandler)37 IOException (java.io.IOException)37 StringDecoder (io.netty.handler.codec.string.StringDecoder)36 IdleStateHandler (io.netty.handler.timeout.IdleStateHandler)36 StringEncoder (io.netty.handler.codec.string.StringEncoder)33