您好,登录后才能下订单哦!
本篇内容介绍了“netty channelPool连接池怎么使用”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
如果流数据推送【持续不断的数据 向服务端进行推送 没有必要使用channelPool。也没有必要释放channel】
核心接口:ChannelPool
public ChannelPool newPool(Bootstrap bootstrap) { return new FixedChannelPool(bootstrap, iridiumClientChannelHandler, protocolOptions.getMaxConnections()); }}
核心实现类:
public class FixedChannelPool extends SimpleChannelPool
一个抽象类
public abstract class AbstractChannelPoolHandler implements ChannelPoolHandler { @Override public void channelAcquired(@SuppressWarnings("unused") Channel ch) throws Exception { // NOOP } @Override public void channelReleased(@SuppressWarnings("unused") Channel ch) throws Exception { // NOOP }}
Channel.close() 不是断开连接 是 从eventLoop 移除 注销
关于channelPool 健康检查:仅仅是获取连接前
ChannelHealthChecker 这个类可以判定连接池中的chanel 是否有效
public interface ChannelPoolHandler {
/**
* Called once a {@link Channel} was released by calling {@link ChannelPool#release(Channel)} or
* {@link ChannelPool#release(Channel, Promise)}.
*
* This method will be called by the {@link EventLoop} of the {@link Channel}.
*/
void channelReleased(Channel ch) throws Exception;
/**
* Called once a {@link Channel} was acquired by calling {@link ChannelPool#acquire()} or
* {@link ChannelPool#acquire(Promise)}.
*
* This method will be called by the {@link EventLoop} of the {@link Channel}.
*/
void channelAcquired(Channel ch) throws Exception;
/**
* Called once a new {@link Channel} is created in the {@link ChannelPool}.
*
* This method will be called by the {@link EventLoop} of the {@link Channel}.
*/
void channelCreated(Channel ch) throws Exception;
}
/* 当链接创建的时候添加channelhandler,只有当channel不足时会创建,但不会超过限制的最大channel数*/
@Override
protected void initChannel(Channel ch) throws Exception {
channelPoolHandler.channelCreated(ch);
}
}
“netty channelPool连接池怎么使用”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。