mrzcc
2020-03-06 ecdac8a738f254db2b2ea28cbe3248f7a6a7eb2b
java110-event/src/main/java/com/java110/event/service/api/ServiceDataFlowEventPublishing.java
@@ -1,18 +1,16 @@
package com.java110.event.service.api;
import com.java110.common.constant.CommonConstant;
import com.java110.common.constant.ResponseConstant;
import com.java110.common.constant.ServiceCodeConstant;
import com.java110.common.exception.BusinessException;
import com.java110.common.exception.ListenerExecuteException;
import com.java110.common.factory.ApplicationContextFactory;
import com.java110.common.log.LoggerEngine;
import com.java110.common.util.Assert;
import com.java110.utils.constant.CommonConstant;
import com.java110.utils.constant.ResponseConstant;
import com.java110.utils.constant.ServiceCodeConstant;
import com.java110.utils.exception.BusinessException;
import com.java110.utils.exception.ListenerExecuteException;
import com.java110.utils.factory.ApplicationContextFactory;
import com.java110.utils.log.LoggerEngine;
import com.java110.utils.util.Assert;
import com.java110.core.context.DataFlowContext;
import com.java110.entity.center.AppService;
import com.java110.event.center.DataFlowListenerOrderComparator;
import com.java110.event.service.BusinessServiceDataFlowEvent;
import com.java110.event.service.BusinessServiceDataFlowListener;
import org.springframework.http.HttpMethod;
import java.util.ArrayList;
@@ -31,17 +29,17 @@
    private static Executor taskExecutor;
    //默认 线程数 100
    private final static int DEFAULT_THREAD_NUM = 100;
    private static final int DEFAULT_THREAD_NUM = 100;
    /**
     * 保存侦听实例信息,一般启动时加载
     */
    private final static List<String> listeners = new ArrayList<String>();
    private static final List<String> listeners = new ArrayList<String>();
    /**
     * 根据 事件类型查询侦听
     */
    private final static Map<String, List<ServiceDataFlowListener>> cacheListenersMap = new HashMap<String, List<ServiceDataFlowListener>>();
    private static final Map<String, List<ServiceDataFlowListener>> cacheListenersMap = new HashMap<String, List<ServiceDataFlowListener>>();
    /**
     * 添加 侦听,这个只有启动时,单线程 处理,所以是线程安全的
@@ -95,8 +93,11 @@
        //这里排序
        DataFlowListenerOrderComparator.sort(dataFlowListeners);
        //将数据放入缓存中
        cacheListenersMap.put(needCachedServiceCode, dataFlowListeners);
        if (dataFlowListeners.size() > 0) {
            cacheListenersMap.put(needCachedServiceCode, dataFlowListeners);
        }
        return dataFlowListeners;
    }
@@ -135,7 +136,7 @@
            multicastEvent(serviceCode, targetDataFlowEvent, asyn);
        } catch (Exception e) {
            logger.error("发布侦听失败,失败原因为:", e);
            throw new BusinessException(ResponseConstant.RESULT_CODE_INNER_ERROR, "发布侦听失败,失败原因为:" + e.getMessage());
            throw new BusinessException(ResponseConstant.RESULT_CODE_INNER_ERROR, e.getMessage());
        }
    }
@@ -198,7 +199,7 @@
            listener.soService(event);
        } catch (Exception e) {
            LoggerEngine.error("发布侦听失败", e);
            throw new RuntimeException("发布侦听失败," + listener + event + e);
            throw new RuntimeException(e.getMessage());
        }
    }
}