类io.netty.channel.udt.nio.NioUdtProvider源码实例Demo

下面列出了怎么用io.netty.channel.udt.nio.NioUdtProvider的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: netty-4.1.22   文件: ByteEchoPeerBase.java
public void run() throws Exception {
    final ThreadFactory connectFactory = new DefaultThreadFactory("rendezvous");
    final NioEventLoopGroup connectGroup = new NioEventLoopGroup(1,
            connectFactory, NioUdtProvider.BYTE_PROVIDER);
    try {
        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();
    }
}
 
源代码2 项目: netty4.0.27Learn   文件: ByteEchoPeerBase.java
public void run() throws Exception {
    final ThreadFactory connectFactory = new DefaultThreadFactory("rendezvous");
    final NioEventLoopGroup connectGroup = new NioEventLoopGroup(1,
            connectFactory, NioUdtProvider.BYTE_PROVIDER);
    try {
        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();
    }
}
 
源代码3 项目: netty4.0.27Learn   文件: NioUdtProviderTest.java
/**
 * verify factory
 */
@Test
public void provideFactory() {
    // bytes
    assertNotNull(NioUdtProvider.BYTE_ACCEPTOR.newChannel());
    assertNotNull(NioUdtProvider.BYTE_CONNECTOR.newChannel());
    assertNotNull(NioUdtProvider.BYTE_RENDEZVOUS.newChannel());

    // message
    assertNotNull(NioUdtProvider.MESSAGE_ACCEPTOR.newChannel());
    assertNotNull(NioUdtProvider.MESSAGE_CONNECTOR.newChannel());
    assertNotNull(NioUdtProvider.MESSAGE_RENDEZVOUS.newChannel());

    // acceptor types
    assertTrue(NioUdtProvider.BYTE_ACCEPTOR.newChannel() instanceof UdtServerChannel);
    assertTrue(NioUdtProvider.MESSAGE_ACCEPTOR.newChannel() instanceof UdtServerChannel);
}
 
源代码4 项目: PowerTunnel   文件: ProxyToServerConnection.java
@Override
protected Future<?> execute() {
    Bootstrap cb = new Bootstrap()
            .group(proxyServer.getProxyToServerWorkerFor(transportProtocol))
            .resolver(remoteAddressResolver);

    switch (transportProtocol) {
        case TCP:
            LOG.debug("Connecting to server with TCP");
            cb.channelFactory(NioSocketChannel::new);
            break;
        case UDT:
            LOG.debug("Connecting to server with UDT");
            cb.channelFactory(NioUdtProvider.BYTE_CONNECTOR)
                    .option(ChannelOption.SO_REUSEADDR, true);
            break;
        default:
            throw new UnknownTransportProtocolException(transportProtocol);
    }

    cb.handler(new ChannelInitializer<Channel>() {
        protected void initChannel(Channel ch) {
            initChannelPipeline(ch.pipeline(), initialRequest);
        }
    });
    cb.option(ChannelOption.CONNECT_TIMEOUT_MILLIS,
            proxyServer.getConnectTimeout());

    if (localAddress != null) {
        return cb.connect(remoteAddress, localAddress);
    } else {
        return cb.connect(remoteAddress);
    }
}
 
源代码5 项目: netty-4.1.22   文件: MsgEchoClient.java
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.MESSAGE_PROVIDER);
        try {
            final Bootstrap boot = new Bootstrap();
            boot.group(connectGroup)
                    .channelFactory(NioUdtProvider.MESSAGE_CONNECTOR)
                    .handler(new ChannelInitializer<UdtChannel>() {
                        @Override
                        public void initChannel(final UdtChannel ch)
                                throws Exception {
                            ch.pipeline().addLast(
                                    new LoggingHandler(LogLevel.INFO),
                                    new MsgEchoClientHandler());
                        }
                    });
            // 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();
        }
    }
 
源代码6 项目: netty-4.1.22   文件: MsgEchoServer.java
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 {
        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();
    }
}
 
