Commit 7cb74dbe51bab0457048c27ddc9d7c5a17253e1a

Authored by 648540858
Committed by GitHub
2 parents 08468edd 40657033

Merge pull request #317 from nikmu/wvp-28181-2.0

添加lombok,分离注册周期事件
... ... @@ -228,6 +228,10 @@
228 228 <artifactId>spring-boot-starter-test</artifactId>
229 229 <!-- <scope>test</scope>-->
230 230 </dependency>
  231 + <dependency>
  232 + <groupId>org.projectlombok</groupId>
  233 + <artifactId>lombok</artifactId>
  234 + </dependency>
231 235 </dependencies>
232 236  
233 237  
... ...
src/main/java/com/genersoft/iot/vmp/gb28181/event/EventPublisher.java
... ... @@ -5,6 +5,7 @@ import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
5 5 import com.genersoft.iot.vmp.gb28181.bean.GbStream;
6 6 import com.genersoft.iot.vmp.gb28181.event.offline.OfflineEvent;
7 7 import com.genersoft.iot.vmp.gb28181.event.platformKeepaliveExpire.PlatformKeepaliveExpireEvent;
  8 +import com.genersoft.iot.vmp.gb28181.event.platformNotRegister.PlatformCycleRegisterEvent;
8 9 import com.genersoft.iot.vmp.gb28181.event.platformNotRegister.PlatformNotRegisterEvent;
9 10 import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEvent;
10 11 import com.genersoft.iot.vmp.media.zlm.event.ZLMOfflineEvent;
... ... @@ -67,6 +68,16 @@ public class EventPublisher {
67 68 platformNotRegisterEvent.setPlatformGbID(platformGbId);
68 69 applicationEventPublisher.publishEvent(platformNotRegisterEvent);
69 70 }
  71 +
  72 + /**
  73 + * 平台周期注册事件
  74 + * @param paltformGbId
  75 + */
  76 + public void platformRegisterCycleEventPublish(String paltformGbId) {
  77 + PlatformCycleRegisterEvent platformCycleRegisterEvent = new PlatformCycleRegisterEvent(this);
  78 + platformCycleRegisterEvent.setPlatformGbID(paltformGbId);
  79 + applicationEventPublisher.publishEvent(platformCycleRegisterEvent);
  80 + }
70 81  
71 82 /**
72 83 * 设备报警事件
... ...
src/main/java/com/genersoft/iot/vmp/gb28181/event/offline/KeepaliveTimeoutListenerForPlatform.java
... ... @@ -66,7 +66,7 @@ public class KeepaliveTimeoutListenerForPlatform extends RedisKeyExpirationEvent
66 66 }else if (expiredKey.startsWith(PLATFORM_REGISTER_PREFIX)) {
67 67 String platformGBId = expiredKey.substring(PLATFORM_REGISTER_PREFIX.length(),expiredKey.length());
68 68  
69   - publisher.platformNotRegisterEventPublish(platformGBId);
  69 + publisher.platformRegisterCycleEventPublish(platformGBId);
70 70 }else if (expiredKey.startsWith(KEEPLIVEKEY_PREFIX)){
71 71 String deviceId = expiredKey.substring(KEEPLIVEKEY_PREFIX.length(),expiredKey.length());
72 72 publisher.outlineEventPublish(deviceId, KEEPLIVEKEY_PREFIX);
... ...
src/main/java/com/genersoft/iot/vmp/gb28181/event/platformNotRegister/PlatformCycleRegisterEvent.java 0 → 100644
  1 +package com.genersoft.iot.vmp.gb28181.event.platformNotRegister;
  2 +
  3 +import org.springframework.context.ApplicationEvent;
  4 +
  5 +public class PlatformCycleRegisterEvent extends ApplicationEvent {
  6 + /**
  7 + * Add default serial version ID
  8 + */
  9 + private static final long serialVersionUID = 1L;
  10 +
  11 + private String platformGbID;
  12 +
  13 + public String getPlatformGbID() {
  14 + return platformGbID;
  15 + }
  16 +
  17 + public void setPlatformGbID(String platformGbID) {
  18 + this.platformGbID = platformGbID;
  19 + }
  20 +
  21 + public PlatformCycleRegisterEvent(Object source) {
  22 + super(source);
  23 + }
  24 +}
... ...
src/main/java/com/genersoft/iot/vmp/gb28181/event/platformNotRegister/PlatformCycleRegisterEventLister.java 0 → 100644
  1 +package com.genersoft.iot.vmp.gb28181.event.platformNotRegister;
  2 +
  3 +import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
  4 +import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
  5 +import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform;
  6 +import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
  7 +import lombok.extern.slf4j.Slf4j;
  8 +import org.springframework.beans.factory.annotation.Autowired;
  9 +import org.springframework.context.ApplicationListener;
  10 +import org.springframework.stereotype.Component;
  11 +
  12 +import java.util.Timer;
  13 +import java.util.TimerTask;
  14 +
  15 +@Slf4j
  16 +@Component
  17 +public class PlatformCycleRegisterEventLister implements ApplicationListener<PlatformCycleRegisterEvent> {
  18 + @Autowired
  19 + private IVideoManagerStorager storager;
  20 + @Autowired
  21 + private ISIPCommanderForPlatform sipCommanderFroPlatform;
  22 +
  23 + @Override
  24 + public void onApplicationEvent(PlatformCycleRegisterEvent event) {
  25 + log.info("上级平台周期注册事件");
  26 + ParentPlatform parentPlatform = storager.queryParentPlatByServerGBId(event.getPlatformGbID());
  27 + if (parentPlatform == null) {
  28 + log.info("[ 平台未注册事件 ] 平台已经删除!!! 平台国标ID:" + event.getPlatformGbID());
  29 + return;
  30 + }
  31 + Timer timer = new Timer();
  32 + SipSubscribe.Event okEvent = (responseEvent)->{
  33 + timer.cancel();
  34 + };
  35 + sipCommanderFroPlatform.register(parentPlatform, null, okEvent);
  36 + timer.schedule(new TimerTask() {
  37 + @Override
  38 + public void run() {
  39 + log.info("[平台注册]再次向平台注册,平台国标ID:" + event.getPlatformGbID());
  40 + sipCommanderFroPlatform.register(parentPlatform, null, okEvent);
  41 + }
  42 + }, 15*1000 ,Long.parseLong(parentPlatform.getExpires())* 1000);
  43 + }
  44 +}
... ...