Search in sources :

Example 1 with CMPPServerEndpointEntity

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);
}
Also used : CMPPServerEndpointEntity(com.zx.sms.connect.manager.cmpp.CMPPServerEndpointEntity) LoggingHandler(io.netty.handler.logging.LoggingHandler) BusinessHandlerInterface(com.zx.sms.handler.api.BusinessHandlerInterface) MessageLogHandler(com.zx.sms.handler.MessageLogHandler) AbstractBusinessHandler(com.zx.sms.handler.api.AbstractBusinessHandler)

Aggregations

CMPPServerEndpointEntity (com.zx.sms.connect.manager.cmpp.CMPPServerEndpointEntity)1 MessageLogHandler (com.zx.sms.handler.MessageLogHandler)1 AbstractBusinessHandler (com.zx.sms.handler.api.AbstractBusinessHandler)1 BusinessHandlerInterface (com.zx.sms.handler.api.BusinessHandlerInterface)1 LoggingHandler (io.netty.handler.logging.LoggingHandler)1