源代码7 项目: netty-4.1.22   文件: ByteEchoClient.java
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 {
        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();
    }
}
 
源代码8 项目: netty-4.1.22   文件: ByteEchoServer.java
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 {
        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();
    }
}
 
源代码9 项目: netty-4.1.22   文件: MsgEchoPeerBase.java
public void run() throws Exception {
    // Configure the peer.
    final ThreadFactory connectFactory = new DefaultThreadFactory("rendezvous");
    final NioEventLoopGroup connectGroup = new NioEventLoopGroup(1,
            connectFactory, NioUdtProvider.MESSAGE_PROVIDER);
    try {
        final Bootstrap boot = new Bootstrap();
        boot.group(connectGroup)
                .channelFactory(NioUdtProvider.MESSAGE_RENDEZVOUS)
                .handler(new ChannelInitializer<UdtChannel>() {
                    @Override
                    public void initChannel(final UdtChannel ch)
                            throws Exception {
                        ch.pipeline().addLast(
                                new LoggingHandler(LogLevel.INFO),
                                new MsgEchoPeerHandler(messageSize));
                    }
                });
        // Start the peer.
        final ChannelFuture f = boot.connect(peer, self).sync();
        // Wait until the connection is closed.
        f.channel().closeFuture().sync();
    } finally {
        // Shut down the event loop to terminate all threads.
        connectGroup.shutdownGracefully();
    }
}
 
@Override
public void run() {
    final Bootstrap boot = new Bootstrap();
    final ThreadFactory clientFactory = new DefaultThreadFactory("client");
    final NioEventLoopGroup connectGroup = new NioEventLoopGroup(1,
            clientFactory, NioUdtProvider.BYTE_PROVIDER);
    try {
        boot.group(connectGroup)
                .channelFactory(NioUdtProvider.BYTE_CONNECTOR)
                .handler(new ChannelInitializer<UdtChannel>() {

                    @Override
                    protected void initChannel(final UdtChannel ch)
                            throws Exception {
                        final ChannelPipeline pipeline = ch.pipeline();
                        pipeline.addLast("framer",
                                new DelimiterBasedFrameDecoder(8192,
                                        Delimiters.lineDelimiter()));
                        pipeline.addLast("decoder", new StringDecoder(
                                CharsetUtil.UTF_8));
                        pipeline.addLast("encoder", new StringEncoder(
                                CharsetUtil.UTF_8));
                        pipeline.addLast("handler", new ClientHandler());
                    }
                });
        channel = boot.connect(address).sync().channel();
        isRunning = true;
        log.info("Client ready.");
        waitForRunning(false);
        log.info("Client closing...");
        channel.close().sync();
        isShutdown = true;
        log.info("Client is done.");
    } catch (final Throwable e) {
        log.error("Client failed.", e);
    } finally {
        connectGroup.shutdownGracefully().syncUninterruptibly();
    }
}
 
源代码11 项目: netty-4.1.22   文件: NioUdtProviderTest.java
/**
 * verify factory
 */
