Commit 80bfd9ce026e67dd2eb86c519b5b1b70e3cc7d12

Authored by 648540858
1 parent f559e6a3

使用@Async多线程处理sip消息

src/main/java/com/genersoft/iot/vmp/gb28181/transmit/SIPProcessorObserver.java
@@ -36,9 +36,9 @@ public class SIPProcessorObserver implements ISIPProcessorObserver { @@ -36,9 +36,9 @@ public class SIPProcessorObserver implements ISIPProcessorObserver {
36 @Autowired 36 @Autowired
37 private SipSubscribe sipSubscribe; 37 private SipSubscribe sipSubscribe;
38 38
39 - @Autowired  
40 - @Qualifier(value = "taskExecutor")  
41 - private ThreadPoolTaskExecutor poolTaskExecutor; 39 +// @Autowired
  40 +// @Qualifier(value = "taskExecutor")
  41 +// private ThreadPoolTaskExecutor poolTaskExecutor;
42 42
43 /** 43 /**
44 * 添加 request订阅 44 * 添加 request订阅
@@ -71,17 +71,15 @@ public class SIPProcessorObserver implements ISIPProcessorObserver { @@ -71,17 +71,15 @@ public class SIPProcessorObserver implements ISIPProcessorObserver {
71 * @param requestEvent RequestEvent事件 71 * @param requestEvent RequestEvent事件
72 */ 72 */
73 @Override 73 @Override
  74 + @Async
74 public void processRequest(RequestEvent requestEvent) { 75 public void processRequest(RequestEvent requestEvent) {
75 -  
76 - poolTaskExecutor.execute(() -> {  
77 - String method = requestEvent.getRequest().getMethod();  
78 - ISIPRequestProcessor sipRequestProcessor = requestProcessorMap.get(method);  
79 - if (sipRequestProcessor == null) {  
80 - logger.warn("不支持方法{}的request", method);  
81 - return;  
82 - }  
83 - requestProcessorMap.get(method).process(requestEvent);  
84 - }); 76 + String method = requestEvent.getRequest().getMethod();
  77 + ISIPRequestProcessor sipRequestProcessor = requestProcessorMap.get(method);
  78 + if (sipRequestProcessor == null) {
  79 + logger.warn("不支持方法{}的request", method);
  80 + return;
  81 + }
  82 + requestProcessorMap.get(method).process(requestEvent);
85 83
86 } 84 }
87 85
@@ -90,55 +88,45 @@ public class SIPProcessorObserver implements ISIPProcessorObserver { @@ -90,55 +88,45 @@ public class SIPProcessorObserver implements ISIPProcessorObserver {
90 * @param responseEvent responseEvent事件 88 * @param responseEvent responseEvent事件
91 */ 89 */
92 @Override 90 @Override
  91 + @Async
93 public void processResponse(ResponseEvent responseEvent) { 92 public void processResponse(ResponseEvent responseEvent) {
94 logger.debug(responseEvent.getResponse().toString()); 93 logger.debug(responseEvent.getResponse().toString());
95 -// CSeqHeader cseqHeader = (CSeqHeader) responseEvent.getResponse().getHeader(CSeqHeader.NAME);  
96 -// String method = cseqHeader.getMethod();  
97 -// ISIPResponseProcessor sipRequestProcessor = responseProcessorMap.get(method);  
98 -// if (sipRequestProcessor == null) {  
99 -// logger.warn("不支持方法{}的response", method);  
100 -// return;  
101 -// }  
102 -// sipRequestProcessor.process(responseEvent);  
103 -  
104 - poolTaskExecutor.execute(() -> {  
105 - Response response = responseEvent.getResponse();  
106 - logger.debug(responseEvent.getResponse().toString());  
107 - int status = response.getStatusCode();  
108 - if (((status >= 200) && (status < 300)) || status == 401) { // Success! 94 + Response response = responseEvent.getResponse();
  95 + logger.debug(responseEvent.getResponse().toString());
  96 + int status = response.getStatusCode();
  97 + if (((status >= 200) && (status < 300)) || status == 401) { // Success!
109 // ISIPResponseProcessor processor = processorFactory.createResponseProcessor(evt); 98 // ISIPResponseProcessor processor = processorFactory.createResponseProcessor(evt);
110 - CSeqHeader cseqHeader = (CSeqHeader) responseEvent.getResponse().getHeader(CSeqHeader.NAME);  
111 - String method = cseqHeader.getMethod();  
112 - ISIPResponseProcessor sipRequestProcessor = responseProcessorMap.get(method);  
113 - if (sipRequestProcessor != null) {  
114 - sipRequestProcessor.process(responseEvent);  
115 - }  
116 - if (responseEvent.getResponse() != null && sipSubscribe.getOkSubscribesSize() > 0 ) {  
117 - CallIdHeader callIdHeader = (CallIdHeader)responseEvent.getResponse().getHeader(CallIdHeader.NAME);  
118 - if (callIdHeader != null) {  
119 - SipSubscribe.Event subscribe = sipSubscribe.getOkSubscribe(callIdHeader.getCallId());  
120 - if (subscribe != null) {  
121 - SipSubscribe.EventResult eventResult = new SipSubscribe.EventResult(responseEvent);  
122 - subscribe.response(eventResult);  
123 - } 99 + CSeqHeader cseqHeader = (CSeqHeader) responseEvent.getResponse().getHeader(CSeqHeader.NAME);
  100 + String method = cseqHeader.getMethod();
  101 + ISIPResponseProcessor sipRequestProcessor = responseProcessorMap.get(method);
  102 + if (sipRequestProcessor != null) {
  103 + sipRequestProcessor.process(responseEvent);
  104 + }
  105 + if (responseEvent.getResponse() != null && sipSubscribe.getOkSubscribesSize() > 0 ) {
  106 + CallIdHeader callIdHeader = (CallIdHeader)responseEvent.getResponse().getHeader(CallIdHeader.NAME);
  107 + if (callIdHeader != null) {
  108 + SipSubscribe.Event subscribe = sipSubscribe.getOkSubscribe(callIdHeader.getCallId());
  109 + if (subscribe != null) {
  110 + SipSubscribe.EventResult eventResult = new SipSubscribe.EventResult(responseEvent);
  111 + subscribe.response(eventResult);
124 } 112 }
125 } 113 }
126 - } else if ((status >= 100) && (status < 200)) {  
127 - // 增加其它无需回复的响应,如101、180等  
128 - } else {  
129 - logger.warn("接收到失败的response响应!status:" + status + ",message:" + response.getReasonPhrase()/* .getContent().toString()*/);  
130 - if (responseEvent.getResponse() != null && sipSubscribe.getErrorSubscribesSize() > 0 ) {  
131 - CallIdHeader callIdHeader = (CallIdHeader)responseEvent.getResponse().getHeader(CallIdHeader.NAME);  
132 - if (callIdHeader != null) {  
133 - SipSubscribe.Event subscribe = sipSubscribe.getErrorSubscribe(callIdHeader.getCallId());  
134 - if (subscribe != null) {  
135 - SipSubscribe.EventResult eventResult = new SipSubscribe.EventResult(responseEvent);  
136 - subscribe.response(eventResult);  
137 - } 114 + }
  115 + } else if ((status >= 100) && (status < 200)) {
  116 + // 增加其它无需回复的响应,如101、180等
  117 + } else {
  118 + logger.warn("接收到失败的response响应!status:" + status + ",message:" + response.getReasonPhrase()/* .getContent().toString()*/);
  119 + if (responseEvent.getResponse() != null && sipSubscribe.getErrorSubscribesSize() > 0 ) {
  120 + CallIdHeader callIdHeader = (CallIdHeader)responseEvent.getResponse().getHeader(CallIdHeader.NAME);
  121 + if (callIdHeader != null) {
  122 + SipSubscribe.Event subscribe = sipSubscribe.getErrorSubscribe(callIdHeader.getCallId());
  123 + if (subscribe != null) {
  124 + SipSubscribe.EventResult eventResult = new SipSubscribe.EventResult(responseEvent);
  125 + subscribe.response(eventResult);
138 } 126 }
139 } 127 }
140 } 128 }
141 - }); 129 + }
142 130
143 131
144 } 132 }
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/ByeRequestProcessor.java
@@ -36,7 +36,8 @@ import java.util.Map; @@ -36,7 +36,8 @@ import java.util.Map;
36 @Component 36 @Component
37 public class ByeRequestProcessor extends SIPRequestProcessorParent implements InitializingBean, ISIPRequestProcessor { 37 public class ByeRequestProcessor extends SIPRequestProcessorParent implements InitializingBean, ISIPRequestProcessor {
38 38
39 - private Logger logger = LoggerFactory.getLogger(ByeRequestProcessor.class); 39 + private final Logger logger = LoggerFactory.getLogger(ByeRequestProcessor.class);
  40 + private final String method = "BYE";
40 41
41 @Autowired 42 @Autowired
42 private ISIPCommander cmder; 43 private ISIPCommander cmder;
@@ -53,8 +54,6 @@ public class ByeRequestProcessor extends SIPRequestProcessorParent implements In @@ -53,8 +54,6 @@ public class ByeRequestProcessor extends SIPRequestProcessorParent implements In
53 @Autowired 54 @Autowired
54 private IMediaServerService mediaServerService; 55 private IMediaServerService mediaServerService;
55 56
56 - private String method = "BYE";  
57 -  
58 @Autowired 57 @Autowired
59 private SIPProcessorObserver sipProcessorObserver; 58 private SIPProcessorObserver sipProcessorObserver;
60 59
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/MessageHandlerAbstract.java
@@ -16,9 +16,6 @@ public abstract class MessageHandlerAbstract extends SIPRequestProcessorParent i @@ -16,9 +16,6 @@ public abstract class MessageHandlerAbstract extends SIPRequestProcessorParent i
16 16
17 public static Map<String, IMessageHandler> messageHandlerMap = new ConcurrentHashMap<>(); 17 public static Map<String, IMessageHandler> messageHandlerMap = new ConcurrentHashMap<>();
18 18
19 - @Autowired  
20 - public MessageRequestProcessor messageRequestProcessor;  
21 -  
22 public void addHandler(String cmdType, IMessageHandler messageHandler) { 19 public void addHandler(String cmdType, IMessageHandler messageHandler) {
23 messageHandlerMap.put(cmdType, messageHandler); 20 messageHandlerMap.put(cmdType, messageHandler);
24 } 21 }
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/NotifyMessageHandler.java
1 package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.notify; 1 package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.notify;
2 2
3 import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.MessageHandlerAbstract; 3 import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.MessageHandlerAbstract;
  4 +import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.MessageRequestProcessor;
4 import org.springframework.beans.factory.InitializingBean; 5 import org.springframework.beans.factory.InitializingBean;
  6 +import org.springframework.beans.factory.annotation.Autowired;
5 import org.springframework.stereotype.Component; 7 import org.springframework.stereotype.Component;
6 8
7 @Component 9 @Component
@@ -9,6 +11,9 @@ public class NotifyMessageHandler extends MessageHandlerAbstract implements Init @@ -9,6 +11,9 @@ public class NotifyMessageHandler extends MessageHandlerAbstract implements Init
9 11
10 private final String messageType = "Notify"; 12 private final String messageType = "Notify";
11 13
  14 + @Autowired
  15 + private MessageRequestProcessor messageRequestProcessor;
  16 +
12 @Override 17 @Override
13 public void afterPropertiesSet() throws Exception { 18 public void afterPropertiesSet() throws Exception {
14 messageRequestProcessor.addHandler(messageType, this); 19 messageRequestProcessor.addHandler(messageType, this);