From 40657033175bbecb983654f43208d9c2c3e37bb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E4=BF=8A=E6=9D=B0?= <502612493@qq.com> Date: Tue, 25 Jan 2022 15:42:11 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0lombok=EF=BC=8C=E5=88=86?= =?UTF-8?q?=E7=A6=BB=E6=B3=A8=E5=86=8C=E5=91=A8=E6=9C=9F=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1、添加lombok依赖 2、分离注册周期事件 --- pom.xml | 4 ++ .../iot/vmp/gb28181/event/EventPublisher.java | 11 +++++ .../KeepaliveTimeoutListenerForPlatform.java | 2 +- .../PlatformCycleRegisterEvent.java | 24 ++++++++++ .../PlatformCycleRegisterEventLister.java | 44 +++++++++++++++++++ 5 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/genersoft/iot/vmp/gb28181/event/platformNotRegister/PlatformCycleRegisterEvent.java create mode 100644 src/main/java/com/genersoft/iot/vmp/gb28181/event/platformNotRegister/PlatformCycleRegisterEventLister.java diff --git a/pom.xml b/pom.xml index 991abc68..cf2c4cf4 100644 --- a/pom.xml +++ b/pom.xml @@ -228,6 +228,10 @@ spring-boot-starter-test + + org.projectlombok + lombok + diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/event/EventPublisher.java b/src/main/java/com/genersoft/iot/vmp/gb28181/event/EventPublisher.java index 76b44271..426e2e58 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/event/EventPublisher.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/event/EventPublisher.java @@ -5,6 +5,7 @@ import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; import com.genersoft.iot.vmp.gb28181.bean.GbStream; import com.genersoft.iot.vmp.gb28181.event.offline.OfflineEvent; import com.genersoft.iot.vmp.gb28181.event.platformKeepaliveExpire.PlatformKeepaliveExpireEvent; +import com.genersoft.iot.vmp.gb28181.event.platformNotRegister.PlatformCycleRegisterEvent; import com.genersoft.iot.vmp.gb28181.event.platformNotRegister.PlatformNotRegisterEvent; import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEvent; import com.genersoft.iot.vmp.media.zlm.event.ZLMOfflineEvent; @@ -67,6 +68,16 @@ public class EventPublisher { platformNotRegisterEvent.setPlatformGbID(platformGbId); applicationEventPublisher.publishEvent(platformNotRegisterEvent); } + + /** + * 平台周期注册事件 + * @param paltformGbId + */ + public void platformRegisterCycleEventPublish(String paltformGbId) { + PlatformCycleRegisterEvent platformCycleRegisterEvent = new PlatformCycleRegisterEvent(this); + platformCycleRegisterEvent.setPlatformGbID(paltformGbId); + applicationEventPublisher.publishEvent(platformCycleRegisterEvent); + } /** * 设备报警事件 diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/event/offline/KeepaliveTimeoutListenerForPlatform.java b/src/main/java/com/genersoft/iot/vmp/gb28181/event/offline/KeepaliveTimeoutListenerForPlatform.java index ea322d12..9ba0c055 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/event/offline/KeepaliveTimeoutListenerForPlatform.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/event/offline/KeepaliveTimeoutListenerForPlatform.java @@ -66,7 +66,7 @@ public class KeepaliveTimeoutListenerForPlatform extends RedisKeyExpirationEvent }else if (expiredKey.startsWith(PLATFORM_REGISTER_PREFIX)) { String platformGBId = expiredKey.substring(PLATFORM_REGISTER_PREFIX.length(),expiredKey.length()); - publisher.platformNotRegisterEventPublish(platformGBId); + publisher.platformRegisterCycleEventPublish(platformGBId); }else if (expiredKey.startsWith(KEEPLIVEKEY_PREFIX)){ String deviceId = expiredKey.substring(KEEPLIVEKEY_PREFIX.length(),expiredKey.length()); publisher.outlineEventPublish(deviceId, KEEPLIVEKEY_PREFIX); diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/event/platformNotRegister/PlatformCycleRegisterEvent.java b/src/main/java/com/genersoft/iot/vmp/gb28181/event/platformNotRegister/PlatformCycleRegisterEvent.java new file mode 100644 index 00000000..c2ff61f3 --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/event/platformNotRegister/PlatformCycleRegisterEvent.java @@ -0,0 +1,24 @@ +package com.genersoft.iot.vmp.gb28181.event.platformNotRegister; + +import org.springframework.context.ApplicationEvent; + +public class PlatformCycleRegisterEvent extends ApplicationEvent { + /** + * Add default serial version ID + */ + private static final long serialVersionUID = 1L; + + private String platformGbID; + + public String getPlatformGbID() { + return platformGbID; + } + + public void setPlatformGbID(String platformGbID) { + this.platformGbID = platformGbID; + } + + public PlatformCycleRegisterEvent(Object source) { + super(source); + } +} diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/event/platformNotRegister/PlatformCycleRegisterEventLister.java b/src/main/java/com/genersoft/iot/vmp/gb28181/event/platformNotRegister/PlatformCycleRegisterEventLister.java new file mode 100644 index 00000000..996f65dd --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/event/platformNotRegister/PlatformCycleRegisterEventLister.java @@ -0,0 +1,44 @@ +package com.genersoft.iot.vmp.gb28181.event.platformNotRegister; + +import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; +import com.genersoft.iot.vmp.gb28181.event.SipSubscribe; +import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform; +import com.genersoft.iot.vmp.storager.IVideoManagerStorager; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationListener; +import org.springframework.stereotype.Component; + +import java.util.Timer; +import java.util.TimerTask; + +@Slf4j +@Component +public class PlatformCycleRegisterEventLister implements ApplicationListener { + @Autowired + private IVideoManagerStorager storager; + @Autowired + private ISIPCommanderForPlatform sipCommanderFroPlatform; + + @Override + public void onApplicationEvent(PlatformCycleRegisterEvent event) { + log.info("上级平台周期注册事件"); + ParentPlatform parentPlatform = storager.queryParentPlatByServerGBId(event.getPlatformGbID()); + if (parentPlatform == null) { + log.info("[ 平台未注册事件 ] 平台已经删除!!! 平台国标ID:" + event.getPlatformGbID()); + return; + } + Timer timer = new Timer(); + SipSubscribe.Event okEvent = (responseEvent)->{ + timer.cancel(); + }; + sipCommanderFroPlatform.register(parentPlatform, null, okEvent); + timer.schedule(new TimerTask() { + @Override + public void run() { + log.info("[平台注册]再次向平台注册,平台国标ID:" + event.getPlatformGbID()); + sipCommanderFroPlatform.register(parentPlatform, null, okEvent); + } + }, 15*1000 ,Long.parseLong(parentPlatform.getExpires())* 1000); + } +}