Example usage for io.netty.channel ChannelInitializer ChannelInitializer

List of usage examples for io.netty.channel ChannelInitializer ChannelInitializer

Introduction

In this page you can find the example usage for io.netty.channel ChannelInitializer ChannelInitializer.

Prototype

ChannelInitializer

Source Link

Usage

From source file:com.papteco.client.netty.ObjectEchoBuilder.java

License:Apache License

public void getMailsList() throws Exception {
    EventLoopGroup group = new NioEventLoopGroup();
    try {//from  www .ja va  2s.co  m
        Bootstrap b = new Bootstrap();
        b.group(group).channel(NioSocketChannel.class).handler(new ChannelInitializer<SocketChannel>() {
            @Override
            public void initChannel(SocketChannel ch) throws Exception {
                ch.pipeline().addLast(new ObjectEncoder(),
                        new NewObjectDecoder(ClassResolvers.cacheDisabled(null)),
                        new LoadMailslistClientHandler(username));
            }
        });
        b.connect(envsetting.getProperty("pims_ip"), PortTranslater(envsetting.getProperty("comm_nett_port")))
                .sync().channel().closeFuture().sync();
    } finally {
        group.shutdownGracefully();
    }
}

From source file:com.papteco.client.netty.ObjectEchoBuilder.java

License:Apache License

public void downMailFile() throws Exception {
    EventLoopGroup group = new NioEventLoopGroup();
    try {/*  w w  w.  ja v a2 s. c o m*/
        Bootstrap b = new Bootstrap();
        b.group(group).channel(NioSocketChannel.class).handler(new ChannelInitializer<SocketChannel>() {
            @Override
            public void initChannel(SocketChannel ch) throws Exception {
                ch.pipeline().addLast(new ObjectEncoder(),
                        new NewObjectDecoder(ClassResolvers.cacheDisabled(null)),
                        new DownMailClientHandler(username, mailfile));
            }
        });
        b.connect(envsetting.getProperty("pims_ip"), PortTranslater(envsetting.getProperty("comm_nett_port")))
                .sync().channel().closeFuture().sync();
    } finally {
        group.shutdownGracefully();
    }
}

From source file:com.papteco.client.netty.OpenFileServerBuilder.java

License:Apache License

public void run() {
    EventLoopGroup bossGroup = new NioEventLoopGroup();
    EventLoopGroup workerGroup = new NioEventLoopGroup();
    try {//  ww  w.  j  ava2s  .c  o m
        ServerBootstrap b = new ServerBootstrap();
        b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
                .childHandler(new ChannelInitializer<SocketChannel>() {
                    @Override
                    public void initChannel(SocketChannel ch) throws Exception {
                        ch.pipeline().addLast(new ObjectEncoder(),
                                new NewObjectDecoder(ClassResolvers.cacheDisabled(null)),
                                new OpenFileServerHandler());
                    }
                });

        // Bind and start to accept incoming connections.
        b.bind(PortTranslater(envsetting.getProperty("open_file_port"))).sync().channel().closeFuture().sync();
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } finally {
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    }
}

From source file:com.papteco.client.netty.QuartzMailBackupBuilder.java

License:Apache License

public void runMailBackup() throws Exception {
    EventLoopGroup group = new NioEventLoopGroup();
    try {//from  w  w  w  . ja  va 2  s  .  com
        Bootstrap b = new Bootstrap();
        b.group(group).channel(NioSocketChannel.class).handler(new ChannelInitializer<SocketChannel>() {
            @Override
            public void initChannel(SocketChannel ch) throws Exception {
                ch.pipeline().addLast(new ObjectEncoder(),
                        new NewObjectDecoder(ClassResolvers.cacheDisabled(null)),
                        new QuartzMailBackupClientHandler());
            }
        });
        b.connect(envsetting.getProperty("pims_ip"), PortTranslater(envsetting.getProperty("email_bkp_port")))
                .sync().channel().closeFuture().sync();
    } finally {
        group.shutdownGracefully();
    }
}

From source file:com.papteco.client.netty.ReleaseFileServerBuilder.java

License:Apache License

public void run() {
    EventLoopGroup bossGroup = new NioEventLoopGroup();
    EventLoopGroup workerGroup = new NioEventLoopGroup();
    try {//from  w  w  w.j  a  v  a2 s .c  om
        ServerBootstrap b = new ServerBootstrap();
        b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
                .childHandler(new ChannelInitializer<SocketChannel>() {
                    @Override
                    public void initChannel(SocketChannel ch) throws Exception {
                        ch.pipeline().addLast(new ObjectEncoder(),
                                new NewObjectDecoder(ClassResolvers.cacheDisabled(null)),
                                new ReleaseFileServerHandler());
                    }
                });

        // Bind and start to accept incoming connections.
        b.bind(PortTranslater(envsetting.getProperty("rlse_file_port"))).sync().channel().closeFuture().sync();
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } finally {
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    }
}

