Commit ec90519c90925accf157434130bcf4ac7958c17d
1 parent
b16923d1
添加设备离线原因
Showing
7 changed files
with
9 additions
and
15 deletions
src/main/java/com/genersoft/iot/vmp/gb28181/event/device/RequestTimeoutEventImpl.java
| 1 | 1 | package com.genersoft.iot.vmp.gb28181.event.device; |
| 2 | 2 | |
| 3 | 3 | import com.genersoft.iot.vmp.gb28181.bean.Device; |
| 4 | -import com.genersoft.iot.vmp.gb28181.event.SipSubscribe; | |
| 5 | 4 | import com.genersoft.iot.vmp.service.IDeviceService; |
| 6 | 5 | import org.springframework.beans.factory.annotation.Autowired; |
| 7 | 6 | import org.springframework.context.ApplicationListener; |
| ... | ... | @@ -9,8 +8,6 @@ import org.springframework.stereotype.Component; |
| 9 | 8 | |
| 10 | 9 | import javax.sip.ClientTransaction; |
| 11 | 10 | import javax.sip.address.SipURI; |
| 12 | -import javax.sip.header.CallIdHeader; | |
| 13 | -import javax.sip.header.ToHeader; | |
| 14 | 11 | import javax.sip.message.Request; |
| 15 | 12 | |
| 16 | 13 | /** |
| ... | ... | @@ -34,7 +31,7 @@ public class RequestTimeoutEventImpl implements ApplicationListener<RequestTimeo |
| 34 | 31 | if (device == null) { |
| 35 | 32 | return; |
| 36 | 33 | } |
| 37 | - deviceService.offline(device.getDeviceId()); | |
| 34 | + deviceService.offline(device.getDeviceId(), "等待消息超时"); | |
| 38 | 35 | } |
| 39 | 36 | |
| 40 | 37 | } | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/task/SipRunner.java
| ... | ... | @@ -61,7 +61,7 @@ public class SipRunner implements CommandLineRunner { |
| 61 | 61 | |
| 62 | 62 | for (Device device : deviceList) { |
| 63 | 63 | if (deviceService.expire(device)){ |
| 64 | - deviceService.offline(device.getDeviceId()); | |
| 64 | + deviceService.offline(device.getDeviceId(), "注册已过期"); | |
| 65 | 65 | }else { |
| 66 | 66 | deviceService.online(device); |
| 67 | 67 | } | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/RegisterRequestProcessor.java
| ... | ... | @@ -182,7 +182,7 @@ public class RegisterRequestProcessor extends SIPRequestProcessorParent implemen |
| 182 | 182 | deviceService.online(device); |
| 183 | 183 | } else { |
| 184 | 184 | logger.info("[注销成功] deviceId: {}->{}" ,deviceId, requestAddress); |
| 185 | - deviceService.offline(deviceId); | |
| 185 | + deviceService.offline(deviceId, "主动注销"); | |
| 186 | 186 | } |
| 187 | 187 | } catch (SipException | NoSuchAlgorithmException | ParseException e) { |
| 188 | 188 | e.printStackTrace(); | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/KeepaliveNotifyMessageHandler.java
| ... | ... | @@ -94,7 +94,7 @@ public class KeepaliveNotifyMessageHandler extends SIPRequestProcessorParent imp |
| 94 | 94 | // 刷新过期任务 |
| 95 | 95 | String registerExpireTaskKey = VideoManagerConstants.REGISTER_EXPIRE_TASK_KEY_PREFIX + device.getDeviceId(); |
| 96 | 96 | // 如果三次心跳失败,则设置设备离线 |
| 97 | - dynamicTask.startDelay(registerExpireTaskKey, ()-> deviceService.offline(device.getDeviceId()), device.getKeepaliveIntervalTime()*1000*3); | |
| 97 | + dynamicTask.startDelay(registerExpireTaskKey, ()-> deviceService.offline(device.getDeviceId(), "三次心跳失败"), device.getKeepaliveIntervalTime()*1000*3); | |
| 98 | 98 | |
| 99 | 99 | } |
| 100 | 100 | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/DeviceStatusResponseMessageHandler.java
| 1 | 1 | package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.cmd; |
| 2 | 2 | |
| 3 | 3 | import com.alibaba.fastjson2.JSONObject; |
| 4 | -import com.genersoft.iot.vmp.common.VideoManagerConstants; | |
| 5 | 4 | import com.genersoft.iot.vmp.gb28181.bean.Device; |
| 6 | 5 | import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; |
| 7 | -import com.genersoft.iot.vmp.gb28181.event.EventPublisher; | |
| 8 | 6 | import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder; |
| 9 | 7 | import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage; |
| 10 | 8 | import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent; |
| ... | ... | @@ -26,7 +24,6 @@ import javax.sip.RequestEvent; |
| 26 | 24 | import javax.sip.SipException; |
| 27 | 25 | import javax.sip.message.Response; |
| 28 | 26 | import java.text.ParseException; |
| 29 | -import java.util.Objects; | |
| 30 | 27 | |
| 31 | 28 | @Component |
| 32 | 29 | public class DeviceStatusResponseMessageHandler extends SIPRequestProcessorParent implements InitializingBean, IMessageHandler { |
| ... | ... | @@ -76,7 +73,7 @@ public class DeviceStatusResponseMessageHandler extends SIPRequestProcessorParen |
| 76 | 73 | if ("ONLINE".equalsIgnoreCase(text.trim())) { |
| 77 | 74 | deviceService.online(device); |
| 78 | 75 | }else { |
| 79 | - deviceService.offline(device.getDeviceId()); | |
| 76 | + deviceService.offline(device.getDeviceId(), "设备状态查询结果:" + text.trim()); | |
| 80 | 77 | } |
| 81 | 78 | RequestMessage msg = new RequestMessage(); |
| 82 | 79 | msg.setKey(DeferredResultHolder.CALLBACK_CMD_DEVICESTATUS + device.getDeviceId()); | ... | ... |
src/main/java/com/genersoft/iot/vmp/service/IDeviceService.java
src/main/java/com/genersoft/iot/vmp/service/impl/DeviceServiceImpl.java
| ... | ... | @@ -156,12 +156,12 @@ public class DeviceServiceImpl implements IDeviceService { |
| 156 | 156 | // 刷新过期任务 |
| 157 | 157 | String registerExpireTaskKey = VideoManagerConstants.REGISTER_EXPIRE_TASK_KEY_PREFIX + device.getDeviceId(); |
| 158 | 158 | // 如果第一次注册那么必须在60 * 3时间内收到一个心跳,否则设备离线 |
| 159 | - dynamicTask.startDelay(registerExpireTaskKey, ()-> offline(device.getDeviceId()), device.getKeepaliveIntervalTime() * 1000 * 3); | |
| 159 | + dynamicTask.startDelay(registerExpireTaskKey, ()-> offline(device.getDeviceId(), "首次注册后未能收到心跳"), device.getKeepaliveIntervalTime() * 1000 * 3); | |
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | @Override |
| 163 | - public void offline(String deviceId) { | |
| 164 | - logger.error("[设备离线], device:{}", deviceId); | |
| 163 | + public void offline(String deviceId, String reason) { | |
| 164 | + logger.error("[设备离线],{}, device:{}", reason, deviceId); | |
| 165 | 165 | Device device = deviceMapper.getDeviceByDeviceId(deviceId); |
| 166 | 166 | if (device == null) { |
| 167 | 167 | return; | ... | ... |