本文整理汇总了Java中io.netty.channel.group.ChannelGroup.add方法的典型用法代码示例。如果您正苦于以下问题:Java ChannelGroup.add方法的具体用法?Java ChannelGroup.add怎么用?Java ChannelGroup.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.netty.channel.group.ChannelGroup
的用法示例。
在下文中一共展示了ChannelGroup.add方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: closeConnectionAsync
import io.netty.channel.group.ChannelGroup; //导入方法依赖的package包/类
@Override
public CompletionStage<NodeConnectionReport> closeConnectionAsync(
SocketAddress connection, CloseType type) {
Optional<Channel> channel =
this.clientChannelGroup
.stream()
.filter(c -> c.remoteAddress().equals(connection))
.findFirst();
if (channel.isPresent()) {
ChannelGroup channelGroup = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);
channelGroup.add(channel.get());
ClusterConnectionReport clusterReport = new ClusterConnectionReport(getCluster().getId());
NodeConnectionReport report =
clusterReport.addNode(this, Collections.singletonList(connection), getAddress());
return closeChannelGroup(channelGroup, type).thenApply(f -> report);
} else {
CompletableFuture<NodeConnectionReport> failedFuture = new CompletableFuture<>();
failedFuture.completeExceptionally(new IllegalArgumentException("Not found"));
return failedFuture;
}
}
示例2: channelActive
import io.netty.channel.group.ChannelGroup; //导入方法依赖的package包/类
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
Channel channel = ctx.channel();
ChannelGroup channelGroup = getServerImpl().getChannelGroup();
ctx.channel().attr(ServerImpl.REQUEST_CONNECTION_ID).set(channel.id().asLongText());
channelGroup.add(channel);
super.channelActive(ctx);
}
示例3: makeMessageInfoToDevice
import io.netty.channel.group.ChannelGroup; //导入方法依赖的package包/类
/**
* 实际发送消息方法
*
* @param pushMessage
* @param status
* @param messageInfo
* @param deviceId
* @return
*/
private MessagePushedInfo makeMessageInfoToDevice(ChannelGroup mchannels, MessageInfo messageInfo, DeviceInfo deviceInfo) {
// System.out.println("makeMessageInfoToDevice come in!");
// 获取设备消息发送对象
MessagePushedInfo messagePushedInfo = getMessagePushedInfo(messageInfo, deviceInfo);
if (messagePushedInfo != null) {
// 发送消息
if (deviceInfo != null && deviceInfo.getIsOnline() == DEVICE_ONLINE_YES) {
// 如果设备在线 则添加发送通道
ChannelDeviceInfo channelDeviceInfo = this.getChannelDeviceInfoFromCache(deviceInfo.getDeviceId());
// System.out.println("makeMessageInfoToDevice channelDeviceInfo=" + channelDeviceInfo);
Channel channel = channelDeviceInfo == null ? null : channelDeviceInfo.getChannel();
if (channel != null && channel.isWritable()) {
mchannels.add(channel);
} else {
return null;
}
}
}
return messagePushedInfo;
}
示例4: runTest
import io.netty.channel.group.ChannelGroup; //导入方法依赖的package包/类
private static void runTest(ThreadPerChannelEventLoopGroup loopGroup) throws InterruptedException {
int taskCount = 100;
EventExecutor testExecutor = new TestEventExecutor();
ChannelGroup channelGroup = new DefaultChannelGroup(testExecutor);
while (taskCount-- > 0) {
Channel channel = new EmbeddedChannel(NOOP_HANDLER);
loopGroup.register(channel, new DefaultChannelPromise(channel, testExecutor));
channelGroup.add(channel);
}
channelGroup.close().sync();
loopGroup.shutdownGracefully(100, 200, TimeUnit.MILLISECONDS).sync();
assertTrue(loopGroup.isTerminated());
}
示例5: runTest
import io.netty.channel.group.ChannelGroup; //导入方法依赖的package包/类
private static void runTest(ThreadPerChannelEventLoopGroup loopGroup) throws InterruptedException {
int taskCount = 100;
EventExecutor testExecutor = new TestEventExecutor();
ChannelGroup channelGroup = new DefaultChannelGroup(testExecutor);
while (taskCount-- > 0) {
Channel channel = new EmbeddedChannel(NOOP_HANDLER);
channel.unsafe().register(new DefaultChannelPromise(channel, testExecutor));
channelGroup.add(channel);
}
channelGroup.close().sync();
loopGroup.shutdownGracefully(100, 200, TimeUnit.MILLISECONDS).sync();
assertTrue(loopGroup.isTerminated());
}