@Test
public void provideFactory() {
    NioUdtByteAcceptorChannel nioUdtByteAcceptorChannel
            = (NioUdtByteAcceptorChannel) NioUdtProvider.BYTE_ACCEPTOR.newChannel();
    NioUdtByteConnectorChannel nioUdtByteConnectorChannel
            = (NioUdtByteConnectorChannel) NioUdtProvider.BYTE_CONNECTOR.newChannel();
    NioUdtByteRendezvousChannel nioUdtByteRendezvousChannel
            = (NioUdtByteRendezvousChannel) NioUdtProvider.BYTE_RENDEZVOUS.newChannel();
    NioUdtMessageAcceptorChannel nioUdtMessageAcceptorChannel
            = (NioUdtMessageAcceptorChannel) NioUdtProvider.MESSAGE_ACCEPTOR.newChannel();
    NioUdtMessageConnectorChannel nioUdtMessageConnectorChannel
            = (NioUdtMessageConnectorChannel) NioUdtProvider.MESSAGE_CONNECTOR.newChannel();
    NioUdtMessageRendezvousChannel nioUdtMessageRendezvousChannel
            = (NioUdtMessageRendezvousChannel) NioUdtProvider.MESSAGE_RENDEZVOUS.newChannel();

    // bytes
    assertNotNull(nioUdtByteAcceptorChannel);
    assertNotNull(nioUdtByteConnectorChannel);
    assertNotNull(nioUdtByteRendezvousChannel);

    // message
    assertNotNull(nioUdtMessageAcceptorChannel);
    assertNotNull(nioUdtMessageConnectorChannel);
    assertNotNull(nioUdtMessageRendezvousChannel);

    // channel
    assertNotNull(NioUdtProvider.channelUDT(nioUdtByteAcceptorChannel));
    assertNotNull(NioUdtProvider.channelUDT(nioUdtByteConnectorChannel));
    assertNotNull(NioUdtProvider.channelUDT(nioUdtByteRendezvousChannel));
    assertNotNull(NioUdtProvider.channelUDT(nioUdtMessageAcceptorChannel));
    assertNotNull(NioUdtProvider.channelUDT(nioUdtMessageConnectorChannel));
    assertNotNull(NioUdtProvider.channelUDT(nioUdtMessageRendezvousChannel));

    // acceptor types
    assertTrue(NioUdtProvider.BYTE_ACCEPTOR.newChannel() instanceof UdtServerChannel);
    assertTrue(NioUdtProvider.MESSAGE_ACCEPTOR.newChannel() instanceof UdtServerChannel);
}
 
源代码12 项目: yfs   文件: ProxyToServerConnection.java
@Override
protected Future<?> execute() {
    Bootstrap cb = new Bootstrap().group(proxyServer.getProxyToServerWorkerFor(transportProtocol));

    switch (transportProtocol) {
        case TCP:
            LOG.debug("Connecting to server with TCP");
            cb.channelFactory(new ChannelFactory<Channel>() {
                @Override
                public Channel newChannel() {
                    return new NioSocketChannel();
                }
            });
            break;
        case UDT:
            LOG.debug("Connecting to server with UDT");
            cb.channelFactory(NioUdtProvider.BYTE_CONNECTOR)
                    .option(ChannelOption.SO_REUSEADDR, true);
            break;
        default:
            throw new UnknownTransportProtocolException(transportProtocol);
    }

    cb.handler(new ChannelInitializer<Channel>() {
        protected void initChannel(Channel ch) throws Exception {
            initChannelPipeline(ch.pipeline(), initialRequest);
        };
    });
    cb.option(ChannelOption.CONNECT_TIMEOUT_MILLIS,
            proxyServer.getConnectTimeout());

    if (localAddress != null) {
        return cb.connect(remoteAddress, localAddress);
    } else {
        return cb.connect(remoteAddress);
    }
}
 
源代码13 项目: mpush   文件: GatewayClient.java
@Override
public ChannelFactory<? extends Channel> getChannelFactory() {
    if (CC.mp.net.tcpGateway()) return super.getChannelFactory();
    if (CC.mp.net.udtGateway()) return NioUdtProvider.BYTE_CONNECTOR;
    if (CC.mp.net.sctpGateway()) return NioSctpChannel::new;
    return super.getChannelFactory();
}
 
源代码14 项目: mpush   文件: GatewayClient.java
@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();
}
 
源代码15 项目: mpush   文件: GatewayServer.java
@Override
public ChannelFactory<? extends ServerChannel> getChannelFactory() {
    if (CC.mp.net.tcpGateway()) return super.getChannelFactory();
    if (CC.mp.net.udtGateway()) return NioUdtProvider.BYTE_ACCEPTOR;
    if (CC.mp.net.sctpGateway()) return NioSctpServerChannel::new;
    return super.getChannelFactory();
}
 
源代码16 项目: mpush   文件: GatewayServer.java
@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();
}
 
