Search in sources :

Example 1 with ClientAuthenticationHandler

use of com.alibaba.otter.canal.server.netty.handler.ClientAuthenticationHandler in project canal by alibaba.

the class CanalServerWithNetty method start.

public void start() {
    super.start();
    if (!embeddedServer.isStart()) {
        embeddedServer.start();
    }
    this.bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool()));
    // 构造对应的pipeline
    bootstrap.setPipelineFactory(new ChannelPipelineFactory() {

        public ChannelPipeline getPipeline() throws Exception {
            ChannelPipeline pipelines = Channels.pipeline();
            pipelines.addLast(FixedHeaderFrameDecoder.class.getName(), new FixedHeaderFrameDecoder());
            pipelines.addLast(HandshakeInitializationHandler.class.getName(), new HandshakeInitializationHandler());
            pipelines.addLast(ClientAuthenticationHandler.class.getName(), new ClientAuthenticationHandler(embeddedServer));
            SessionHandler sessionHandler = new SessionHandler(embeddedServer);
            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.server.netty.handler.SessionHandler) ClientAuthenticationHandler(com.alibaba.otter.canal.server.netty.handler.ClientAuthenticationHandler) NioServerSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory) HandshakeInitializationHandler(com.alibaba.otter.canal.server.netty.handler.HandshakeInitializationHandler) InetSocketAddress(java.net.InetSocketAddress) ChannelPipelineFactory(org.jboss.netty.channel.ChannelPipelineFactory) 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.server.netty.handler.ClientAuthenticationHandler)1 FixedHeaderFrameDecoder (com.alibaba.otter.canal.server.netty.handler.FixedHeaderFrameDecoder)1 HandshakeInitializationHandler (com.alibaba.otter.canal.server.netty.handler.HandshakeInitializationHandler)1 SessionHandler (com.alibaba.otter.canal.server.netty.handler.SessionHandler)1 InetSocketAddress (java.net.InetSocketAddress)1 ServerBootstrap (org.jboss.netty.bootstrap.ServerBootstrap)1 ChannelPipeline (org.jboss.netty.channel.ChannelPipeline)1 ChannelPipelineFactory (org.jboss.netty.channel.ChannelPipelineFactory)1 NioServerSocketChannelFactory (org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory)1