当前位置: 首页>>代码示例>>Java>>正文


Java ChannelGroup.add方法代码示例

本文整理汇总了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;
  }
}
 
开发者ID:datastax,项目名称:simulacron,代码行数:24,代码来源:BoundNode.java

示例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);
}
 
开发者ID:caricah,项目名称:iotracah,代码行数:11,代码来源:ServerHandler.java

示例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;
}
 
开发者ID:maofw,项目名称:netty_push_server,代码行数:30,代码来源:ApplicationContext.java

示例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());
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:14,代码来源:ThreadPerChannelEventLoopGroupTest.java

示例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());
}
 
开发者ID:nathanchen,项目名称:netty-netty-5.0.0.Alpha1,代码行数:14,代码来源:ThreadPerChannelEventLoopGroupTest.java


注:本文中的io.netty.channel.group.ChannelGroup.add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。