From cbc1f9db3d796683d88d6d30df3659984dfbeda3 Mon Sep 17 00:00:00 2001
From: webapp <webapp@home-server.attdns.com>
Date: 星期一, 30 九月 2019 22:56:12 +0800
Subject: [PATCH] 取消java110-common jar包,提升为CommonService服务,将之前的Java110-common内容变更为Java110-utils包
---
java110-event/src/main/java/com/java110/event/service/api/ServiceDataFlowEventPublishing.java | 110 +++++++++++++++++++++++++++++-------------------------
1 files changed, 59 insertions(+), 51 deletions(-)
diff --git a/java110-event/src/main/java/com/java110/event/service/api/ServiceDataFlowEventPublishing.java b/java110-event/src/main/java/com/java110/event/service/api/ServiceDataFlowEventPublishing.java
index f8d1aea..2e34026 100644
--- a/java110-event/src/main/java/com/java110/event/service/api/ServiceDataFlowEventPublishing.java
+++ b/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,59 +29,63 @@
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>>();
/**
* 娣诲姞 渚﹀惉锛岃繖涓彧鏈夊惎鍔ㄦ椂锛屽崟绾跨▼ 澶勭悊锛屾墍浠ユ槸绾跨▼瀹夊叏鐨�
+ *
* @param listener
*/
- public static void addListener(String listener){
+ public static void addListener(String listener) {
listeners.add(listener);
}
/**
* 鑾峰彇渚﹀惉锛堝叏閮ㄤ睛鍚級
+ *
* @return
*/
- public static List<String> getListeners(){
+ public static List<String> getListeners() {
return listeners;
}
/**
* 鏍规嵁鏄惁瀹炵幇浜嗘煇涓帴鍙o紝杩斿洖渚﹀惉
+ *
* @param serviceCode
- * @since 1.8
* @return
+ * @since 1.8
*/
- public static List<ServiceDataFlowListener> getListeners(String serviceCode,String httpMethod){
+ public static List<ServiceDataFlowListener> getListeners(String serviceCode, String httpMethod) {
- Assert.hasLength(serviceCode,"鑾峰彇闇�瑕佸彂甯冪殑浜嬩欢澶勭悊渚﹀惉鏃讹紝浼犻�掍簨浠朵负绌猴紝璇锋鏌�");
+ Assert.hasLength(serviceCode, "鑾峰彇闇�瑕佸彂甯冪殑浜嬩欢澶勭悊渚﹀惉鏃讹紝浼犻�掍簨浠朵负绌猴紝璇锋鏌�");
- String needCachedServiceCode = serviceCode+httpMethod;
+ String needCachedServiceCode = serviceCode + httpMethod;
//鍏堜粠缂撳瓨涓幏鍙栵紝涓轰簡鎻愬崌鏁堢巼
- if(cacheListenersMap.containsKey(needCachedServiceCode)){
+ if (cacheListenersMap.containsKey(needCachedServiceCode)) {
return cacheListenersMap.get(needCachedServiceCode);
}
List<ServiceDataFlowListener> dataFlowListeners = new ArrayList<ServiceDataFlowListener>();
- for(String listenerBeanName : getListeners()){
- ServiceDataFlowListener listener = ApplicationContextFactory.getBean(listenerBeanName,ServiceDataFlowListener.class);
- if(serviceCode.equals(listener.getServiceCode())
- && listener.getHttpMethod() == HttpMethod.valueOf(httpMethod)){
+ for (String listenerBeanName : getListeners()) {
+ ServiceDataFlowListener listener = ApplicationContextFactory.getBean(listenerBeanName, ServiceDataFlowListener.class);
+ if (serviceCode.equals(listener.getServiceCode())
+ && listener.getHttpMethod() == HttpMethod.valueOf(httpMethod)) {
dataFlowListeners.add(listener);
}
//鐗规畩澶勭悊 閫忎紶绫绘帴鍙�
- if(ServiceCodeConstant.SERVICE_CODE_DO_SERVICE_TRANSFER.equals(listener.getServiceCode())){
+ if (ServiceCodeConstant.SERVICE_CODE_DO_SERVICE_TRANSFER.equals(listener.getServiceCode())
+ && ServiceCodeConstant.SERVICE_CODE_DO_SERVICE_TRANSFER.equals(serviceCode)) {
dataFlowListeners.add(listener);
}
}
@@ -91,44 +93,50 @@
//杩欓噷鎺掑簭
DataFlowListenerOrderComparator.sort(dataFlowListeners);
+
//灏嗘暟鎹斁鍏ョ紦瀛樹腑
- cacheListenersMap.put(needCachedServiceCode,dataFlowListeners);
+ if (dataFlowListeners.size() > 0) {
+ cacheListenersMap.put(needCachedServiceCode, dataFlowListeners);
+ }
return dataFlowListeners;
}
/**
* 鍙戝竷浜嬩欢
+ *
* @param dataFlowContext
*/
- public static void multicastEvent(DataFlowContext dataFlowContext,AppService appService) throws BusinessException{
- Assert.notNull(dataFlowContext.getServiceCode(),"褰撳墠娌℃湁鍙鐞嗙殑涓氬姟淇℃伅锛�");
- multicastEvent(dataFlowContext.getServiceCode(),dataFlowContext,appService,null);
+ public static void multicastEvent(DataFlowContext dataFlowContext, AppService appService) throws BusinessException {
+ Assert.notNull(dataFlowContext.getServiceCode(), "褰撳墠娌℃湁鍙鐞嗙殑涓氬姟淇℃伅锛�");
+ multicastEvent(dataFlowContext.getServiceCode(), dataFlowContext, appService, null);
}
/**
* 鍙戝竷浜嬩欢
+ *
* @param serviceCode
* @param dataFlowContext
*/
- public static void multicastEvent(String serviceCode,DataFlowContext dataFlowContext,AppService appService) throws BusinessException{
- multicastEvent(serviceCode,dataFlowContext,appService,null);
+ public static void multicastEvent(String serviceCode, DataFlowContext dataFlowContext, AppService appService) throws BusinessException {
+ multicastEvent(serviceCode, dataFlowContext, appService, null);
}
/**
* 鍙戝竷浜嬩欢
+ *
* @param serviceCode
* @param dataFlowContext 杩欎釜璁㈠崟淇℃伅锛屼互渚夸簬 渚﹀惉閭h竟闇�瑕佺敤
*/
- public static void multicastEvent(String serviceCode, DataFlowContext dataFlowContext, AppService appService, String asyn) throws BusinessException{
+ public static void multicastEvent(String serviceCode, DataFlowContext dataFlowContext, AppService appService, String asyn) throws BusinessException {
try {
- ServiceDataFlowEvent targetDataFlowEvent = new ServiceDataFlowEvent(serviceCode,dataFlowContext,appService);
+ ServiceDataFlowEvent targetDataFlowEvent = new ServiceDataFlowEvent(serviceCode, dataFlowContext, appService);
- multicastEvent(serviceCode,targetDataFlowEvent, asyn);
- }catch (Exception e){
- logger.error("鍙戝竷渚﹀惉澶辫触锛屽け璐ュ師鍥犱负锛�",e);
- throw new BusinessException(ResponseConstant.RESULT_CODE_INNER_ERROR,"鍙戝竷渚﹀惉澶辫触锛屽け璐ュ師鍥犱负锛�"+e.getMessage());
+ multicastEvent(serviceCode, targetDataFlowEvent, asyn);
+ } catch (Exception e) {
+ logger.error("鍙戝竷渚﹀惉澶辫触锛屽け璐ュ師鍥犱负锛�", e);
+ throw new BusinessException(ResponseConstant.RESULT_CODE_INNER_ERROR, "鍙戝竷渚﹀惉澶辫触锛屽け璐ュ師鍥犱负锛�" + e.getMessage());
}
}
@@ -136,20 +144,21 @@
/**
* 鍙戝竷浜嬩欢
+ *
* @param event
- * @param asyn A 琛ㄧず寮傛澶勭悊
+ * @param asyn A 琛ㄧず寮傛澶勭悊
*/
- public static void multicastEvent(String serviceCode,final ServiceDataFlowEvent event, String asyn) {
+ public static void multicastEvent(String serviceCode, final ServiceDataFlowEvent event, String asyn) {
String httpMethod = event.getDataFlowContext().getRequestCurrentHeaders().get(CommonConstant.HTTP_METHOD);
- List<ServiceDataFlowListener> listeners = getListeners(serviceCode,httpMethod);
+ List<ServiceDataFlowListener> listeners = getListeners(serviceCode, httpMethod);
//杩欓噷鍒ゆ柇 serviceCode + httpMethod 鐨勪睛鍚紝濡傛灉娌℃湁娉ㄥ唽鐩存帴鎶ラ敊銆�
- if(listeners == null || listeners.size() == 0){
+ if (listeners == null || listeners.size() == 0) {
throw new ListenerExecuteException(ResponseConstant.RESULT_CODE_ERROR,
- "鏈嶅姟銆�" + serviceCode + "銆戣皟鐢ㄦ柟寮忋��"+httpMethod+"銆戝綋鍓嶄笉鏀寔");
+ "鏈嶅姟銆�" + serviceCode + "銆戣皟鐢ㄦ柟寮忋��" + httpMethod + "銆戝綋鍓嶄笉鏀寔");
}
for (final ServiceDataFlowListener listener : listeners) {
- if(CommonConstant.PROCESS_ORDER_ASYNCHRONOUS.equals(asyn)){ //寮傛澶勭悊
+ if (CommonConstant.PROCESS_ORDER_ASYNCHRONOUS.equals(asyn)) { //寮傛澶勭悊
Executor executor = getTaskExecutor();
executor.execute(new Runnable() {
@@ -159,8 +168,7 @@
}
});
break;
- }
- else {
+ } else {
invokeListener(listener, event);
break;
}
@@ -168,12 +176,11 @@
}
-
/**
* Return the current task executor for this multicaster.
*/
protected static synchronized Executor getTaskExecutor() {
- if(taskExecutor == null) {
+ if (taskExecutor == null) {
taskExecutor = Executors.newFixedThreadPool(DEFAULT_THREAD_NUM);
}
return taskExecutor;
@@ -181,17 +188,18 @@
/**
* Invoke the given listener with the given event.
+ *
* @param listener the ApplicationListener to invoke
- * @param event the current event to propagate
+ * @param event the current event to propagate
* @since 4.1
*/
@SuppressWarnings({"unchecked", "rawtypes"})
protected static void invokeListener(ServiceDataFlowListener listener, ServiceDataFlowEvent event) {
try {
listener.soService(event);
- }catch (Exception e){
- LoggerEngine.error("鍙戝竷渚﹀惉澶辫触",e);
- throw new RuntimeException("鍙戝竷渚﹀惉澶辫触,"+listener+ event + e);
+ } catch (Exception e) {
+ LoggerEngine.error("鍙戝竷渚﹀惉澶辫触", e);
+ throw new RuntimeException("鍙戝竷渚﹀惉澶辫触," + listener + event + e);
}
}
}
--
Gitblit v1.8.0