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

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

Introduction

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

Prototype

SelectorProvider BYTE_PROVIDER

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

Click Source Link

Document

SelectorProvider for UDT Byte channels.

Usage

From source file:com.flysoloing.learning.network.netty.udt.echo.bytes.ByteEchoClient.java

License:Apache License

public static void main(String[] args) throws Exception {
    // Configure the client.
    final ThreadFactory connectFactory = new DefaultThreadFactory("connect");
    final NioEventLoopGroup connectGroup = new NioEventLoopGroup(1, connectFactory,
            NioUdtProvider.BYTE_PROVIDER);
    try {/*from  w ww  .  j a  va  2s . co  m*/
        final Bootstrap boot = new Bootstrap();
        boot.group(connectGroup).channelFactory(NioUdtProvider.BYTE_CONNECTOR)
                .handler(new ChannelInitializer<UdtChannel>() {
                    @Override
                    public void initChannel(final UdtChannel ch) throws Exception {
                        ch.pipeline().addLast(new LoggingHandler(LogLevel.INFO), new ByteEchoClientHandler());
                    }
                });
        // Start the client.
        final ChannelFuture f = boot.connect(HOST, PORT).sync();
        // Wait until the connection is closed.
        f.channel().closeFuture().sync();
    } finally {
        // Shut down the event loop to terminate all threads.
        connectGroup.shutdownGracefully();
    }
}

From source file:com.flysoloing.learning.network.netty.udt.echo.bytes.ByteEchoServer.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.BYTE_PROVIDER);
    final NioEventLoopGroup connectGroup = new NioEventLoopGroup(1, connectFactory,
            NioUdtProvider.BYTE_PROVIDER);

    // Configure the server.
    try {/*from w w  w  .j a v a 2s. c  o m*/
        final ServerBootstrap boot = new ServerBootstrap();
        boot.group(acceptGroup, connectGroup).channelFactory(NioUdtProvider.BYTE_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 ByteEchoServerHandler());
                    }
                });
        // 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.flysoloing.learning.network.netty.udt.echo.rendezvousBytes.ByteEchoPeerBase.java

License:Apache License

public void run() throws Exception {
    final ThreadFactory connectFactory = new DefaultThreadFactory("rendezvous");
    final NioEventLoopGroup connectGroup = new NioEventLoopGroup(1, connectFactory,
            NioUdtProvider.BYTE_PROVIDER);
    try {//from w ww .  j  ava  2  s  .  com
        final Bootstrap bootstrap = new Bootstrap();
        bootstrap.group(connectGroup).channelFactory(NioUdtProvider.BYTE_RENDEZVOUS)
                .handler(new ChannelInitializer<UdtChannel>() {
                    @Override
                    protected void initChannel(UdtChannel ch) throws Exception {
                        ch.pipeline().addLast(new LoggingHandler(LogLevel.INFO),
                                new ByteEchoPeerHandler(messageSize));
                    }
                });
        final ChannelFuture future = bootstrap.connect(peerAddress, myAddress).sync();
        future.channel().closeFuture().sync();
    } finally {
        connectGroup.shutdownGracefully();
    }
}

From source file:com.mpush.client.gateway.GatewayClient.java

License:Apache License

@Override
public SelectorProvider getSelectorProvider() {
    if (CC.mp.net.tcpGateway())
        return super.getSelectorProvider();
    if (CC.mp.net.udtGateway())
        return NioUdtProvider.BYTE_PROVIDER;
    if (CC.mp.net.sctpGateway())
        return super.getSelectorProvider();
    return super.getSelectorProvider();
}

From source file:io.aos.netty5.udt.echo.bytes.ByteEchoClient.java

License:Apache License

public static void main(String[] args) throws Exception {
    // Configure the client.
    final ExecutorServiceFactory connectFactory = new DefaultExecutorServiceFactory("connect");
    final NioEventLoopGroup connectGroup = new NioEventLoopGroup(1, connectFactory,
            NioUdtProvider.BYTE_PROVIDER);

    try {//from w ww .  j a  v  a  2  s  . c o  m
        final Bootstrap boot = new Bootstrap();
        boot.group(connectGroup).channelFactory(NioUdtProvider.BYTE_CONNECTOR)
                .handler(new ChannelInitializer<UdtChannel>() {
                    @Override
                    public void initChannel(final UdtChannel ch) throws Exception {
                        ch.pipeline().addLast(new LoggingHandler(LogLevel.INFO), new ByteEchoClientHandler());
                    }
                });
        // Start the client.
        final ChannelFuture f = boot.connect(HOST, PORT).sync();
        // Wait until the connection is closed.
        f.channel().closeFuture().sync();
    } finally {
        // Shut down the event loop to terminate all threads.
        connectGroup.shutdownGracefully();
    }
}

From source file:io.aos.netty5.udt.echo.bytes.ByteEchoServer.java

License:Apache License

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

    // Configure the server.
    try {//from w  ww .j a  va 2s.co m
        final ServerBootstrap boot = new ServerBootstrap();
        boot.group(acceptGroup, connectGroup).channelFactory(NioUdtProvider.BYTE_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 ByteEchoServerHandler());
                    }
                });
        // 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:io.aos.netty5.udt.echo.rendezvousBytes.ByteEchoPeerBase.java

License:Apache License

