Search in sources :

Example 1 with SessionHandler

use of com.alibaba.otter.canal.admin.handler.SessionHandler in project canal by alibaba.

the class CanalAdminWithNetty method start.

public void start() {
    super.start();
    this.bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool()));
    /*
         * enable keep-alive mechanism, handle abnormal network connection
         * scenarios on OS level. the threshold parameters are depended on OS.
         * e.g. On Linux: net.ipv4.tcp_keepalive_time = 300
         * net.ipv4.tcp_keepalive_probes = 2 net.ipv4.tcp_keepalive_intvl = 30
         */
    bootstrap.setOption("child.keepAlive", true);
    /*
         * optional parameter.
         */
    bootstrap.setOption("child.tcpNoDelay", true);
    // 构造对应的pipeline
    bootstrap.setPipelineFactory(() -> {
        ChannelPipeline pipelines = Channels.pipeline();
        pipelines.addLast(FixedHeaderFrameDecoder.class.getName(), new FixedHeaderFrameDecoder());
        // support to maintain child socket channel.
        pipelines.addLast(HandshakeInitializationHandler.class.getName(), new HandshakeInitializationHandler(childGroups));
        pipelines.addLast(ClientAuthenticationHandler.class.getName(), new ClientAuthenticationHandler(canalAdmin));
        SessionHandler sessionHandler = new SessionHandler(canalAdmin);
        pipelines.addLast(SessionHandler.class.getName(), sessionHandler);
        return pipelines;
    });
    // 启动
    if (StringUtils.isNotEmpty(ip)) {
        this.serverChannel = bootstrap.bind(new InetSocketAddress(this.ip, this.port));
    } else {
        this.serverChannel = bootstrap.bind(new InetSocketAddress(this.port));
    }
}
Also used : SessionHandler(com.alibaba.otter.canal.admin.handler.SessionHandler) ClientAuthenticationHandler(com.alibaba.otter.canal.admin.handler.ClientAuthenticationHandler) NioServerSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory) HandshakeInitializationHandler(com.alibaba.otter.canal.admin.handler.HandshakeInitializationHandler) InetSocketAddress(java.net.InetSocketAddress) FixedHeaderFrameDecoder(com.alibaba.otter.canal.server.netty.handler.FixedHeaderFrameDecoder) ServerBootstrap(org.jboss.netty.bootstrap.ServerBootstrap) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline)

Aggregations

ClientAuthenticationHandler (com.alibaba.otter.canal.admin.handler.ClientAuthenticationHandler)1 HandshakeInitializationHandler (com.alibaba.otter.canal.admin.handler.HandshakeInitializationHandler)1 SessionHandler (com.alibaba.otter.canal.admin.handler.SessionHandler)1 FixedHeaderFrameDecoder (com.alibaba.otter.canal.server.netty.handler.FixedHeaderFrameDecoder)1 InetSocketAddress (java.net.InetSocketAddress)1 ServerBootstrap (org.jboss.netty.bootstrap.ServerBootstrap)1 ChannelPipeline (org.jboss.netty.channel.ChannelPipeline)1 NioServerSocketChannelFactory (org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory)1