本文整理汇总了Java中io.netty.channel.udt.nio.NioUdtProvider.MESSAGE_PROVIDER属性的典型用法代码示例。如果您正苦于以下问题:Java NioUdtProvider.MESSAGE_PROVIDER属性的具体用法?Java NioUdtProvider.MESSAGE_PROVIDER怎么用?Java NioUdtProvider.MESSAGE_PROVIDER使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类io.netty.channel.udt.nio.NioUdtProvider
的用法示例。
在下文中一共展示了NioUdtProvider.MESSAGE_PROVIDER属性的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
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();
}
}
示例2: main
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();
}
}
示例3: run
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();
}
}
示例4: run
public void run() throws Exception {
// Configure the client.
final ThreadFactory connectFactory = new UtilThreadFactory("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(messageSize));
}
});
// 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();
}
}
示例5: run
public void run() throws Exception {
final ThreadFactory acceptFactory = new UtilThreadFactory("accept");
final ThreadFactory connectFactory = new UtilThreadFactory("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();
}
}
示例6: run
public void run() throws Exception {
// Configure the peer.
final ThreadFactory connectFactory = new UtilThreadFactory("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();
}
}
示例7: basicEcho
/**
* verify basic echo message rendezvous
*
* FIXME: Re-enable after making it pass on Windows without unncessary tight loop.
* https://github.com/netty/netty/issues/2853
*/
@Test(timeout = 10 * 1000)
@Ignore
public void basicEcho() throws Exception {
final int messageSize = 64 * 1024;
final int transferLimit = messageSize * 16;
final Meter rate1 = Metrics.newMeter(
NioUdtMessageRendezvousChannelTest.class, "send rate", "bytes", TimeUnit.SECONDS);
final Meter rate2 = Metrics.newMeter(
NioUdtMessageRendezvousChannelTest.class, "send rate", "bytes", TimeUnit.SECONDS);
final InetSocketAddress addr1 = UnitHelp.localSocketAddress();
final InetSocketAddress addr2 = UnitHelp.localSocketAddress();
final EchoMessageHandler handler1 = new EchoMessageHandler(rate1, messageSize);
final EchoMessageHandler handler2 = new EchoMessageHandler(rate2, messageSize);
final NioEventLoopGroup group1 = new NioEventLoopGroup(
1, Executors.defaultThreadFactory(), NioUdtProvider.MESSAGE_PROVIDER);
final NioEventLoopGroup group2 = new NioEventLoopGroup(
1, Executors.defaultThreadFactory(), NioUdtProvider.MESSAGE_PROVIDER);
final Bootstrap boot1 = new Bootstrap();
boot1.group(group1)
.channelFactory(NioUdtProvider.MESSAGE_RENDEZVOUS)
.localAddress(addr1).remoteAddress(addr2).handler(handler1);
final Bootstrap boot2 = new Bootstrap();
boot2.group(group2)
.channelFactory(NioUdtProvider.MESSAGE_RENDEZVOUS)
.localAddress(addr2).remoteAddress(addr1).handler(handler2);
final ChannelFuture connectFuture1 = boot1.connect();
final ChannelFuture connectFuture2 = boot2.connect();
while (handler1.meter().count() < transferLimit
&& handler2.meter().count() < transferLimit) {
log.info("progress : {} {}", handler1.meter().count(), handler2
.meter().count());
Thread.sleep(1000);
}
connectFuture1.channel().close().sync();
connectFuture2.channel().close().sync();
log.info("handler1 : {}", handler1.meter().count());
log.info("handler2 : {}", handler2.meter().count());
assertTrue(handler1.meter().count() >= transferLimit);
assertTrue(handler2.meter().count() >= transferLimit);
assertEquals(handler1.meter().count(), handler2.meter().count());
group1.shutdownGracefully();
group2.shutdownGracefully();
group1.terminationFuture().sync();
group2.terminationFuture().sync();
}
示例8: basicEcho
/**
* verify basic echo message rendezvous
*/
@Test(timeout = 10 * 1000)
public void basicEcho() throws Exception {
final int messageSize = 64 * 1024;
final int transferLimit = messageSize * 16;
final Meter rate1 = Metrics.newMeter(
NioUdtMessageRendezvousChannelTest.class, "send rate", "bytes", TimeUnit.SECONDS);
final Meter rate2 = Metrics.newMeter(
NioUdtMessageRendezvousChannelTest.class, "send rate", "bytes", TimeUnit.SECONDS);
final InetSocketAddress addr1 = UnitHelp.localSocketAddress();
final InetSocketAddress addr2 = UnitHelp.localSocketAddress();
final EchoMessageHandler handler1 = new EchoMessageHandler(rate1, messageSize);
final EchoMessageHandler handler2 = new EchoMessageHandler(rate2, messageSize);
final NioEventLoopGroup group1 = new NioEventLoopGroup(
1, Executors.defaultThreadFactory(), NioUdtProvider.MESSAGE_PROVIDER);
final NioEventLoopGroup group2 = new NioEventLoopGroup(
1, Executors.defaultThreadFactory(), NioUdtProvider.MESSAGE_PROVIDER);
final Bootstrap boot1 = new Bootstrap();
boot1.group(group1)
.channelFactory(NioUdtProvider.MESSAGE_RENDEZVOUS)
.localAddress(addr1).remoteAddress(addr2).handler(handler1);
final Bootstrap boot2 = new Bootstrap();
boot2.group(group2)
.channelFactory(NioUdtProvider.MESSAGE_RENDEZVOUS)
.localAddress(addr2).remoteAddress(addr1).handler(handler2);
final ChannelFuture connectFuture1 = boot1.connect();
final ChannelFuture connectFuture2 = boot2.connect();
while (handler1.meter().count() < transferLimit
&& handler2.meter().count() < transferLimit) {
log.info("progress : {} {}", handler1.meter().count(), handler2
.meter().count());
Thread.sleep(1000);
}
connectFuture1.channel().close().sync();
connectFuture2.channel().close().sync();
log.info("handler1 : {}", handler1.meter().count());
log.info("handler2 : {}", handler2.meter().count());
assertTrue(handler1.meter().count() >= transferLimit);
assertTrue(handler2.meter().count() >= transferLimit);
assertEquals(handler1.meter().count(), handler2.meter().count());
group1.shutdownGracefully();
group2.shutdownGracefully();
group1.terminationFuture().sync();
group2.terminationFuture().sync();
}
示例9: main
public static void main(final String[] args) throws Exception {
log.info("init");
TrafficControl.delay(0);
final AtomicBoolean isOn = new AtomicBoolean(true);
final InetSocketAddress addr1 = UnitHelp.localSocketAddress();
final InetSocketAddress addr2 = UnitHelp.localSocketAddress();
final ChannelHandler handler1 = new EchoMessageHandler(rate, size);
final ChannelHandler handler2 = new EchoMessageHandler(null, size);
final NioEventLoopGroup group1 = new NioEventLoopGroup(
1, Executors.defaultThreadFactory(), NioUdtProvider.MESSAGE_PROVIDER);
final NioEventLoopGroup group2 = new NioEventLoopGroup(
1, Executors.defaultThreadFactory(), NioUdtProvider.MESSAGE_PROVIDER);
final Bootstrap peerBoot1 = new Bootstrap();
peerBoot1.group(group1)
.channelFactory(NioUdtProvider.MESSAGE_RENDEZVOUS)
.localAddress(addr1).remoteAddress(addr2).handler(handler1);
final Bootstrap peerBoot2 = new Bootstrap();
peerBoot2.group(group2)
.channelFactory(NioUdtProvider.MESSAGE_RENDEZVOUS)
.localAddress(addr2).remoteAddress(addr1).handler(handler2);
final ChannelFuture peerFuture1 = peerBoot1.connect();
final ChannelFuture peerFuture2 = peerBoot2.connect();
CustomReporter.enable(3, TimeUnit.SECONDS);
Thread.sleep(time);
isOn.set(false);
Thread.sleep(1000);
peerFuture1.channel().close().sync();
peerFuture2.channel().close().sync();
Thread.sleep(1000);
group1.shutdownGracefully();
group2.shutdownGracefully();
Metrics.defaultRegistry().shutdown();
TrafficControl.delay(0);
log.info("done");
}