public void run() throws Exception {
    final ExecutorServiceFactory connectFactory = new DefaultExecutorServiceFactory("rendezvous");
    final NioEventLoopGroup connectGroup = new NioEventLoopGroup(1, connectFactory,
            NioUdtProvider.BYTE_PROVIDER);

    try {//from   w  w  w .  jav a  2  s  .  co m
        final Bootstrap bootstrap = new Bootstrap();
        bootstrap.group(connectGroup).channelFactory(NioUdtProvider.BYTE_RENDEZVOUS)
                .handler(new ChannelInitializer<UdtChannel>() {
                    @Override
                    protected void initChannel(UdtChannel ch) throws Exception {
                        ch.pipeline().addLast(new LoggingHandler(LogLevel.INFO),
                                new ByteEchoPeerHandler(messageSize));
                    }
                });
        final ChannelFuture future = bootstrap.connect(peerAddress, myAddress).sync();
        future.channel().closeFuture().sync();
    } finally {
        connectGroup.shutdownGracefully();
    }
}

From source file:org.jupiter.transport.netty.NettyUdtAcceptor.java

License:Apache License

@Override
protected EventLoopGroup initEventLoopGroup(int nThreads, ThreadFactory tFactory) {
    return new NioEventLoopGroup(nThreads, tFactory, NioUdtProvider.BYTE_PROVIDER);
}

From source file:se.sics.gvod.net.NettyNetwork.java

License:Open Source License

/**
 * Start listening as a server at the given address..
 *
 * @param addr the address to listen at/*from ww  w  . j  a v a  2s . c  o m*/
 * @param port the port number to listen at
 * @param bindAllNetworkIfs whether to bind on all network interfaces
 * @return true if listening was started
 * @throws ChannelException in case binding failed
 */
private boolean bindUdtPort(InetAddress addr, int port, boolean bindAllNetworkIfs) {

    if (udtPortsToSockets.containsKey(port)) {
        return true;
    }

    ThreadFactory bossFactory = new UtilThreadFactory("boss");
    ThreadFactory workerFactory = new UtilThreadFactory("worker");
    NioEventLoopGroup bossGroup = new NioEventLoopGroup(1, bossFactory, NioUdtProvider.BYTE_PROVIDER);
    NioEventLoopGroup workerGroup = new NioEventLoopGroup(1, workerFactory, NioUdtProvider.BYTE_PROVIDER);
    NettyUdtServerHandler handler = new NettyUdtServerHandler(component);
    ServerBootstrap bootstrap = new ServerBootstrap();
    bootstrap.group(bossGroup, workerGroup).channelFactory(NioUdtProvider.BYTE_ACCEPTOR)
            .childHandler(new NettyInitializer<UdtChannel>(handler, msgDecoderClass))
            .option(ChannelOption.SO_REUSEADDR, true);

    try {
        if (bindAllNetworkIfs) {
            bootstrap.bind(new InetSocketAddress(port)).sync();
        } else {
            bootstrap.bind(new InetSocketAddress(addr, port)).sync();
        }

        logger.debug("Successfully bound to ip:port {}:{}", addr, port);
    } catch (InterruptedException e) {
        logger.warn("Problem when trying to bind to {}:{}", addr.getHostAddress(), port);
        trigger(new Fault(e.getCause()), control);
        return false;
    }

    InetSocketAddress iAddr = new InetSocketAddress(addr, port);
    udtPortsToSockets.put(port, iAddr);
    udtSocketsToServerBootstraps.put(iAddr, bootstrap);

    return true;
}

From source file:se.sics.gvod.net.NettyNetwork.java

License:Open Source License

/**
 * Connect to a UDT server./*from w w  w  .  j  a va2  s . c o  m*/
 *
 * @param remoteAddress the remote address
 * @param localAddress the local address to bind to
 * @return true if connection succeeded
 * @throws ChannelException if connecting failed
 */
private boolean connectUdt(Address remoteAddress, Address localAddress) {
    InetSocketAddress remote = address2SocketAddress(remoteAddress);
    InetSocketAddress local = address2SocketAddress(localAddress);

    if (udtSocketsToBootstraps.containsKey(remote)) {
        return true;
    }

    ThreadFactory workerFactory = new UtilThreadFactory("clientWorker");
    NioEventLoopGroup workerGroup = new NioEventLoopGroup(1, workerFactory, NioUdtProvider.BYTE_PROVIDER);
    NettyStreamHandler handler = new NettyStreamHandler(component, Transport.UDT);
    Bootstrap bootstrap = new Bootstrap();
    bootstrap.group(workerGroup).channelFactory(NioUdtProvider.BYTE_CONNECTOR)
            .handler(new NettyInitializer<UdtChannel>(handler, msgDecoderClass))
            .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, CONNECT_TIMEOUT_MS)
            .option(ChannelOption.SO_REUSEADDR, true);

    try {
        UdtChannel c = (UdtChannel) bootstrap.connect(remote, local).sync().channel();
        addLocalSocket(remote, c);
        logger.debug("Successfully connected to ip:port {}", remote.toString());
    } catch (InterruptedException e) {
        logger.warn("Problem when trying to connect to {}", remote.toString());
        trigger(new Fault(e.getCause()), control);
        return false;
    }

    udtSocketsToBootstraps.put(remote, bootstrap);
    return true;
}