當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。