| | |
| | | package com.java110.core.event.cmd; |
| | | |
| | | import com.java110.core.annotation.Java110Cmd; |
| | | import com.java110.core.context.DataFlowContext; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.java110.core.context.ICmdDataFlowContext; |
| | | import com.java110.core.event.center.DataFlowListenerOrderComparator; |
| | | import com.java110.core.event.service.api.ServiceDataFlowEvent; |
| | | import com.java110.core.event.service.api.ServiceDataFlowListener; |
| | | import com.java110.core.log.LoggerFactory; |
| | | import com.java110.dto.CmdListenerDto; |
| | | import com.java110.entity.center.AppService; |
| | | 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.CmdException; |
| | | import com.java110.utils.exception.ListenerExecuteException; |
| | |
| | | import com.java110.utils.log.LoggerEngine; |
| | | import com.java110.utils.util.Assert; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.http.HttpMethod; |
| | | |
| | | import java.lang.annotation.Annotation; |
| | | import java.text.ParseException; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | |
| | | |
| | | List<ServiceCmdListener> cmdListeners = new ArrayList<ServiceCmdListener>(); |
| | | for (CmdListenerDto listenerBean : getListeners()) { |
| | | //ServiceCmdListener listener = ApplicationContextFactory.getBean(listenerBean.getBeanName(), ServiceCmdListener.class); |
| | | ServiceCmdListener listener = ApplicationContextFactory.getBean(listenerBean.getBeanName(), ServiceCmdListener.class); |
| | | if(listenerBean.getServiceCode().equals(serviceCode)) { |
| | | if (listenerBean.getServiceCode().equals(serviceCode)) { |
| | | cmdListeners.add(listener); |
| | | } |
| | | } |
| | |
| | | * @param dataFlowContext |
| | | */ |
| | | public static void multicastEvent(String serviceCode, ICmdDataFlowContext dataFlowContext) throws BusinessException { |
| | | multicastEvent(serviceCode, dataFlowContext, null); |
| | | multicastEvent(serviceCode, dataFlowContext, null); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @param event |
| | | * @param asyn A 表示异步处理 |
| | | */ |
| | | public static void multicastEvent(String serviceCode, final CmdEvent event, String asyn) { |
| | | public static void multicastEvent(String serviceCode, final CmdEvent event, String asyn) throws ParseException { |
| | | List<ServiceCmdListener> listeners = getListeners(serviceCode); |
| | | //这里判断 serviceCode + httpMethod 的侦听,如果没有注册直接报错。 |
| | | if (listeners == null || listeners.size() == 0) { |
| | |
| | | executor.execute(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | invokeListener(listener, event); |
| | | try { |
| | | invokeListener(listener, event); |
| | | } catch (ParseException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | }); |
| | | break; |
| | |
| | | * @since 4.1 |
| | | */ |
| | | @SuppressWarnings({"unchecked", "rawtypes"}) |
| | | protected static void invokeListener(ServiceCmdListener listener, CmdEvent event) { |
| | | protected static void invokeListener(ServiceCmdListener listener, CmdEvent event) throws ParseException { |
| | | try { |
| | | listener.cmd(event); |
| | | } catch (CmdException e) { |
| | | // //这里处理业务逻辑数据 |
| | | ICmdDataFlowContext dataFlowContext = event.getCmdDataFlowContext(); |
| | | //获取请求数据 |
| | | JSONObject reqJson = dataFlowContext.getReqJson(); |
| | | |
| | | logger.debug("API服务 --- 请求参数为:{}", reqJson.toJSONString()); |
| | | |
| | | listener.validate(event, dataFlowContext, reqJson); |
| | | |
| | | listener.doCmd(event, dataFlowContext, reqJson); |
| | | |
| | | //logger.debug("API服务 --- 返回报文信息:{}", dataFlowContext.getResponseEntity()); |
| | | // listener.cmd(event); |
| | | } catch (CmdException | ParseException e) { |
| | | LoggerEngine.error("发布侦听失败", e); |
| | | throw e; |
| | | } |
| | | } |
| | | |
| | | |
| | | } |