use of com.zx.sms.connect.manager.cmpp.CMPPServerEndpointEntity in project SMSGate by Lihuanghe.
the class AbstractEndpointConnector method bindHandler.
/**
* 连接建立成功后要加载的channelHandler
*/
protected void bindHandler(ChannelPipeline pipe, EndpointEntity entity) {
if (entity instanceof CMPPServerEndpointEntity) {
return;
}
pipe.addFirst("socketLog", new LoggingHandler(String.format(GlobalConstance.loggerNamePrefix, entity.getId()), LogLevel.TRACE));
// 调用子类的bind方法
doBindHandler(pipe, entity);
pipe.addAfter(GlobalConstance.codecName, "msgLog", new MessageLogHandler(entity));
List<BusinessHandlerInterface> handlers = entity.getBusinessHandlerSet();
if (handlers != null && handlers.size() > 0) {
for (BusinessHandlerInterface handler : handlers) {
if (handler instanceof AbstractBusinessHandler) {
AbstractBusinessHandler buziHandler = (AbstractBusinessHandler) handler;
buziHandler.setEndpointEntity(entity);
if (buziHandler.isSharable()) {
pipe.addLast(buziHandler.name(), buziHandler);
} else {
AbstractBusinessHandler cloned = null;
try {
cloned = buziHandler.clone();
} catch (CloneNotSupportedException e) {
logger.error("handlers is not shareable and not implements Cloneable", e);
}
if (cloned != null) {
cloned.setEndpointEntity(entity);
pipe.addLast(buziHandler.name(), cloned);
logger.info("handlers is not shareable . clone it success. {}", cloned);
}
}
} else {
handler.setEndpointEntity(entity);
pipe.addLast(handler.name(), handler);
logger.info("add share handlers . {}", handler);
}
}
}
// 黑洞处理,丢弃所有消息
pipe.addLast("BlackHole", GlobalConstance.blackhole);
}
Aggregations