Example usage for io.netty.channel.udt.nio NioUdtProvider MESSAGE_ACCEPTOR

List of usage examples for io.netty.channel.udt.nio NioUdtProvider MESSAGE_ACCEPTOR

Introduction

In this page you can find the example usage for io.netty.channel.udt.nio NioUdtProvider MESSAGE_ACCEPTOR.

Prototype

ChannelFactory MESSAGE_ACCEPTOR

To view the source code for io.netty.channel.udt.nio NioUdtProvider MESSAGE_ACCEPTOR.

Click Source Link

Document

ChannelFactory for UDT Message Acceptor.

Usage

From source file:com.flysoloing.learning.network.netty.udt.echo.message.MsgEchoServer.java

License:Apache License

public static void main(String[] args) throws Exception {
    final ThreadFactory acceptFactory = new DefaultThreadFactory("accept");
    final ThreadFactory connectFactory = new DefaultThreadFactory("connect");
    final NioEventLoopGroup acceptGroup = new NioEventLoopGroup(1, acceptFactory,
            NioUdtProvider.MESSAGE_PROVIDER);
    final NioEventLoopGroup connectGroup = new NioEventLoopGroup(1, connectFactory,
            NioUdtProvider.MESSAGE_PROVIDER);

    // Configure the server.
    try {/*from w  w w .j ava2  s. c  o m*/
        final ServerBootstrap boot = new ServerBootstrap();
        boot.group(acceptGroup, connectGroup).channelFactory(NioUdtProvider.MESSAGE_ACCEPTOR)
                .option(ChannelOption.SO_BACKLOG, 10).handler(new LoggingHandler(LogLevel.INFO))
                .childHandler(new ChannelInitializer<UdtChannel>() {
                    @Override
                    public void initChannel(final UdtChannel ch) throws Exception {
                        ch.pipeline().addLast(new LoggingHandler(LogLevel.INFO), new MsgEchoServerHandler());
                    }
                });
        // Start the server.
        final ChannelFuture future = boot.bind(PORT).sync();
        // Wait until the server socket is closed.
        future.channel().closeFuture().sync();
    } finally {
        // Shut down all event loops to terminate all threads.
        acceptGroup.shutdownGracefully();
        connectGroup.shutdownGracefully();
    }
}

From source file:com.seagate.kinetic.simulator.io.provider.nio.udt.UdtTransportProvider.java

License:Open Source License

public void doInit() throws InterruptedException {

    this.port = this.service.getServiceConfiguration().getPort();

    final ThreadFactory acceptFactory = new NioThreadFactory("UdtAccept");

    final ThreadFactory connectFactory = new NioThreadFactory("UdtConnect");

    bossGroup = new NioEventLoopGroup(10, acceptFactory, NioUdtProvider.MESSAGE_PROVIDER);

    workerGroup = new NioEventLoopGroup(10, connectFactory, NioUdtProvider.MESSAGE_PROVIDER);

    msChannelInitializer = new UdtChannelInitializer(this.service);

    bootstrap = new ServerBootstrap();

    bootstrap.group(bossGroup, workerGroup).channelFactory(NioUdtProvider.MESSAGE_ACCEPTOR)
            .option(ChannelOption.SO_BACKLOG, 1000).option(ChannelOption.SO_REUSEADDR, true)
            .childHandler(msChannelInitializer);

    logger.info("Kinetic udt service binding on port =" + port);

    channelFuture = bootstrap.bind(port).sync();

    logger.info("Kinetic udt service bound on port =" + port);
}

From source file:io.aos.netty5.udt.echo.message.MsgEchoServer.java

License:Apache License

public static void main(String[] args) throws Exception {
    final ExecutorServiceFactory acceptFactory = new DefaultExecutorServiceFactory("accept");
    final ExecutorServiceFactory connectFactory = new DefaultExecutorServiceFactory("connect");
    final NioEventLoopGroup acceptGroup = new NioEventLoopGroup(1, acceptFactory,
            NioUdtProvider.MESSAGE_PROVIDER);
    final NioEventLoopGroup connectGroup = new NioEventLoopGroup(1, connectFactory,
            NioUdtProvider.MESSAGE_PROVIDER);

    // Configure the server.
    try {//from w  w  w  .jav  a 2 s. com
        final ServerBootstrap boot = new ServerBootstrap();
        boot.group(acceptGroup, connectGroup).channelFactory(NioUdtProvider.MESSAGE_ACCEPTOR)
                .option(ChannelOption.SO_BACKLOG, 10).handler(new LoggingHandler(LogLevel.INFO))
                .childHandler(new ChannelInitializer<UdtChannel>() {
                    @Override
                    public void initChannel(final UdtChannel ch) throws Exception {
                        ch.pipeline().addLast(new LoggingHandler(LogLevel.INFO), new MsgEchoServerHandler());
                    }
                });
        // Start the server.
        final ChannelFuture future = boot.bind(PORT).sync();
        // Wait until the server socket is closed.
        future.channel().closeFuture().sync();
    } finally {
        // Shut down all event loops to terminate all threads.
        acceptGroup.shutdownGracefully();
        connectGroup.shutdownGracefully();
    }
}