EventPublisher.java 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. package com.genersoft.iot.vmp.gb28181.event;
  2. import com.genersoft.iot.vmp.gb28181.bean.*;
  3. import com.genersoft.iot.vmp.gb28181.event.device.RequestTimeoutEvent;
  4. import com.genersoft.iot.vmp.gb28181.event.platformKeepaliveExpire.PlatformKeepaliveExpireEvent;
  5. import com.genersoft.iot.vmp.gb28181.event.platformNotRegister.PlatformCycleRegisterEvent;
  6. import com.genersoft.iot.vmp.gb28181.event.platformNotRegister.PlatformNotRegisterEvent;
  7. import com.genersoft.iot.vmp.gb28181.event.record.RecordEndEvent;
  8. import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEvent;
  9. import com.genersoft.iot.vmp.media.zlm.event.ZLMOfflineEvent;
  10. import com.genersoft.iot.vmp.media.zlm.event.ZLMOnlineEvent;
  11. import org.springframework.beans.factory.annotation.Autowired;
  12. import org.springframework.context.ApplicationEventPublisher;
  13. import org.springframework.stereotype.Component;
  14. import com.genersoft.iot.vmp.gb28181.event.alarm.AlarmEvent;
  15. import javax.sip.TimeoutEvent;
  16. import java.util.ArrayList;
  17. import java.util.HashSet;
  18. import java.util.List;
  19. import java.util.Set;
  20. /**
  21. * @description:Event事件通知推送器,支持推送在线事件、离线事件
  22. * @author: swwheihei
  23. * @date: 2020年5月6日 上午11:30:50
  24. */
  25. @Component
  26. public class EventPublisher {
  27. @Autowired
  28. private ApplicationEventPublisher applicationEventPublisher;
  29. /**
  30. * 平台心跳到期事件
  31. * @param platformGbId
  32. */
  33. public void platformKeepaliveExpireEventPublish(String platformGbId){
  34. PlatformKeepaliveExpireEvent platformKeepaliveExpireEvent = new PlatformKeepaliveExpireEvent(this);
  35. platformKeepaliveExpireEvent.setPlatformGbID(platformGbId);
  36. applicationEventPublisher.publishEvent(platformKeepaliveExpireEvent);
  37. }
  38. /**
  39. * 平台未注册事件
  40. * @param platformGbId
  41. */
  42. public void platformNotRegisterEventPublish(String platformGbId){
  43. PlatformNotRegisterEvent platformNotRegisterEvent = new PlatformNotRegisterEvent(this);
  44. platformNotRegisterEvent.setPlatformGbID(platformGbId);
  45. applicationEventPublisher.publishEvent(platformNotRegisterEvent);
  46. }
  47. /**
  48. * 平台周期注册事件
  49. * @param paltformGbId
  50. */
  51. public void platformRegisterCycleEventPublish(String paltformGbId) {
  52. PlatformCycleRegisterEvent platformCycleRegisterEvent = new PlatformCycleRegisterEvent(this);
  53. platformCycleRegisterEvent.setPlatformGbID(paltformGbId);
  54. applicationEventPublisher.publishEvent(platformCycleRegisterEvent);
  55. }
  56. /**
  57. * 设备报警事件
  58. * @param deviceAlarm
  59. */
  60. public void deviceAlarmEventPublish(DeviceAlarm deviceAlarm) {
  61. AlarmEvent alarmEvent = new AlarmEvent(this);
  62. alarmEvent.setAlarmInfo(deviceAlarm);
  63. applicationEventPublisher.publishEvent(alarmEvent);
  64. }
  65. public void zlmOfflineEventPublish(String mediaServerId){
  66. ZLMOfflineEvent outEvent = new ZLMOfflineEvent(this);
  67. outEvent.setMediaServerId(mediaServerId);
  68. applicationEventPublisher.publishEvent(outEvent);
  69. }
  70. public void zlmOnlineEventPublish(String mediaServerId) {
  71. ZLMOnlineEvent outEvent = new ZLMOnlineEvent(this);
  72. outEvent.setMediaServerId(mediaServerId);
  73. applicationEventPublisher.publishEvent(outEvent);
  74. }
  75. public void catalogEventPublish(String platformId, DeviceChannel deviceChannel, String type) {
  76. List<DeviceChannel> deviceChannelList = new ArrayList<>();
  77. deviceChannelList.add(deviceChannel);
  78. catalogEventPublish(platformId, deviceChannelList, type);
  79. }
  80. public void requestTimeOut(TimeoutEvent timeoutEvent) {
  81. RequestTimeoutEvent requestTimeoutEvent = new RequestTimeoutEvent(this);
  82. requestTimeoutEvent.setTimeoutEvent(timeoutEvent);
  83. applicationEventPublisher.publishEvent(requestTimeoutEvent);
  84. }
  85. /**
  86. *
  87. * @param platformId
  88. * @param deviceChannels
  89. * @param type
  90. */
  91. public void catalogEventPublish(String platformId, List<DeviceChannel> deviceChannels, String type) {
  92. CatalogEvent outEvent = new CatalogEvent(this);
  93. List<DeviceChannel> channels = new ArrayList<>();
  94. if (deviceChannels.size() > 1) {
  95. // 数据去重
  96. Set<String> gbIdSet = new HashSet<>();
  97. for (DeviceChannel deviceChannel : deviceChannels) {
  98. if (!gbIdSet.contains(deviceChannel.getChannelId())) {
  99. gbIdSet.add(deviceChannel.getChannelId());
  100. channels.add(deviceChannel);
  101. }
  102. }
  103. }else {
  104. channels = deviceChannels;
  105. }
  106. outEvent.setDeviceChannels(channels);
  107. outEvent.setType(type);
  108. outEvent.setPlatformId(platformId);
  109. applicationEventPublisher.publishEvent(outEvent);
  110. }
  111. public void catalogEventPublishForStream(String platformId, List<GbStream> gbStreams, String type) {
  112. CatalogEvent outEvent = new CatalogEvent(this);
  113. outEvent.setGbStreams(gbStreams);
  114. outEvent.setType(type);
  115. outEvent.setPlatformId(platformId);
  116. applicationEventPublisher.publishEvent(outEvent);
  117. }
  118. public void catalogEventPublishForStream(String platformId, GbStream gbStream, String type) {
  119. List<GbStream> gbStreamList = new ArrayList<>();
  120. gbStreamList.add(gbStream);
  121. catalogEventPublishForStream(platformId, gbStreamList, type);
  122. }
  123. public void recordEndEventPush(RecordInfo recordInfo) {
  124. RecordEndEvent outEvent = new RecordEndEvent(this);
  125. outEvent.setRecordInfo(recordInfo);
  126. applicationEventPublisher.publishEvent(outEvent);
  127. }
  128. }