源代码17 项目: netty4.0.27Learn   文件: MsgEchoClient.java
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.MESSAGE_PROVIDER);
        try {
            final Bootstrap boot = new Bootstrap();
            boot.group(connectGroup)
                    .channelFactory(NioUdtProvider.MESSAGE_CONNECTOR)
                    .handler(new ChannelInitializer<UdtChannel>() {
                        @Override
                        public void initChannel(final UdtChannel ch)
                                throws Exception {
                            ch.pipeline().addLast(
                                    new LoggingHandler(LogLevel.INFO),
                                    new MsgEchoClientHandler());
                        }
                    });
            // 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();
        }
    }
 
源代码18 项目: netty4.0.27Learn   文件: MsgEchoServer.java
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 {
        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();
    }
}
 
源代码19 项目: netty4.0.27Learn   文件: ByteEchoClient.java
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 {
        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();
    }
}
 
源代码20 项目: netty4.0.27Learn   文件: ByteEchoServer.java
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 {
        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();
    }
}
 
源代码21 项目: netty4.0.27Learn   文件: MsgEchoPeerBase.java
public void run() throws Exception {
    // Configure the peer.
    final ThreadFactory connectFactory = new DefaultThreadFactory("rendezvous");
    final NioEventLoopGroup connectGroup = new NioEventLoopGroup(1,
            connectFactory, NioUdtProvider.MESSAGE_PROVIDER);
    try {
        final Bootstrap boot = new Bootstrap();
        boot.group(connectGroup)
                .channelFactory(NioUdtProvider.MESSAGE_RENDEZVOUS)
                .handler(new ChannelInitializer<UdtChannel>() {
                    @Override
                    public void initChannel(final UdtChannel ch)
                            throws Exception {
                        ch.pipeline().addLast(
                                new LoggingHandler(LogLevel.INFO),
                                new MsgEchoPeerHandler(messageSize));
                    }
                });
        // Start the peer.
        final ChannelFuture f = boot.connect(peer, self).sync();
        // Wait until the connection is closed.
        f.channel().closeFuture().sync();
    } finally {
        // Shut down the event loop to terminate all threads.
        connectGroup.shutdownGracefully();
    }
}
 
@Override
public void run() {
    final Bootstrap boot = new Bootstrap();
    final ThreadFactory clientFactory = new DefaultThreadFactory("client");
    final NioEventLoopGroup connectGroup = new NioEventLoopGroup(1,
            clientFactory, NioUdtProvider.BYTE_PROVIDER);
    try {
        boot.group(connectGroup)
                .channelFactory(NioUdtProvider.BYTE_CONNECTOR)
                .handler(new ChannelInitializer<UdtChannel>() {

                    @Override
                    protected void initChannel(final UdtChannel ch)
                            throws Exception {
                        final ChannelPipeline pipeline = ch.pipeline();
                        pipeline.addLast("framer",
                                new DelimiterBasedFrameDecoder(8192,
                                        Delimiters.lineDelimiter()));
                        pipeline.addLast("decoder", new StringDecoder(
                                CharsetUtil.UTF_8));
                        pipeline.addLast("encoder", new StringEncoder(
                                CharsetUtil.UTF_8));
                        pipeline.addLast("handler", new ClientHandler());
                    }
                });
        channel = boot.connect(host, port).sync().channel();
        isRunning = true;
        log.info("Client ready.");
        waitForRunning(false);
        log.info("Client closing...");
        channel.close().sync();
        isShutdown = true;
        log.info("Client is done.");
    } catch (final Throwable e) {
        log.error("Client failed.", e);
    } finally {
        connectGroup.shutdownGracefully().syncUninterruptibly();
    }
}
 
源代码23 项目: netty-4.1.22   文件: MsgEchoClientHandler.java
@Override
public void channelActive(final ChannelHandlerContext ctx) {
    System.err.println("ECHO active " + NioUdtProvider.socketUDT(ctx.channel()).toStringOptions());
    ctx.writeAndFlush(message);
}
 
