Browse Source

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

pull/93/head
panlinlin 4 years ago
parent
commit
bf8fb0c51f
  1. 21
      src/main/java/com/genersoft/iot/vmp/gb28181/event/platformNotRegister/PlatformNotRegisterEventLister.java
  2. 2
      src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/ISIPCommanderForPlatform.java
  3. 18
      src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommanderFroPlatform.java
  4. 2
      src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/platform/PlatformController.java

21
src/main/java/com/genersoft/iot/vmp/gb28181/event/platformNotRegister/PlatformNotRegisterEventLister.java

@ -2,6 +2,7 @@ package com.genersoft.iot.vmp.gb28181.event.platformNotRegister;
import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
import com.genersoft.iot.vmp.gb28181.bean.SendRtpItem; import com.genersoft.iot.vmp.gb28181.bean.SendRtpItem;
import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommanderFroPlatform; import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommanderFroPlatform;
import com.genersoft.iot.vmp.media.zlm.ZLMRTPServerFactory; import com.genersoft.iot.vmp.media.zlm.ZLMRTPServerFactory;
import com.genersoft.iot.vmp.storager.IRedisCatchStorage; import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
@ -12,9 +13,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener; import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.HashMap; import java.util.*;
import java.util.List;
import java.util.Map;
/** /**
* @Description: 平台未注册事件,来源有二: * @Description: 平台未注册事件,来源有二:
@ -77,6 +76,20 @@ public class PlatformNotRegisterEventLister implements ApplicationListener<Platf
zlmrtpServerFactory.stopSendRtpStream(param); zlmrtpServerFactory.stopSendRtpStream(param);
} }
sipCommanderFroPlatform.register(parentPlatform);
Timer timer = new Timer();
SipSubscribe.Event okEvent = (responseEvent)->{
timer.cancel();
};
logger.info("向平台注册,平台国标ID:" + event.getPlatformGbID());
sipCommanderFroPlatform.register(parentPlatform, null, okEvent);
// 设置注册失败则每隔15秒发起一次注册
timer.schedule(new TimerTask() {
@Override
public void run() {
logger.info("再次向平台注册,平台国标ID:" + event.getPlatformGbID());
sipCommanderFroPlatform.register(parentPlatform, null, okEvent);
}
}, 15000, 15000);//十五秒后再次发起注册
} }
} }

2
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/ISIPCommanderForPlatform.java

@ -13,7 +13,7 @@ public interface ISIPCommanderForPlatform {
* @param parentPlatform * @param parentPlatform
* @return * @return
*/ */
boolean register(ParentPlatform parentPlatform); boolean register(ParentPlatform parentPlatform, SipSubscribe.Event errorEvent , SipSubscribe.Event okEvent);
boolean register(ParentPlatform parentPlatform, String callId, WWWAuthenticateHeader www, SipSubscribe.Event errorEvent , SipSubscribe.Event okEvent); boolean register(ParentPlatform parentPlatform, String callId, WWWAuthenticateHeader www, SipSubscribe.Event errorEvent , SipSubscribe.Event okEvent);
/** /**

18
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;
import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform; import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform;
import com.genersoft.iot.vmp.gb28181.transmit.cmd.SIPRequestHeaderPlarformProvider; import com.genersoft.iot.vmp.gb28181.transmit.cmd.SIPRequestHeaderPlarformProvider;
import com.genersoft.iot.vmp.storager.IRedisCatchStorage; import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
@ -20,12 +22,16 @@ import javax.sip.header.CallIdHeader;
import javax.sip.header.WWWAuthenticateHeader; import javax.sip.header.WWWAuthenticateHeader;
import javax.sip.message.Request; import javax.sip.message.Request;
import java.text.ParseException; import java.text.ParseException;
import java.util.Timer;
import java.util.TimerTask;
import java.util.UUID; import java.util.UUID;
@Component @Component
@DependsOn("sipLayer") @DependsOn("sipLayer")
public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
private final Logger logger = LoggerFactory.getLogger(SIPCommanderFroPlatform.class);
// @Autowired // @Autowired
// private SipConfig sipConfig; // private SipConfig sipConfig;
@ -61,8 +67,8 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
private boolean rtpEnable; private boolean rtpEnable;
@Override @Override
public boolean register(ParentPlatform parentPlatform) { public boolean register(ParentPlatform parentPlatform, SipSubscribe.Event errorEvent , SipSubscribe.Event okEvent) {
return register(parentPlatform, null, null, null, null); return register(parentPlatform, null, null, errorEvent, okEvent);
} }
@Override @Override
@ -95,13 +101,17 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
// 将 callid 写入缓存, 等注册成功可以更新状态 // 将 callid 写入缓存, 等注册成功可以更新状态
redisCatchStorage.updatePlatformRegisterInfo(callIdHeader.getCallId(), parentPlatform.getServerGBId()); redisCatchStorage.updatePlatformRegisterInfo(callIdHeader.getCallId(), parentPlatform.getServerGBId());
CallIdHeader finalCallIdHeader = callIdHeader;
sipSubscribe.addErrorSubscribe(callIdHeader.getCallId(), (event)->{ sipSubscribe.addErrorSubscribe(callIdHeader.getCallId(), (event)->{
redisCatchStorage.delPlatformRegisterInfo(finalCallIdHeader.getCallId()); if (event != null) {
logger.info("向上级平台 [ {} ] 注册发上错误: {} ",
parentPlatform.getServerGBId(),
event.getResponse().getReasonPhrase());
}
if (errorEvent != null ) { if (errorEvent != null ) {
errorEvent.response(event); errorEvent.response(event);
} }
}); });
}else { }else {
CallIdHeader callIdHeader = parentPlatform.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId() CallIdHeader callIdHeader = parentPlatform.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId()
: udpSipProvider.getNewCallId(); : udpSipProvider.getNewCallId();

2
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/platform/PlatformController.java

@ -119,7 +119,7 @@ public class PlatformController {
// 保存时启用就发送注册 // 保存时启用就发送注册
if (parentPlatform.isEnable()) { if (parentPlatform.isEnable()) {
// 只要保存就发送注册 // 只要保存就发送注册
commanderForPlatform.register(parentPlatform); commanderForPlatform.register(parentPlatform, null, null);
} else if (parentPlatformOld != null && parentPlatformOld.isEnable() && !parentPlatform.isEnable()){ // 关闭启用时注销 } else if (parentPlatformOld != null && parentPlatformOld.isEnable() && !parentPlatform.isEnable()){ // 关闭启用时注销
commanderForPlatform.unregister(parentPlatform, null, null); commanderForPlatform.unregister(parentPlatform, null, null);
} }

Loading…
Cancel
Save