Commit bf8fb0c51f4e7894a62636dede6c69a2a85d8458

Authored by panlinlin
1 parent 39078225

添加级联平台自动注册时失败自动重新注册

src/main/java/com/genersoft/iot/vmp/gb28181/event/platformNotRegister/PlatformNotRegisterEventLister.java
... ... @@ -2,6 +2,7 @@ package com.genersoft.iot.vmp.gb28181.event.platformNotRegister;
2 2  
3 3 import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
4 4 import com.genersoft.iot.vmp.gb28181.bean.SendRtpItem;
  5 +import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
5 6 import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommanderFroPlatform;
6 7 import com.genersoft.iot.vmp.media.zlm.ZLMRTPServerFactory;
7 8 import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
... ... @@ -12,9 +13,7 @@ import org.springframework.beans.factory.annotation.Autowired;
12 13 import org.springframework.context.ApplicationListener;
13 14 import org.springframework.stereotype.Component;
14 15  
15   -import java.util.HashMap;
16   -import java.util.List;
17   -import java.util.Map;
  16 +import java.util.*;
18 17  
19 18 /**
20 19 * @Description: 平台未注册事件,来源有二:
... ... @@ -77,6 +76,20 @@ public class PlatformNotRegisterEventLister implements ApplicationListener<Platf
77 76 zlmrtpServerFactory.stopSendRtpStream(param);
78 77  
79 78 }
80   - sipCommanderFroPlatform.register(parentPlatform);
  79 +
  80 + Timer timer = new Timer();
  81 + SipSubscribe.Event okEvent = (responseEvent)->{
  82 + timer.cancel();
  83 + };
  84 + logger.info("向平台注册,平台国标ID:" + event.getPlatformGbID());
  85 + sipCommanderFroPlatform.register(parentPlatform, null, okEvent);
  86 + // 设置注册失败则每隔15秒发起一次注册
  87 + timer.schedule(new TimerTask() {
  88 + @Override
  89 + public void run() {
  90 + logger.info("再次向平台注册,平台国标ID:" + event.getPlatformGbID());
  91 + sipCommanderFroPlatform.register(parentPlatform, null, okEvent);
  92 + }
  93 + }, 15000, 15000);//十五秒后再次发起注册
81 94 }
82 95 }
... ...
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/ISIPCommanderForPlatform.java
... ... @@ -13,7 +13,7 @@ public interface ISIPCommanderForPlatform {
13 13 * @param parentPlatform
14 14 * @return
15 15 */
16   - boolean register(ParentPlatform parentPlatform);
  16 + boolean register(ParentPlatform parentPlatform, SipSubscribe.Event errorEvent , SipSubscribe.Event okEvent);
17 17 boolean register(ParentPlatform parentPlatform, String callId, WWWAuthenticateHeader www, SipSubscribe.Event errorEvent , SipSubscribe.Event okEvent);
18 18  
19 19 /**
... ...
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommanderFroPlatform.java
... ... @@ -7,6 +7,8 @@ import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
7 7 import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform;
8 8 import com.genersoft.iot.vmp.gb28181.transmit.cmd.SIPRequestHeaderPlarformProvider;
9 9 import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
  10 +import org.slf4j.Logger;
  11 +import org.slf4j.LoggerFactory;
10 12 import org.springframework.beans.factory.annotation.Autowired;
11 13 import org.springframework.beans.factory.annotation.Qualifier;
12 14 import org.springframework.beans.factory.annotation.Value;
... ... @@ -20,12 +22,16 @@ import javax.sip.header.CallIdHeader;
20 22 import javax.sip.header.WWWAuthenticateHeader;
21 23 import javax.sip.message.Request;
22 24 import java.text.ParseException;
  25 +import java.util.Timer;
  26 +import java.util.TimerTask;
23 27 import java.util.UUID;
24 28  
25 29 @Component
26 30 @DependsOn("sipLayer")
27 31 public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
28 32  
  33 + private final Logger logger = LoggerFactory.getLogger(SIPCommanderFroPlatform.class);
  34 +
29 35 // @Autowired
30 36 // private SipConfig sipConfig;
31 37  
... ... @@ -61,8 +67,8 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
61 67 private boolean rtpEnable;
62 68  
63 69 @Override
64   - public boolean register(ParentPlatform parentPlatform) {
65   - return register(parentPlatform, null, null, null, null);
  70 + public boolean register(ParentPlatform parentPlatform, SipSubscribe.Event errorEvent , SipSubscribe.Event okEvent) {
  71 + return register(parentPlatform, null, null, errorEvent, okEvent);
66 72 }
67 73  
68 74 @Override
... ... @@ -95,13 +101,17 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
95 101 // 将 callid 写入缓存, 等注册成功可以更新状态
96 102 redisCatchStorage.updatePlatformRegisterInfo(callIdHeader.getCallId(), parentPlatform.getServerGBId());
97 103  
98   - CallIdHeader finalCallIdHeader = callIdHeader;
99 104 sipSubscribe.addErrorSubscribe(callIdHeader.getCallId(), (event)->{
100   - redisCatchStorage.delPlatformRegisterInfo(finalCallIdHeader.getCallId());
101   - if (errorEvent != null) {
  105 + if (event != null) {
  106 + logger.info("向上级平台 [ {} ] 注册发上错误: {} ",
  107 + parentPlatform.getServerGBId(),
  108 + event.getResponse().getReasonPhrase());
  109 + }
  110 + if (errorEvent != null ) {
102 111 errorEvent.response(event);
103 112 }
104 113 });
  114 +
105 115 }else {
106 116 CallIdHeader callIdHeader = parentPlatform.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId()
107 117 : udpSipProvider.getNewCallId();
... ...
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/platform/PlatformController.java
... ... @@ -119,7 +119,7 @@ public class PlatformController {
119 119 // 保存时启用就发送注册
120 120 if (parentPlatform.isEnable()) {
121 121 // 只要保存就发送注册
122   - commanderForPlatform.register(parentPlatform);
  122 + commanderForPlatform.register(parentPlatform, null, null);
123 123 } else if (parentPlatformOld != null && parentPlatformOld.isEnable() && !parentPlatform.isEnable()){ // 关闭启用时注销
124 124 commanderForPlatform.unregister(parentPlatform, null, null);
125 125 }
... ...