[英]Implementing a bootstrap pool in Netty 4.x
我正在尝试使用netty 4.x实现异步redis客户端。 阅读了netty的源代码和文档之后,使用与我在ServerBootstrap中用作childEventLoop的NioEventLoop [s]似乎更有效。 问题是似乎我需要将这样的RedisClientPool
附加到每个NioChildEventLoop
,否则我无法共享那些缓存的连接,但是EventLoop不是AttributeMap
。 我尝试扩展NioEventLoop
并覆盖newChild以使用AttributeMap
字段返回自定义NioChildEventLoop
(只是复制了代码,因为它被声明为final),因此我可以通过它共享一些对象。
public class NioChildEventLoopWithAttributeMap extends SingleThreadEventLoop {
private AttributeMap map = new DefaultAttributeMap();
public <T> Attribute<T> attr(AttributeKey<T> key) {
return map.attr(key);
}
//.... omit the copied codes
}
和
public class CustomNioEventLoop extends NioEventLoop {
public EventExecutor newChild() {
return new NioChildEventLoopWithAttributeMap();
}
}
但是在AbstractChannel
它检查EventLoop
protected boolean isCompatible(EventLoop loop) {
return loop instanceof NioChildEventLoop;
}
我不知道该怎么办,有什么建议吗? 对不起,我的英语不好。
仅作记录,github上有一个用于netty4和netty3的redis编解码器:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.