From source file:com.papteco.web.netty.LoginServerBuilder.java

License:Apache License

public void run() {
    EventLoopGroup bossGroup = new NioEventLoopGroup();
    EventLoopGroup workerGroup = new NioEventLoopGroup();
    try {//from w ww . j  av a  2  s. c  o  m
        ServerBootstrap b = new ServerBootstrap();
        b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
                .childHandler(new ChannelInitializer<SocketChannel>() {
                    @Override
                    public void initChannel(SocketChannel ch) throws Exception {
                        ch.pipeline().addLast(new ObjectEncoder(),
                                new NewObjectDecoder(ClassResolvers.cacheDisabled(null)),
                                new LoginServerHandler());
                    }
                });

        // Bind and start to accept incoming connections.
        b.bind(PortTranslater(envsetting.getProperty("login_sym_port"))).sync().channel().closeFuture().sync();
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } finally {
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    }
}

From source file:com.papteco.web.netty.NettyAppServerBuilder.java

License:Apache License

public void run() {
    EventLoopGroup bossGroup = new NioEventLoopGroup();
    EventLoopGroup workerGroup = new NioEventLoopGroup();
    try {// ww  w .j a v a 2s . c om
        ServerBootstrap b = new ServerBootstrap();
        b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
                .childHandler(new ChannelInitializer<SocketChannel>() {
                    @Override
                    public void initChannel(SocketChannel ch) throws Exception {
                        ch.pipeline().addLast(new ObjectEncoder(),
                                new NewObjectDecoder(ClassResolvers.cacheDisabled(null)),
                                new NettyAppServerHandler(rootpath));
                    }
                });

        // Bind and start to accept incoming connections.
        b.bind(PortTranslater(envsetting.getProperty("comm_nett_port"))).sync().channel().closeFuture().sync();
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } finally {
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    }
}

From source file:com.papteco.web.netty.OpenFileClientBuilder.java

License:Apache License

public Object call() throws Exception {
    EventLoopGroup group = new NioEventLoopGroup();
    try {// w ww .  j  a  v a 2  s  .c  o  m
        Bootstrap b = new Bootstrap();
        b.group(group).channel(NioSocketChannel.class).handler(new ChannelInitializer<SocketChannel>() {
            @Override
            public void initChannel(SocketChannel ch) throws Exception {
                ch.pipeline().addLast(new ObjectEncoder(),
                        new NewObjectDecoder(ClassResolvers.cacheDisabled(null)),
                        new OpenFileClientHandler(openfile, filepath, fileStructPath));
            }
        });

        // Start the connection attempt.
        b.connect(host, PortTranslater(envsetting.getProperty("open_file_port"))).sync().channel().closeFuture()
                .sync();

    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        throw e;
    } finally {
        group.shutdownGracefully();
    }
    return "Success";
}

From source file:com.papteco.web.netty.QuartzMailBackupServerBuilder.java

License:Apache License

public void run() {
    EventLoopGroup bossGroup = new NioEventLoopGroup();
    EventLoopGroup workerGroup = new NioEventLoopGroup();
    try {/*from w w w .  j  av a 2 s . co m*/
        ServerBootstrap b = new ServerBootstrap();
        b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
                .childHandler(new ChannelInitializer<SocketChannel>() {
                    @Override
                    public void initChannel(SocketChannel ch) throws Exception {
                        ch.pipeline().addLast(new ObjectEncoder(),
                                new NewObjectDecoder(ClassResolvers.cacheDisabled(null)),
                                new QuartzMailBackupServerHandler(envsetting.getProperty("rootpath")));
                    }
                });

        // Bind and start to accept incoming connections.
        b.bind(PortTranslater(envsetting.getProperty("email_bkp_port"))).sync().channel().closeFuture().sync();
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } finally {
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    }
}

From source file:com.papteco.web.netty.ReleaseFileClientBuilder.java

License:Apache License

public Object call() throws Exception {
    EventLoopGroup group = new NioEventLoopGroup();
    try {/*  w w  w. j  a v  a2s .c  o m*/
        Bootstrap b = new Bootstrap();
        b.group(group).channel(NioSocketChannel.class).handler(new ChannelInitializer<SocketChannel>() {
            @Override
            public void initChannel(SocketChannel ch) throws Exception {
                ch.pipeline().addLast(new ObjectEncoder(),
                        new NewObjectDecoder(ClassResolvers.cacheDisabled(null)),
                        new ReleaseFileClientHandler(filepath, fileStructPath, fileid, taskid));
            }
        });

        // Start the connection attempt.
        b.connect(host, PortTranslater(envsetting.getProperty("rlse_file_port"))).sync().channel().closeFuture()
                .sync();

    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } finally {
        group.shutdownGracefully();
    }
    return "Success";
}