源代码24 项目: netty-4.1.22   文件: MsgEchoServerHandler.java
@Override
public void channelActive(final ChannelHandlerContext ctx) {
    System.err.println("ECHO active " + NioUdtProvider.socketUDT(ctx.channel()).toStringOptions());
}
 
源代码25 项目: netty-4.1.22   文件: ByteEchoServerHandler.java
@Override
public void channelActive(final ChannelHandlerContext ctx) {
    System.err.println("ECHO active " + NioUdtProvider.socketUDT(ctx.channel()).toStringOptions());
}
 
源代码26 项目: netty-4.1.22   文件: ByteEchoClientHandler.java
@Override
public void channelActive(final ChannelHandlerContext ctx) {
    System.err.println("ECHO active " + NioUdtProvider.socketUDT(ctx.channel()).toStringOptions());
    ctx.writeAndFlush(message);
}
 
源代码27 项目: netty-4.1.22   文件: MsgEchoPeerHandler.java
@Override
public void channelActive(final ChannelHandlerContext ctx) {
    System.err.println("ECHO active " + NioUdtProvider.socketUDT(ctx.channel()).toStringOptions());
    ctx.writeAndFlush(message);
}
 
源代码28 项目: netty-4.1.22   文件: ByteEchoPeerHandler.java
@Override
public void channelActive(ChannelHandlerContext ctx) {
    System.err.println("ECHO active " + NioUdtProvider.socketUDT(ctx.channel()).toStringOptions());
    ctx.writeAndFlush(message);
}
 
@Override
public void run() {
    final ServerBootstrap boot = new ServerBootstrap();
    final ThreadFactory acceptFactory = new DefaultThreadFactory("accept");
    final ThreadFactory serverFactory = new DefaultThreadFactory("server");
    final NioEventLoopGroup acceptGroup = new NioEventLoopGroup(1,
            acceptFactory, NioUdtProvider.BYTE_PROVIDER);
    final NioEventLoopGroup connectGroup = new NioEventLoopGroup(1,
            serverFactory, NioUdtProvider.BYTE_PROVIDER);
    try {
        boot.group(acceptGroup, connectGroup)
                .channelFactory(NioUdtProvider.BYTE_ACCEPTOR)
                .childHandler(new ChannelInitializer<UdtChannel>() {
                    @Override
                    protected void initChannel(final UdtChannel ch)
                            throws Exception {
                        final ChannelPipeline pipeline = ch.pipeline();
                        pipeline.addLast("framer",
                                new DelimiterBasedFrameDecoder(8192,
                                        Delimiters.lineDelimiter()));
                        pipeline.addLast("decoder", new StringDecoder(
                                CharsetUtil.UTF_8));
                        pipeline.addLast("encoder", new StringEncoder(
                                CharsetUtil.UTF_8));
                        pipeline.addLast("handler", new ServerHandler(
                                group));
                    }
                });
        channel = boot.bind(address).sync().channel();
        isRunning = true;
        log.info("Server ready.");
        waitForRunning(false);
        log.info("Server closing acceptor...");
        channel.close().sync();
        log.info("Server closing connectors...");
        group.close().sync();
        isShutdown = true;
        log.info("Server is done.");
    } catch (final Throwable e) {
        log.error("Server failure.", e);
    } finally {
        acceptGroup.shutdownGracefully();
        connectGroup.shutdownGracefully();

        acceptGroup.terminationFuture().syncUninterruptibly();
        connectGroup.terminationFuture().syncUninterruptibly();
    }
}
 
源代码30 项目: netty-4.1.22   文件: EchoMessageHandler.java
@Override
public void channelActive(final ChannelHandlerContext ctx) throws Exception {
    log.info("ECHO active {}", NioUdtProvider.socketUDT(ctx.channel()).toStringOptions());
    ctx.writeAndFlush(message);
}
 
 类所在包
 同包方法