netty - Netty 4 ChannelGroup.find(ChannelId id)但没有找到(String/Integer id)
问题描述
当我从 Netty 3 升级到 Netty 4 时,我发现 ChannelGroup 有 find(Integer id) API 来获取 Netty3 中的 Channel,而它在 Netty 4 中更改为 find(ChannelId id)。当我从数据库中找到一个 id 时,我可以'在 Netty 4 中找不到任何 API 来通过 id 和 String/Integer 类型参数获取 Channel。也不能使用 String/Integer id 来查找 ChannelId。提前致谢!
我在网上找了很久。有什么想法吗?Netty 4 使用 ConcurrentMap 来维护 channelGroup 中的通道。如果无法解决,现在我想自己维护一个。
Netty3
public interface ChannelGroup extends Set<Channel>, Comparable<ChannelGroup> {
Channel find(Integer var1);
// ...
}
Netty4
public interface ChannelGroup extends Set<Channel>, Comparable<ChannelGroup> {
Channel find(ChannelId var1);
// ...
}
我希望它有像 ChannelGroup.find(String/Integer id) 这样的 API 来获取 Netty 4 中的 Channel 或使用 id 来获取 ChannelId。
解决方案
在 Netty 4.x 中,Channel id 不仅仅是整数,以减少冲突的风险。你ChannelId
就是Serializable
这样,你可以从一个byte[]
tho 重新创建它。
推荐阅读
- r - 删除嵌套列表中的数据框并在 R 中的同一嵌套列表中添加另一个数据框
- angular - 角 | PrimeNG | Chart.js | 格式化标签中的数字
- pytorch - 训练模型时训练损失完全没有变化
- reactjs - React-Native 如何使用过滤器修改数组中的对象?
- arrays - 在 3 个(用户填充的)数组(可能为空)中找到最大值
- python - 如何 pd.GroupBy 和 pd.Cut 在相同的结果?
- javascript - 数组减少意外使用逗号运算符无序列
- spring-integration - 是否可以使轮询器(或 PollableMessageSource)将消息作为列表轮询?
- ios13 - UILabel - 与 iOS 13 相比,iOS 14 的一些单词将换行
- python - 总结 pandas DataFrame