本文整理汇总了Java中io.netty.channel.group.DefaultChannelGroup.add方法的典型用法代码示例。如果您正苦于以下问题:Java DefaultChannelGroup.add方法的具体用法?Java DefaultChannelGroup.add怎么用?Java DefaultChannelGroup.add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.netty.channel.group.DefaultChannelGroup
的用法示例。
在下文中一共展示了DefaultChannelGroup.add方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: startUp
import io.netty.channel.group.DefaultChannelGroup; //导入方法依赖的package包/类
@Override
protected void startUp() throws Exception {
channelGroup = new DefaultChannelGroup(ImmediateEventExecutor.INSTANCE);
EventLoopGroup bossGroup = new NioEventLoopGroup(NUM_BOSS_THREADS,
new ThreadFactoryBuilder()
.setDaemon(true).setNameFormat("boss-thread").build());
EventLoopGroup workerGroup = new NioEventLoopGroup(NUM_WORKER_THREADS,
new ThreadFactoryBuilder()
.setDaemon(true).setNameFormat("worker-thread#%d").build());
bootstrap = new ServerBootstrap()
.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class)
.childHandler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel ch) throws Exception {
channelGroup.add(ch);
ChannelPipeline pipeline = ch.pipeline();
pipeline.addLast("codec", new HttpServerCodec());
pipeline.addLast("compressor", new HttpContentCompressor());
pipeline.addLast("aggregator", new HttpObjectAggregator(MAX_INPUT_SIZE));
pipeline.addLast("handler", new ReportHandler());
}
});
Channel serverChannel = bootstrap.bind(new InetSocketAddress(host, 0)).sync().channel();
channelGroup.add(serverChannel);
bindAddress = (InetSocketAddress) serverChannel.localAddress();
url = URI.create(String.format("http://%s:%d", host, bindAddress.getPort())).toURL();
LOG.info("Tracker service started at {}", url);
}
示例2: testBindMultiple
import io.netty.channel.group.DefaultChannelGroup; //导入方法依赖的package包/类
/**
* Test try to reproduce issue #1335
*/
@Test
public void testBindMultiple() throws Exception {
DefaultChannelGroup channelGroup = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);
NioEventLoopGroup group = new NioEventLoopGroup();
try {
for (int i = 0; i < 100; i++) {
Bootstrap udpBootstrap = new Bootstrap();
udpBootstrap.group(group).channel(NioDatagramChannel.class)
.option(ChannelOption.SO_BROADCAST, true)
.handler(new ChannelInboundHandlerAdapter() {
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) {
// Discard
ReferenceCountUtil.release(msg);
}
});
DatagramChannel datagramChannel = (DatagramChannel) udpBootstrap
.bind(new InetSocketAddress(0)).syncUninterruptibly().channel();
channelGroup.add(datagramChannel);
}
Assert.assertEquals(100, channelGroup.size());
} finally {
channelGroup.close().sync();
group.shutdownGracefully().sync();
}
}
示例3: startServer
import io.netty.channel.group.DefaultChannelGroup; //导入方法依赖的package包/类
@Override
protected void startServer(int port, final Action<ServerWebSocket> websocketAction) {
bossGroup = new NioEventLoopGroup();
workerGroup = new NioEventLoopGroup();
channels = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);
ServerBootstrap bootstrap = new ServerBootstrap();
bootstrap.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class)
.childHandler(new ChannelInitializer<SocketChannel>() {
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
channels.add(ctx.channel());
}
@Override
public void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
pipeline.addLast(new HttpServerCodec())
.addLast(new AsityServerCodec() {
@Override
protected boolean accept(HttpRequest req) {
return URI.create(req.getUri()).getPath().equals(TEST_URI);
}
}.onwebsocket(websocketAction));
}
});
channels.add(bootstrap.bind(port).channel());
}
示例4: startServer
import io.netty.channel.group.DefaultChannelGroup; //导入方法依赖的package包/类
@Override
protected void startServer(int port, final Action<ServerHttpExchange> requestAction) throws
Exception {
bossGroup = new NioEventLoopGroup();
workerGroup = new NioEventLoopGroup();
channels = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);
ServerBootstrap bootstrap = new ServerBootstrap();
bootstrap.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class)
.childHandler(new ChannelInitializer<SocketChannel>() {
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
channels.add(ctx.channel());
}
@Override
public void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
pipeline.addLast(new HttpServerCodec())
.addLast(new AsityServerCodec() {
@Override
protected boolean accept(HttpRequest req) {
return URI.create(req.getUri()).getPath().equals(TEST_URI);
}
}.onhttp(requestAction));
}
});
channels.add(bootstrap.bind(port).channel());
}
示例5: startServer
import io.netty.channel.group.DefaultChannelGroup; //导入方法依赖的package包/类
@Override
protected void startServer() {
bossGroup = new NioEventLoopGroup();
workerGroup = new NioEventLoopGroup();
channels = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);
ServerBootstrap bootstrap = new ServerBootstrap();
bootstrap.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class)
.childHandler(new ChannelInitializer<SocketChannel>() {
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
channels.add(ctx.channel());
}
@Override
public void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
pipeline.addLast(new HttpServerCodec())
.addLast(new VibeServerCodec() {
@Override
protected boolean accept(HttpRequest req) {
return URI.create(req.getUri()).getPath().equals("/test");
}
}
.onwebsocket(performer.serverAction()));
}
});
channels.add(bootstrap.bind(port).channel());
}
示例6: startServer
import io.netty.channel.group.DefaultChannelGroup; //导入方法依赖的package包/类
@Override
protected void startServer() {
bossGroup = new NioEventLoopGroup();
workerGroup = new NioEventLoopGroup();
channels = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);
ServerBootstrap bootstrap = new ServerBootstrap();
bootstrap.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class)
.childHandler(new ChannelInitializer<SocketChannel>() {
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
channels.add(ctx.channel());
}
@Override
public void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
pipeline.addLast(new HttpServerCodec())
.addLast(new VibeServerCodec() {
@Override
protected boolean accept(HttpRequest req) {
return URI.create(req.getUri()).getPath().equals("/test");
}
}
.onhttp(performer.serverAction()));
}
});
channels.add(bootstrap.bind(port).channel());
}
示例7: testBindMultiple
import io.netty.channel.group.DefaultChannelGroup; //导入方法依赖的package包/类
/**
* Test try to reproduce issue #1335
*/
@Test
public void testBindMultiple() throws Exception {
DefaultChannelGroup channelGroup = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);
NioEventLoopGroup group = new NioEventLoopGroup();
try {
for (int i = 0; i < 100; i++) {
Bootstrap udpBootstrap = new Bootstrap();
udpBootstrap.group(group).channel(NioDatagramChannel.class)
.option(ChannelOption.SO_BROADCAST, true)
.handler(new ChannelHandlerAdapter() {
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) {
// Discard
ReferenceCountUtil.release(msg);
}
});
DatagramChannel datagramChannel = (DatagramChannel) udpBootstrap
.bind(new InetSocketAddress(0)).syncUninterruptibly().channel();
channelGroup.add(datagramChannel);
}
Assert.assertEquals(100, channelGroup.size());
} finally {
channelGroup.close().sync();
group.shutdownGracefully().sync();
}
}
示例8: bootstrapNetty
import io.netty.channel.group.DefaultChannelGroup; //导入方法依赖的package包/类
/**
* Bootstraps netty, the server that handles all openflow connections
*/
public void bootstrapNetty() {
try {
bossGroup = new NioEventLoopGroup();
workerGroup = new NioEventLoopGroup();
ServerBootstrap bootstrap = new ServerBootstrap()
.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class)
.option(ChannelOption.SO_REUSEADDR, true)
.option(ChannelOption.SO_KEEPALIVE, true)
.option(ChannelOption.TCP_NODELAY, true)
.option(ChannelOption.SO_SNDBUF, Controller.SEND_BUFFER_SIZE);
OFChannelInitializer initializer = new OFChannelInitializer(
this,
this,
debugCounterService,
floodlightProvider.getTimer(),
ofBitmaps,
defaultFactory,
keyStore,
keyStorePassword);
bootstrap.childHandler(initializer);
cg = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);
Set<InetSocketAddress> addrs = new HashSet<InetSocketAddress>();
if (floodlightProvider.getOFAddresses().isEmpty()) {
cg.add(bootstrap.bind(new InetSocketAddress(InetAddress.getByAddress(IPv4Address.NONE.getBytes()), floodlightProvider.getOFPort().getPort())).channel());
} else {
for (IPv4Address ip : floodlightProvider.getOFAddresses()) {
addrs.add(new InetSocketAddress(InetAddress.getByAddress(ip.getBytes()), floodlightProvider.getOFPort().getPort()));
}
}
for (InetSocketAddress sa : addrs) {
cg.add(bootstrap.bind(sa).channel());
log.info("Listening for switch connections on {}", sa);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例9: bootstrapNetty
import io.netty.channel.group.DefaultChannelGroup; //导入方法依赖的package包/类
/**
* Bootstraps netty, the server that handles all openflow connections
*/
public void bootstrapNetty() {
try {
bossGroup = new NioEventLoopGroup();
workerGroup = new NioEventLoopGroup();
ServerBootstrap bootstrap = new ServerBootstrap()
.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class)
.option(ChannelOption.SO_REUSEADDR, true)
.option(ChannelOption.SO_KEEPALIVE, true)
.option(ChannelOption.TCP_NODELAY, true)
.option(ChannelOption.SO_SNDBUF, Controller.SEND_BUFFER_SIZE);
OFChannelInitializer initializer = new OFChannelInitializer(
this,
this,
debugCounterService,
floodlightProvider.getTimer(),
ofBitmaps,
defaultFactory,
keyStore,
keyStorePassword);
bootstrap.childHandler(initializer);
cg = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);
Set<InetSocketAddress> addrs = new HashSet<InetSocketAddress>();
if (floodlightProvider.getOFAddresses().isEmpty()) {
cg.add(bootstrap.bind(new InetSocketAddress(InetAddress.getByAddress(IPv4Address.NONE.getBytes()), floodlightProvider.getOFPort().getPort())).channel());
} else {
for (IPv4Address ip : floodlightProvider.getOFAddresses()) {
addrs.add(new InetSocketAddress(InetAddress.getByAddress(ip.getBytes()), floodlightProvider.getOFPort().getPort()));
}
}
for (InetSocketAddress sa : addrs) {
cg.add(bootstrap.bind(sa).channel());
log.info("Listening for switch connections on {}", sa);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}