Commit 3b21f385cdae7d94fce1ebba6abb06a893f57114
1 parent
ce931ab8
对需要向设备发起请求的http请求,使用缓存,等待设备请求返回的时候一次性释放所有请求
Showing
17 changed files
with
436 additions
and
210 deletions
src/main/java/com/genersoft/iot/vmp/gb28181/bean/RecordInfo.java
| @@ -13,7 +13,9 @@ import java.util.List; | @@ -13,7 +13,9 @@ import java.util.List; | ||
| 13 | public class RecordInfo { | 13 | public class RecordInfo { |
| 14 | 14 | ||
| 15 | private String deviceId; | 15 | private String deviceId; |
| 16 | - | 16 | + |
| 17 | + private String channelId; | ||
| 18 | + | ||
| 17 | private String name; | 19 | private String name; |
| 18 | 20 | ||
| 19 | private int sumNum; | 21 | private int sumNum; |
| @@ -52,4 +54,11 @@ public class RecordInfo { | @@ -52,4 +54,11 @@ public class RecordInfo { | ||
| 52 | this.recordList = recordList; | 54 | this.recordList = recordList; |
| 53 | } | 55 | } |
| 54 | 56 | ||
| 57 | + public String getChannelId() { | ||
| 58 | + return channelId; | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + public void setChannelId(String channelId) { | ||
| 62 | + this.channelId = channelId; | ||
| 63 | + } | ||
| 55 | } | 64 | } |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/callback/CheckForAllRecordsThread.java
| @@ -54,11 +54,9 @@ public class CheckForAllRecordsThread extends Thread { | @@ -54,11 +54,9 @@ public class CheckForAllRecordsThread extends Thread { | ||
| 54 | // 自然顺序排序, 元素进行升序排列 | 54 | // 自然顺序排序, 元素进行升序排列 |
| 55 | this.recordInfo.getRecordList().sort(Comparator.naturalOrder()); | 55 | this.recordInfo.getRecordList().sort(Comparator.naturalOrder()); |
| 56 | RequestMessage msg = new RequestMessage(); | 56 | RequestMessage msg = new RequestMessage(); |
| 57 | - String deviceId = recordInfo.getDeviceId(); | ||
| 58 | - msg.setDeviceId(deviceId); | ||
| 59 | - msg.setType(DeferredResultHolder.CALLBACK_CMD_RECORDINFO); | 57 | + msg.setKey(DeferredResultHolder.CALLBACK_CMD_RECORDINFO + recordInfo.getDeviceId() + recordInfo.getChannelId()); |
| 60 | msg.setData(recordInfo); | 58 | msg.setData(recordInfo); |
| 61 | - deferredResultHolder.invokeResult(msg); | 59 | + deferredResultHolder.invokeAllResult(msg); |
| 62 | logger.info("处理完成,返回结果"); | 60 | logger.info("处理完成,返回结果"); |
| 63 | MessageRequestProcessor.threadNameList.remove(cacheKey); | 61 | MessageRequestProcessor.threadNameList.remove(cacheKey); |
| 64 | } | 62 | } |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/callback/DeferredResultHolder.java
| 1 | package com.genersoft.iot.vmp.gb28181.transmit.callback; | 1 | package com.genersoft.iot.vmp.gb28181.transmit.callback; |
| 2 | 2 | ||
| 3 | +import java.util.HashMap; | ||
| 3 | import java.util.Map; | 4 | import java.util.Map; |
| 5 | +import java.util.Set; | ||
| 4 | import java.util.concurrent.ConcurrentHashMap; | 6 | import java.util.concurrent.ConcurrentHashMap; |
| 5 | 7 | ||
| 6 | import org.springframework.http.HttpStatus; | 8 | import org.springframework.http.HttpStatus; |
| @@ -45,22 +47,72 @@ public class DeferredResultHolder { | @@ -45,22 +47,72 @@ public class DeferredResultHolder { | ||
| 45 | 47 | ||
| 46 | public static final String CALLBACK_CMD_BROADCAST = "CALLBACK_BROADCAST"; | 48 | public static final String CALLBACK_CMD_BROADCAST = "CALLBACK_BROADCAST"; |
| 47 | 49 | ||
| 48 | - private Map<String, DeferredResult> map = new ConcurrentHashMap<String, DeferredResult>(); | 50 | + private Map<String, Map<String, DeferredResult>> map = new ConcurrentHashMap<>(); |
| 49 | 51 | ||
| 50 | 52 | ||
| 51 | - public void put(String key, DeferredResult result) { | ||
| 52 | - map.put(key, result); | 53 | + public void put(String key, String id, DeferredResult result) { |
| 54 | + Map<String, DeferredResult> deferredResultMap = map.get(key); | ||
| 55 | + if (deferredResultMap == null) { | ||
| 56 | + deferredResultMap = new ConcurrentHashMap<>(); | ||
| 57 | + map.put(key, deferredResultMap); | ||
| 58 | + } | ||
| 59 | + deferredResultMap.put(id, result); | ||
| 53 | } | 60 | } |
| 54 | 61 | ||
| 55 | - public DeferredResult get(String key) { | ||
| 56 | - return map.get(key); | 62 | + public DeferredResult get(String key, String id) { |
| 63 | + Map<String, DeferredResult> deferredResultMap = map.get(key); | ||
| 64 | + if (deferredResultMap == null) return null; | ||
| 65 | + return deferredResultMap.get(id); | ||
| 57 | } | 66 | } |
| 58 | - | 67 | + |
| 68 | + public boolean exist(String key, String id){ | ||
| 69 | + if (key == null) return false; | ||
| 70 | + Map<String, DeferredResult> deferredResultMap = map.get(key); | ||
| 71 | + if (id == null) { | ||
| 72 | + return deferredResultMap != null; | ||
| 73 | + }else { | ||
| 74 | + return deferredResultMap != null && deferredResultMap.get(id) != null; | ||
| 75 | + } | ||
| 76 | + } | ||
| 77 | + | ||
| 78 | + /** | ||
| 79 | + * 释放单个请求 | ||
| 80 | + * @param msg | ||
| 81 | + */ | ||
| 59 | public void invokeResult(RequestMessage msg) { | 82 | public void invokeResult(RequestMessage msg) { |
| 60 | - DeferredResult result = map.get(msg.getId()); | 83 | + Map<String, DeferredResult> deferredResultMap = map.get(msg.getKey()); |
| 84 | + if (deferredResultMap == null) { | ||
| 85 | + return; | ||
| 86 | + } | ||
| 87 | + DeferredResult result = deferredResultMap.get(msg.getId()); | ||
| 61 | if (result == null) { | 88 | if (result == null) { |
| 62 | return; | 89 | return; |
| 63 | } | 90 | } |
| 64 | result.setResult(new ResponseEntity<>(msg.getData(),HttpStatus.OK)); | 91 | result.setResult(new ResponseEntity<>(msg.getData(),HttpStatus.OK)); |
| 92 | + deferredResultMap.remove(msg.getId()); | ||
| 93 | + if (deferredResultMap.size() == 0) { | ||
| 94 | + map.remove(msg.getKey()); | ||
| 95 | + } | ||
| 96 | + } | ||
| 97 | + | ||
| 98 | + /** | ||
| 99 | + * 释放所有的请求 | ||
| 100 | + * @param msg | ||
| 101 | + */ | ||
| 102 | + public void invokeAllResult(RequestMessage msg) { | ||
| 103 | + Map<String, DeferredResult> deferredResultMap = map.get(msg.getKey()); | ||
| 104 | + if (deferredResultMap == null) { | ||
| 105 | + return; | ||
| 106 | + } | ||
| 107 | + Set<String> ids = deferredResultMap.keySet(); | ||
| 108 | + for (String id : ids) { | ||
| 109 | + DeferredResult result = deferredResultMap.get(id); | ||
| 110 | + if (result == null) { | ||
| 111 | + return; | ||
| 112 | + } | ||
| 113 | + result.setResult(new ResponseEntity<>(msg.getData(),HttpStatus.OK)); | ||
| 114 | + } | ||
| 115 | + map.remove(msg.getKey()); | ||
| 116 | + | ||
| 65 | } | 117 | } |
| 66 | } | 118 | } |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/callback/RequestMessage.java
| @@ -9,12 +9,10 @@ public class RequestMessage { | @@ -9,12 +9,10 @@ public class RequestMessage { | ||
| 9 | 9 | ||
| 10 | private String id; | 10 | private String id; |
| 11 | 11 | ||
| 12 | - private String deviceId; | ||
| 13 | - | ||
| 14 | - private String type; | ||
| 15 | - | 12 | + private String key; |
| 13 | + | ||
| 16 | private Object data; | 14 | private Object data; |
| 17 | - | 15 | + |
| 18 | public String getId() { | 16 | public String getId() { |
| 19 | return id; | 17 | return id; |
| 20 | } | 18 | } |
| @@ -23,22 +21,12 @@ public class RequestMessage { | @@ -23,22 +21,12 @@ public class RequestMessage { | ||
| 23 | this.id = id; | 21 | this.id = id; |
| 24 | } | 22 | } |
| 25 | 23 | ||
| 26 | - public String getDeviceId() { | ||
| 27 | - return deviceId; | ||
| 28 | - } | ||
| 29 | - | ||
| 30 | - public void setDeviceId(String deviceId) { | ||
| 31 | - this.deviceId = deviceId; | ||
| 32 | - this.id = type + deviceId; | ||
| 33 | - } | ||
| 34 | - | ||
| 35 | - public String getType() { | ||
| 36 | - return type; | 24 | + public void setKey(String key) { |
| 25 | + this.key = key; | ||
| 37 | } | 26 | } |
| 38 | 27 | ||
| 39 | - public void setType(String type) { | ||
| 40 | - this.type = type; | ||
| 41 | - this.id = type + deviceId; | 28 | + public String getKey() { |
| 29 | + return key; | ||
| 42 | } | 30 | } |
| 43 | 31 | ||
| 44 | public Object getData() { | 32 | public Object getData() { |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/MessageRequestProcessor.java
| @@ -173,12 +173,12 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { | @@ -173,12 +173,12 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { | ||
| 173 | Device device = storager.queryVideoDevice(deviceId); | 173 | Device device = storager.queryVideoDevice(deviceId); |
| 174 | if (device == null) { | 174 | if (device == null) { |
| 175 | logger.warn("处理MobilePosition移动位置消息时未找到设备信息"); | 175 | logger.warn("处理MobilePosition移动位置消息时未找到设备信息"); |
| 176 | + response404Ack(evt); | ||
| 176 | return; | 177 | return; |
| 177 | } | 178 | } |
| 178 | Element rootElement = getRootElement(evt, device.getCharset()); | 179 | Element rootElement = getRootElement(evt, device.getCharset()); |
| 179 | 180 | ||
| 180 | MobilePosition mobilePosition = new MobilePosition(); | 181 | MobilePosition mobilePosition = new MobilePosition(); |
| 181 | - Element deviceIdElement = rootElement.element("DeviceID"); | ||
| 182 | if (!StringUtils.isEmpty(device.getName())) { | 182 | if (!StringUtils.isEmpty(device.getName())) { |
| 183 | mobilePosition.setDeviceName(device.getName()); | 183 | mobilePosition.setDeviceName(device.getName()); |
| 184 | } | 184 | } |
| @@ -227,11 +227,17 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { | @@ -227,11 +227,17 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { | ||
| 227 | */ | 227 | */ |
| 228 | private void processMessageDeviceStatus(RequestEvent evt) { | 228 | private void processMessageDeviceStatus(RequestEvent evt) { |
| 229 | try { | 229 | try { |
| 230 | + String deviceId = SipUtils.getUserIdFromFromHeader(evt.getRequest()); | ||
| 231 | + Device device = storager.queryVideoDevice(deviceId); | ||
| 232 | + if (device == null) { | ||
| 233 | + logger.warn("处理DeviceStatus设备状态Message时未找到设备信息"); | ||
| 234 | + response404Ack(evt); | ||
| 235 | + return; | ||
| 236 | + } | ||
| 230 | Element rootElement = getRootElement(evt); | 237 | Element rootElement = getRootElement(evt); |
| 231 | String name = rootElement.getName(); | 238 | String name = rootElement.getName(); |
| 232 | Element deviceIdElement = rootElement.element("DeviceID"); | 239 | Element deviceIdElement = rootElement.element("DeviceID"); |
| 233 | - String deviceId = deviceIdElement.getText(); | ||
| 234 | - Device device = storager.queryVideoDevice(deviceId); | 240 | + String channelId = deviceIdElement.getText(); |
| 235 | if (name.equalsIgnoreCase("Query")) { // 区分是Response——查询响应,还是Query——查询请求 | 241 | if (name.equalsIgnoreCase("Query")) { // 区分是Response——查询响应,还是Query——查询请求 |
| 236 | logger.info("接收到DeviceStatus查询消息"); | 242 | logger.info("接收到DeviceStatus查询消息"); |
| 237 | FromHeader fromHeader = (FromHeader) evt.getRequest().getHeader(FromHeader.NAME); | 243 | FromHeader fromHeader = (FromHeader) evt.getRequest().getHeader(FromHeader.NAME); |
| @@ -258,10 +264,9 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { | @@ -258,10 +264,9 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { | ||
| 258 | logger.debug(json.toJSONString()); | 264 | logger.debug(json.toJSONString()); |
| 259 | } | 265 | } |
| 260 | RequestMessage msg = new RequestMessage(); | 266 | RequestMessage msg = new RequestMessage(); |
| 261 | - msg.setDeviceId(deviceId); | ||
| 262 | - msg.setType(DeferredResultHolder.CALLBACK_CMD_DEVICESTATUS); | 267 | + msg.setKey(DeferredResultHolder.CALLBACK_CMD_DEVICESTATUS + deviceId + channelId); |
| 263 | msg.setData(json); | 268 | msg.setData(json); |
| 264 | - deferredResultHolder.invokeResult(msg); | 269 | + deferredResultHolder.invokeAllResult(msg); |
| 265 | 270 | ||
| 266 | if (offLineDetector.isOnline(deviceId)) { | 271 | if (offLineDetector.isOnline(deviceId)) { |
| 267 | publisher.onlineEventPublish(device, VideoManagerConstants.EVENT_ONLINE_MESSAGE); | 272 | publisher.onlineEventPublish(device, VideoManagerConstants.EVENT_ONLINE_MESSAGE); |
| @@ -282,8 +287,15 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { | @@ -282,8 +287,15 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { | ||
| 282 | */ | 287 | */ |
| 283 | private void processMessageDeviceControl(RequestEvent evt) { | 288 | private void processMessageDeviceControl(RequestEvent evt) { |
| 284 | try { | 289 | try { |
| 290 | + String deviceId = SipUtils.getUserIdFromFromHeader(evt.getRequest()); | ||
| 291 | + Device device = storager.queryVideoDevice(deviceId); | ||
| 292 | + if (device == null) { | ||
| 293 | + logger.warn("处理DeviceControl设备状态Message未找到设备信息"); | ||
| 294 | + response404Ack(evt); | ||
| 295 | + return; | ||
| 296 | + } | ||
| 285 | Element rootElement = getRootElement(evt); | 297 | Element rootElement = getRootElement(evt); |
| 286 | - String deviceId = XmlUtil.getText(rootElement, "DeviceID"); | 298 | + String channelId = XmlUtil.getText(rootElement, "DeviceID"); |
| 287 | //String result = XmlUtil.getText(rootElement, "Result"); | 299 | //String result = XmlUtil.getText(rootElement, "Result"); |
| 288 | // 回复200 OK | 300 | // 回复200 OK |
| 289 | responseAck(evt); | 301 | responseAck(evt); |
| @@ -295,10 +307,10 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { | @@ -295,10 +307,10 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { | ||
| 295 | logger.debug(json.toJSONString()); | 307 | logger.debug(json.toJSONString()); |
| 296 | } | 308 | } |
| 297 | RequestMessage msg = new RequestMessage(); | 309 | RequestMessage msg = new RequestMessage(); |
| 298 | - msg.setDeviceId(deviceId); | ||
| 299 | - msg.setType(DeferredResultHolder.CALLBACK_CMD_DEVICECONTROL); | 310 | + String key = DeferredResultHolder.CALLBACK_CMD_DEVICECONTROL + deviceId + channelId; |
| 311 | + msg.setKey(key); | ||
| 300 | msg.setData(json); | 312 | msg.setData(json); |
| 301 | - deferredResultHolder.invokeResult(msg); | 313 | + deferredResultHolder.invokeAllResult(msg); |
| 302 | } else { | 314 | } else { |
| 303 | // 此处是上级发出的DeviceControl指令 | 315 | // 此处是上级发出的DeviceControl指令 |
| 304 | String platformId = ((SipURI) ((HeaderAddress) evt.getRequest().getHeader(FromHeader.NAME)).getAddress().getURI()).getUser(); | 316 | String platformId = ((SipURI) ((HeaderAddress) evt.getRequest().getHeader(FromHeader.NAME)).getAddress().getURI()).getUser(); |
| @@ -344,8 +356,8 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { | @@ -344,8 +356,8 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { | ||
| 344 | // 云台/前端控制命令 | 356 | // 云台/前端控制命令 |
| 345 | if (!StringUtils.isEmpty(XmlUtil.getText(rootElement,"PTZCmd")) && !deviceId.equals(targetGBId)) { | 357 | if (!StringUtils.isEmpty(XmlUtil.getText(rootElement,"PTZCmd")) && !deviceId.equals(targetGBId)) { |
| 346 | String cmdString = XmlUtil.getText(rootElement,"PTZCmd"); | 358 | String cmdString = XmlUtil.getText(rootElement,"PTZCmd"); |
| 347 | - Device device = storager.queryVideoDeviceByPlatformIdAndChannelId(platformId, deviceId); | ||
| 348 | - cmder.fronEndCmd(device, deviceId, cmdString); | 359 | + Device deviceForPlatform = storager.queryVideoDeviceByPlatformIdAndChannelId(platformId, deviceId); |
| 360 | + cmder.fronEndCmd(deviceForPlatform, deviceId, cmdString); | ||
| 349 | } | 361 | } |
| 350 | } | 362 | } |
| 351 | } catch (ParseException | SipException | InvalidArgumentException | DocumentException e) { | 363 | } catch (ParseException | SipException | InvalidArgumentException | DocumentException e) { |
| @@ -360,8 +372,16 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { | @@ -360,8 +372,16 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { | ||
| 360 | */ | 372 | */ |
| 361 | private void processMessageDeviceConfig(RequestEvent evt) { | 373 | private void processMessageDeviceConfig(RequestEvent evt) { |
| 362 | try { | 374 | try { |
| 375 | + String deviceId = SipUtils.getUserIdFromFromHeader(evt.getRequest()); | ||
| 376 | + // 查询设备是否存在 | ||
| 377 | + Device device = storager.queryVideoDevice(deviceId); | ||
| 378 | + if (device == null) { | ||
| 379 | + logger.warn("处理DeviceConfig设备状态Message消息时未找到设备信息"); | ||
| 380 | + response404Ack(evt); | ||
| 381 | + return; | ||
| 382 | + } | ||
| 363 | Element rootElement = getRootElement(evt); | 383 | Element rootElement = getRootElement(evt); |
| 364 | - String deviceId = XmlUtil.getText(rootElement, "DeviceID"); | 384 | + String channelId = XmlUtil.getText(rootElement, "DeviceID"); |
| 365 | // 回复200 OK | 385 | // 回复200 OK |
| 366 | responseAck(evt); | 386 | responseAck(evt); |
| 367 | if (rootElement.getName().equals("Response")) { | 387 | if (rootElement.getName().equals("Response")) { |
| @@ -371,11 +391,11 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { | @@ -371,11 +391,11 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { | ||
| 371 | if (logger.isDebugEnabled()) { | 391 | if (logger.isDebugEnabled()) { |
| 372 | logger.debug(json.toJSONString()); | 392 | logger.debug(json.toJSONString()); |
| 373 | } | 393 | } |
| 394 | + String key = DeferredResultHolder.CALLBACK_CMD_DEVICECONFIG + deviceId + channelId; | ||
| 374 | RequestMessage msg = new RequestMessage(); | 395 | RequestMessage msg = new RequestMessage(); |
| 375 | - msg.setDeviceId(deviceId); | ||
| 376 | - msg.setType(DeferredResultHolder.CALLBACK_CMD_DEVICECONFIG); | 396 | + msg.setKey(key); |
| 377 | msg.setData(json); | 397 | msg.setData(json); |
| 378 | - deferredResultHolder.invokeResult(msg); | 398 | + deferredResultHolder.invokeAllResult(msg); |
| 379 | } else { | 399 | } else { |
| 380 | // 此处是上级发出的DeviceConfig指令 | 400 | // 此处是上级发出的DeviceConfig指令 |
| 381 | } | 401 | } |
| @@ -391,8 +411,17 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { | @@ -391,8 +411,17 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { | ||
| 391 | */ | 411 | */ |
| 392 | private void processMessageConfigDownload(RequestEvent evt) { | 412 | private void processMessageConfigDownload(RequestEvent evt) { |
| 393 | try { | 413 | try { |
| 414 | + String deviceId = SipUtils.getUserIdFromFromHeader(evt.getRequest()); | ||
| 415 | + // 查询设备是否存在 | ||
| 416 | + Device device = storager.queryVideoDevice(deviceId); | ||
| 417 | + if (device == null) { | ||
| 418 | + logger.warn("处理ConfigDownload设备状态Message时未找到设备信息"); | ||
| 419 | + response404Ack(evt); | ||
| 420 | + return; | ||
| 421 | + } | ||
| 394 | Element rootElement = getRootElement(evt); | 422 | Element rootElement = getRootElement(evt); |
| 395 | - String deviceId = XmlUtil.getText(rootElement, "DeviceID"); | 423 | + String channelId = XmlUtil.getText(rootElement, "DeviceID"); |
| 424 | + String key = DeferredResultHolder.CALLBACK_CMD_CONFIGDOWNLOAD + deviceId + channelId; | ||
| 396 | // 回复200 OK | 425 | // 回复200 OK |
| 397 | responseAck(evt); | 426 | responseAck(evt); |
| 398 | if (rootElement.getName().equals("Response")) { | 427 | if (rootElement.getName().equals("Response")) { |
| @@ -403,10 +432,9 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { | @@ -403,10 +432,9 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { | ||
| 403 | logger.debug(json.toJSONString()); | 432 | logger.debug(json.toJSONString()); |
| 404 | } | 433 | } |
| 405 | RequestMessage msg = new RequestMessage(); | 434 | RequestMessage msg = new RequestMessage(); |
| 406 | - msg.setDeviceId(deviceId); | ||
| 407 | - msg.setType(DeferredResultHolder.CALLBACK_CMD_CONFIGDOWNLOAD); | 435 | + msg.setKey(key); |
| 408 | msg.setData(json); | 436 | msg.setData(json); |
| 409 | - deferredResultHolder.invokeResult(msg); | 437 | + deferredResultHolder.invokeAllResult(msg); |
| 410 | } else { | 438 | } else { |
| 411 | // 此处是上级发出的DeviceConfig指令 | 439 | // 此处是上级发出的DeviceConfig指令 |
| 412 | } | 440 | } |
| @@ -422,8 +450,17 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { | @@ -422,8 +450,17 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { | ||
| 422 | */ | 450 | */ |
| 423 | private void processMessagePresetQuery(RequestEvent evt) { | 451 | private void processMessagePresetQuery(RequestEvent evt) { |
| 424 | try { | 452 | try { |
| 453 | + String deviceId = SipUtils.getUserIdFromFromHeader(evt.getRequest()); | ||
| 454 | + // 查询设备是否存在 | ||
| 455 | + Device device = storager.queryVideoDevice(deviceId); | ||
| 456 | + if (device == null) { | ||
| 457 | + logger.warn("处理PresetQuery预置位列表Message时未找到设备信息"); | ||
| 458 | + response404Ack(evt); | ||
| 459 | + return; | ||
| 460 | + } | ||
| 425 | Element rootElement = getRootElement(evt); | 461 | Element rootElement = getRootElement(evt); |
| 426 | - String deviceId = XmlUtil.getText(rootElement, "DeviceID"); | 462 | + String channelId = XmlUtil.getText(rootElement, "DeviceID"); |
| 463 | + String key = DeferredResultHolder.CALLBACK_CMD_PRESETQUERY + deviceId + channelId; | ||
| 427 | // 回复200 OK | 464 | // 回复200 OK |
| 428 | responseAck(evt); | 465 | responseAck(evt); |
| 429 | if (rootElement.getName().equals("Response")) {// !StringUtils.isEmpty(result)) { | 466 | if (rootElement.getName().equals("Response")) {// !StringUtils.isEmpty(result)) { |
| @@ -434,10 +471,9 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { | @@ -434,10 +471,9 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { | ||
| 434 | logger.debug(json.toJSONString()); | 471 | logger.debug(json.toJSONString()); |
| 435 | } | 472 | } |
| 436 | RequestMessage msg = new RequestMessage(); | 473 | RequestMessage msg = new RequestMessage(); |
| 437 | - msg.setDeviceId(deviceId); | ||
| 438 | - msg.setType(DeferredResultHolder.CALLBACK_CMD_PRESETQUERY); | 474 | + msg.setKey(key); |
| 439 | msg.setData(json); | 475 | msg.setData(json); |
| 440 | - deferredResultHolder.invokeResult(msg); | 476 | + deferredResultHolder.invokeAllResult(msg); |
| 441 | } else { | 477 | } else { |
| 442 | // 此处是上级发出的DeviceControl指令 | 478 | // 此处是上级发出的DeviceControl指令 |
| 443 | } | 479 | } |
| @@ -453,11 +489,19 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { | @@ -453,11 +489,19 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { | ||
| 453 | */ | 489 | */ |
| 454 | private void processMessageDeviceInfo(RequestEvent evt) { | 490 | private void processMessageDeviceInfo(RequestEvent evt) { |
| 455 | try { | 491 | try { |
| 492 | + String deviceId = SipUtils.getUserIdFromFromHeader(evt.getRequest()); | ||
| 493 | + // 查询设备是否存在 | ||
| 494 | + Device device = storager.queryVideoDevice(deviceId); | ||
| 495 | + if (device == null) { | ||
| 496 | + logger.warn("处理DeviceInfo设备信息Message时未找到设备信息"); | ||
| 497 | + response404Ack(evt); | ||
| 498 | + return; | ||
| 499 | + } | ||
| 456 | Element rootElement = getRootElement(evt); | 500 | Element rootElement = getRootElement(evt); |
| 457 | String requestName = rootElement.getName(); | 501 | String requestName = rootElement.getName(); |
| 458 | Element deviceIdElement = rootElement.element("DeviceID"); | 502 | Element deviceIdElement = rootElement.element("DeviceID"); |
| 459 | - String deviceId = deviceIdElement.getTextTrim(); | ||
| 460 | - Device device = storager.queryVideoDevice(deviceId); | 503 | + String channelId = deviceIdElement.getTextTrim(); |
| 504 | + String key = DeferredResultHolder.CALLBACK_CMD_DEVICEINFO + deviceId + channelId; | ||
| 461 | if (device != null ) { | 505 | if (device != null ) { |
| 462 | rootElement = getRootElement(evt, device.getCharset()); | 506 | rootElement = getRootElement(evt, device.getCharset()); |
| 463 | } | 507 | } |
| @@ -492,10 +536,9 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { | @@ -492,10 +536,9 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { | ||
| 492 | storager.updateDevice(device); | 536 | storager.updateDevice(device); |
| 493 | 537 | ||
| 494 | RequestMessage msg = new RequestMessage(); | 538 | RequestMessage msg = new RequestMessage(); |
| 495 | - msg.setDeviceId(deviceId); | ||
| 496 | - msg.setType(DeferredResultHolder.CALLBACK_CMD_DEVICEINFO); | 539 | + msg.setKey(key); |
| 497 | msg.setData(device); | 540 | msg.setData(device); |
| 498 | - deferredResultHolder.invokeResult(msg); | 541 | + deferredResultHolder.invokeAllResult(msg); |
| 499 | // 回复200 OK | 542 | // 回复200 OK |
| 500 | responseAck(evt); | 543 | responseAck(evt); |
| 501 | if (offLineDetector.isOnline(deviceId)) { | 544 | if (offLineDetector.isOnline(deviceId)) { |
| @@ -514,12 +557,22 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { | @@ -514,12 +557,22 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { | ||
| 514 | */ | 557 | */ |
| 515 | private void processMessageCatalogList(RequestEvent evt) { | 558 | private void processMessageCatalogList(RequestEvent evt) { |
| 516 | try { | 559 | try { |
| 560 | + | ||
| 561 | + String deviceId = SipUtils.getUserIdFromFromHeader(evt.getRequest()); | ||
| 562 | + // 查询设备是否存在 | ||
| 563 | + Device device = storager.queryVideoDevice(deviceId); | ||
| 564 | + if (device == null) { | ||
| 565 | + logger.warn("处理DeviceInfo设备信息Message时未找到设备信息"); | ||
| 566 | + response404Ack(evt); | ||
| 567 | + return; | ||
| 568 | + } | ||
| 569 | + | ||
| 517 | Element rootElement = getRootElement(evt); | 570 | Element rootElement = getRootElement(evt); |
| 518 | String name = rootElement.getName(); | 571 | String name = rootElement.getName(); |
| 519 | Element deviceIdElement = rootElement.element("DeviceID"); | 572 | Element deviceIdElement = rootElement.element("DeviceID"); |
| 520 | - String deviceId = deviceIdElement.getText(); | 573 | + String channelId = deviceIdElement.getText(); |
| 521 | Element deviceListElement = rootElement.element("DeviceList"); | 574 | Element deviceListElement = rootElement.element("DeviceList"); |
| 522 | - | 575 | + String key = DeferredResultHolder.CALLBACK_CMD_CATALOG + deviceId; |
| 523 | FromHeader fromHeader = (FromHeader) evt.getRequest().getHeader(FromHeader.NAME); | 576 | FromHeader fromHeader = (FromHeader) evt.getRequest().getHeader(FromHeader.NAME); |
| 524 | AddressImpl address = (AddressImpl) fromHeader.getAddress(); | 577 | AddressImpl address = (AddressImpl) fromHeader.getAddress(); |
| 525 | SipUri uri = (SipUri) address.getURI(); | 578 | SipUri uri = (SipUri) address.getURI(); |
| @@ -581,10 +634,6 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { | @@ -581,10 +634,6 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { | ||
| 581 | 634 | ||
| 582 | 635 | ||
| 583 | } else { | 636 | } else { |
| 584 | - Device device = storager.queryVideoDevice(deviceId); | ||
| 585 | - if (device == null) { | ||
| 586 | - return; | ||
| 587 | - } | ||
| 588 | deviceListElement = getRootElement(evt, device.getCharset()).element("DeviceList"); | 637 | deviceListElement = getRootElement(evt, device.getCharset()).element("DeviceList"); |
| 589 | Iterator<Element> deviceListIterator = deviceListElement.elementIterator(); | 638 | Iterator<Element> deviceListIterator = deviceListElement.elementIterator(); |
| 590 | if (deviceListIterator != null) { | 639 | if (deviceListIterator != null) { |
| @@ -674,10 +723,9 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { | @@ -674,10 +723,9 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { | ||
| 674 | } | 723 | } |
| 675 | 724 | ||
| 676 | RequestMessage msg = new RequestMessage(); | 725 | RequestMessage msg = new RequestMessage(); |
| 677 | - msg.setDeviceId(deviceId); | ||
| 678 | - msg.setType(DeferredResultHolder.CALLBACK_CMD_CATALOG); | 726 | + msg.setKey(key); |
| 679 | msg.setData(device); | 727 | msg.setData(device); |
| 680 | - deferredResultHolder.invokeResult(msg); | 728 | + deferredResultHolder.invokeAllResult(msg); |
| 681 | // 回复200 OK | 729 | // 回复200 OK |
| 682 | responseAck(evt); | 730 | responseAck(evt); |
| 683 | if (offLineDetector.isOnline(deviceId)) { | 731 | if (offLineDetector.isOnline(deviceId)) { |
| @@ -701,11 +749,13 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { | @@ -701,11 +749,13 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { | ||
| 701 | Device device = storager.queryVideoDevice(deviceId); | 749 | Device device = storager.queryVideoDevice(deviceId); |
| 702 | if (device == null) { | 750 | if (device == null) { |
| 703 | logger.warn("处理alarm设备报警信息未找到设备信息"); | 751 | logger.warn("处理alarm设备报警信息未找到设备信息"); |
| 752 | + response404Ack(evt); | ||
| 704 | return; | 753 | return; |
| 705 | } | 754 | } |
| 706 | Element rootElement = getRootElement(evt, device.getCharset()); | 755 | Element rootElement = getRootElement(evt, device.getCharset()); |
| 707 | Element deviceIdElement = rootElement.element("DeviceID"); | 756 | Element deviceIdElement = rootElement.element("DeviceID"); |
| 708 | String channelId = deviceIdElement.getText().toString(); | 757 | String channelId = deviceIdElement.getText().toString(); |
| 758 | + String key = DeferredResultHolder.CALLBACK_CMD_ALARM + deviceId + channelId; | ||
| 709 | // 回复200 OK | 759 | // 回复200 OK |
| 710 | responseAck(evt); | 760 | responseAck(evt); |
| 711 | 761 | ||
| @@ -770,10 +820,9 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { | @@ -770,10 +820,9 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { | ||
| 770 | logger.debug(json.toJSONString()); | 820 | logger.debug(json.toJSONString()); |
| 771 | } | 821 | } |
| 772 | RequestMessage msg = new RequestMessage(); | 822 | RequestMessage msg = new RequestMessage(); |
| 773 | - msg.setDeviceId(deviceId); | ||
| 774 | - msg.setType(DeferredResultHolder.CALLBACK_CMD_ALARM); | 823 | + msg.setKey(key); |
| 775 | msg.setData(json); | 824 | msg.setData(json); |
| 776 | - deferredResultHolder.invokeResult(msg); | 825 | + deferredResultHolder.invokeAllResult(msg); |
| 777 | } | 826 | } |
| 778 | } catch (DocumentException | SipException | InvalidArgumentException | ParseException e) { | 827 | } catch (DocumentException | SipException | InvalidArgumentException | ParseException e) { |
| 779 | e.printStackTrace(); | 828 | e.printStackTrace(); |
| @@ -787,10 +836,14 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { | @@ -787,10 +836,14 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { | ||
| 787 | */ | 836 | */ |
| 788 | private void processMessageKeepAlive(RequestEvent evt) { | 837 | private void processMessageKeepAlive(RequestEvent evt) { |
| 789 | try { | 838 | try { |
| 790 | - Element rootElement = getRootElement(evt); | ||
| 791 | - String deviceId = XmlUtil.getText(rootElement, "DeviceID"); | 839 | + |
| 840 | + String deviceId = SipUtils.getUserIdFromFromHeader(evt.getRequest()); | ||
| 841 | + // 查询设备是否存在 | ||
| 792 | Device device = storager.queryVideoDevice(deviceId); | 842 | Device device = storager.queryVideoDevice(deviceId); |
| 793 | 843 | ||
| 844 | + Element rootElement = getRootElement(evt); | ||
| 845 | + String channelId = XmlUtil.getText(rootElement, "DeviceID"); | ||
| 846 | + | ||
| 794 | // 检查设备是否存在并在线, 不在线则设置为在线 | 847 | // 检查设备是否存在并在线, 不在线则设置为在线 |
| 795 | if (device != null ) { | 848 | if (device != null ) { |
| 796 | // 回复200 OK | 849 | // 回复200 OK |
| @@ -831,18 +884,29 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { | @@ -831,18 +884,29 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { | ||
| 831 | */ | 884 | */ |
| 832 | private void processMessageRecordInfo(RequestEvent evt) { | 885 | private void processMessageRecordInfo(RequestEvent evt) { |
| 833 | try { | 886 | try { |
| 887 | + | ||
| 888 | + String deviceId = SipUtils.getUserIdFromFromHeader(evt.getRequest()); | ||
| 889 | + // 查询设备是否存在 | ||
| 890 | + Device device = storager.queryVideoDevice(deviceId); | ||
| 891 | + if (device == null) { | ||
| 892 | + logger.warn("处理DeviceInfo设备信息Message时未找到设备信息"); | ||
| 893 | + response404Ack(evt); | ||
| 894 | + return; | ||
| 895 | + } | ||
| 896 | + | ||
| 834 | // 回复200 OK | 897 | // 回复200 OK |
| 835 | responseAck(evt); | 898 | responseAck(evt); |
| 836 | String uuid = UUID.randomUUID().toString().replace("-", ""); | 899 | String uuid = UUID.randomUUID().toString().replace("-", ""); |
| 837 | RecordInfo recordInfo = new RecordInfo(); | 900 | RecordInfo recordInfo = new RecordInfo(); |
| 838 | Element rootElement = getRootElement(evt); | 901 | Element rootElement = getRootElement(evt); |
| 839 | Element deviceIdElement = rootElement.element("DeviceID"); | 902 | Element deviceIdElement = rootElement.element("DeviceID"); |
| 840 | - String deviceId = deviceIdElement.getText().toString(); | ||
| 841 | - Device device = storager.queryVideoDevice(deviceId); | 903 | + String channelId = deviceIdElement.getText().toString(); |
| 904 | + String key = DeferredResultHolder.CALLBACK_CMD_RECORDINFO + deviceId + channelId; | ||
| 842 | if (device != null ) { | 905 | if (device != null ) { |
| 843 | rootElement = getRootElement(evt, device.getCharset()); | 906 | rootElement = getRootElement(evt, device.getCharset()); |
| 844 | } | 907 | } |
| 845 | recordInfo.setDeviceId(deviceId); | 908 | recordInfo.setDeviceId(deviceId); |
| 909 | + recordInfo.setChannelId(channelId); | ||
| 846 | recordInfo.setName(XmlUtil.getText(rootElement, "Name")); | 910 | recordInfo.setName(XmlUtil.getText(rootElement, "Name")); |
| 847 | if (XmlUtil.getText(rootElement, "SumNum")== null || XmlUtil.getText(rootElement, "SumNum") =="") { | 911 | if (XmlUtil.getText(rootElement, "SumNum")== null || XmlUtil.getText(rootElement, "SumNum") =="") { |
| 848 | recordInfo.setSumNum(0); | 912 | recordInfo.setSumNum(0); |
| @@ -854,10 +918,9 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { | @@ -854,10 +918,9 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { | ||
| 854 | if (recordListElement == null || recordInfo.getSumNum() == 0) { | 918 | if (recordListElement == null || recordInfo.getSumNum() == 0) { |
| 855 | logger.info("无录像数据"); | 919 | logger.info("无录像数据"); |
| 856 | RequestMessage msg = new RequestMessage(); | 920 | RequestMessage msg = new RequestMessage(); |
| 857 | - msg.setDeviceId(deviceId); | ||
| 858 | - msg.setType(DeferredResultHolder.CALLBACK_CMD_RECORDINFO); | 921 | + msg.setKey(key); |
| 859 | msg.setData(recordInfo); | 922 | msg.setData(recordInfo); |
| 860 | - deferredResultHolder.invokeResult(msg); | 923 | + deferredResultHolder.invokeAllResult(msg); |
| 861 | } else { | 924 | } else { |
| 862 | Iterator<Element> recordListIterator = recordListElement.elementIterator(); | 925 | Iterator<Element> recordListIterator = recordListElement.elementIterator(); |
| 863 | List<RecordItem> recordList = new ArrayList<RecordItem>(); | 926 | List<RecordItem> recordList = new ArrayList<RecordItem>(); |
| @@ -956,10 +1019,20 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { | @@ -956,10 +1019,20 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { | ||
| 956 | */ | 1019 | */ |
| 957 | private void processMessageMediaStatus(RequestEvent evt){ | 1020 | private void processMessageMediaStatus(RequestEvent evt){ |
| 958 | try { | 1021 | try { |
| 1022 | + | ||
| 1023 | + String deviceId = SipUtils.getUserIdFromFromHeader(evt.getRequest()); | ||
| 1024 | + // 查询设备是否存在 | ||
| 1025 | + Device device = storager.queryVideoDevice(deviceId); | ||
| 1026 | + if (device == null) { | ||
| 1027 | + logger.warn("处理DeviceInfo设备信息Message时未找到设备信息"); | ||
| 1028 | + response404Ack(evt); | ||
| 1029 | + return; | ||
| 1030 | + } | ||
| 1031 | + | ||
| 959 | // 回复200 OK | 1032 | // 回复200 OK |
| 960 | responseAck(evt); | 1033 | responseAck(evt); |
| 961 | Element rootElement = getRootElement(evt); | 1034 | Element rootElement = getRootElement(evt); |
| 962 | - String deviceId = XmlUtil.getText(rootElement, "DeviceID"); | 1035 | + String channelId = XmlUtil.getText(rootElement, "DeviceID"); |
| 963 | String NotifyType =XmlUtil.getText(rootElement, "NotifyType"); | 1036 | String NotifyType =XmlUtil.getText(rootElement, "NotifyType"); |
| 964 | if (NotifyType.equals("121")){ | 1037 | if (NotifyType.equals("121")){ |
| 965 | logger.info("媒体播放完毕,通知关流"); | 1038 | logger.info("媒体播放完毕,通知关流"); |
| @@ -981,8 +1054,19 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { | @@ -981,8 +1054,19 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { | ||
| 981 | */ | 1054 | */ |
| 982 | private void processMessageBroadcast(RequestEvent evt) { | 1055 | private void processMessageBroadcast(RequestEvent evt) { |
| 983 | try { | 1056 | try { |
| 1057 | + | ||
| 1058 | + String deviceId = SipUtils.getUserIdFromFromHeader(evt.getRequest()); | ||
| 1059 | + // 查询设备是否存在 | ||
| 1060 | + Device device = storager.queryVideoDevice(deviceId); | ||
| 1061 | + if (device == null) { | ||
| 1062 | + logger.warn("处理DeviceInfo设备信息Message时未找到设备信息"); | ||
| 1063 | + response404Ack(evt); | ||
| 1064 | + return; | ||
| 1065 | + } | ||
| 1066 | + | ||
| 984 | Element rootElement = getRootElement(evt); | 1067 | Element rootElement = getRootElement(evt); |
| 985 | - String deviceId = XmlUtil.getText(rootElement, "DeviceID"); | 1068 | + String channelId = XmlUtil.getText(rootElement, "DeviceID"); |
| 1069 | + String key = DeferredResultHolder.CALLBACK_CMD_BROADCAST + deviceId + channelId; | ||
| 986 | // 回复200 OK | 1070 | // 回复200 OK |
| 987 | responseAck(evt); | 1071 | responseAck(evt); |
| 988 | if (rootElement.getName().equals("Response")) { | 1072 | if (rootElement.getName().equals("Response")) { |
| @@ -993,10 +1077,9 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { | @@ -993,10 +1077,9 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { | ||
| 993 | logger.debug(json.toJSONString()); | 1077 | logger.debug(json.toJSONString()); |
| 994 | } | 1078 | } |
| 995 | RequestMessage msg = new RequestMessage(); | 1079 | RequestMessage msg = new RequestMessage(); |
| 996 | - msg.setDeviceId(deviceId); | ||
| 997 | - msg.setType(DeferredResultHolder.CALLBACK_CMD_BROADCAST); | 1080 | + msg.setKey(key); |
| 998 | msg.setData(json); | 1081 | msg.setData(json); |
| 999 | - deferredResultHolder.invokeResult(msg); | 1082 | + deferredResultHolder.invokeAllResult(msg); |
| 1000 | } else { | 1083 | } else { |
| 1001 | // 此处是上级发出的Broadcast指令 | 1084 | // 此处是上级发出的Broadcast指令 |
| 1002 | } | 1085 | } |
src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java
| @@ -78,9 +78,11 @@ public class PlayServiceImpl implements IPlayService { | @@ -78,9 +78,11 @@ public class PlayServiceImpl implements IPlayService { | ||
| 78 | @Override | 78 | @Override |
| 79 | public PlayResult play(MediaServerItem mediaServerItem, String deviceId, String channelId, ZLMHttpHookSubscribe.Event hookEvent, SipSubscribe.Event errorEvent) { | 79 | public PlayResult play(MediaServerItem mediaServerItem, String deviceId, String channelId, ZLMHttpHookSubscribe.Event hookEvent, SipSubscribe.Event errorEvent) { |
| 80 | PlayResult playResult = new PlayResult(); | 80 | PlayResult playResult = new PlayResult(); |
| 81 | + RequestMessage msg = new RequestMessage(); | ||
| 82 | + String key = DeferredResultHolder.CALLBACK_CMD_PLAY + deviceId + channelId; | ||
| 83 | + msg.setKey(key); | ||
| 84 | + msg.setId(playResult.getUuid()); | ||
| 81 | if (mediaServerItem == null) { | 85 | if (mediaServerItem == null) { |
| 82 | - RequestMessage msg = new RequestMessage(); | ||
| 83 | - msg.setId(DeferredResultHolder.CALLBACK_CMD_PLAY + playResult.getUuid()); | ||
| 84 | WVPResult wvpResult = new WVPResult(); | 86 | WVPResult wvpResult = new WVPResult(); |
| 85 | wvpResult.setCode(-1); | 87 | wvpResult.setCode(-1); |
| 86 | wvpResult.setMsg("未找到可用的zlm"); | 88 | wvpResult.setMsg("未找到可用的zlm"); |
| @@ -88,20 +90,19 @@ public class PlayServiceImpl implements IPlayService { | @@ -88,20 +90,19 @@ public class PlayServiceImpl implements IPlayService { | ||
| 88 | resultHolder.invokeResult(msg); | 90 | resultHolder.invokeResult(msg); |
| 89 | return playResult; | 91 | return playResult; |
| 90 | } | 92 | } |
| 93 | + | ||
| 91 | Device device = storager.queryVideoDevice(deviceId); | 94 | Device device = storager.queryVideoDevice(deviceId); |
| 92 | StreamInfo streamInfo = redisCatchStorage.queryPlayByDevice(deviceId, channelId); | 95 | StreamInfo streamInfo = redisCatchStorage.queryPlayByDevice(deviceId, channelId); |
| 93 | playResult.setDevice(device); | 96 | playResult.setDevice(device); |
| 94 | - UUID uuid = UUID.randomUUID(); | ||
| 95 | - playResult.setUuid(uuid.toString()); | 97 | + String uuid = UUID.randomUUID().toString(); |
| 98 | + playResult.setUuid(uuid); | ||
| 96 | DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String>>(userSetup.getPlayTimeout()); | 99 | DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String>>(userSetup.getPlayTimeout()); |
| 97 | playResult.setResult(result); | 100 | playResult.setResult(result); |
| 98 | // 录像查询以channelId作为deviceId查询 | 101 | // 录像查询以channelId作为deviceId查询 |
| 99 | - resultHolder.put(DeferredResultHolder.CALLBACK_CMD_PLAY + uuid, result); | 102 | + resultHolder.put(key, uuid, result); |
| 100 | // 超时处理 | 103 | // 超时处理 |
| 101 | result.onTimeout(()->{ | 104 | result.onTimeout(()->{ |
| 102 | logger.warn(String.format("设备点播超时,deviceId:%s ,channelId:%s", deviceId, channelId)); | 105 | logger.warn(String.format("设备点播超时,deviceId:%s ,channelId:%s", deviceId, channelId)); |
| 103 | - RequestMessage msg = new RequestMessage(); | ||
| 104 | - msg.setId(DeferredResultHolder.CALLBACK_CMD_PLAY + playResult.getUuid()); | ||
| 105 | WVPResult wvpResult = new WVPResult(); | 106 | WVPResult wvpResult = new WVPResult(); |
| 106 | wvpResult.setCode(-1); | 107 | wvpResult.setCode(-1); |
| 107 | SIPDialog dialog = streamSession.getDialog(deviceId, channelId); | 108 | SIPDialog dialog = streamSession.getDialog(deviceId, channelId); |
| @@ -115,7 +116,8 @@ public class PlayServiceImpl implements IPlayService { | @@ -115,7 +116,8 @@ public class PlayServiceImpl implements IPlayService { | ||
| 115 | cmder.streamByeCmd(device.getDeviceId(), channelId); | 116 | cmder.streamByeCmd(device.getDeviceId(), channelId); |
| 116 | // 释放rtpserver | 117 | // 释放rtpserver |
| 117 | mediaServerService.closeRTPServer(playResult.getDevice(), channelId); | 118 | mediaServerService.closeRTPServer(playResult.getDevice(), channelId); |
| 118 | - resultHolder.invokeResult(msg); | 119 | + // 回复之前所有的点播请求 |
| 120 | + resultHolder.invokeAllResult(msg); | ||
| 119 | }); | 121 | }); |
| 120 | result.onCompletion(()->{ | 122 | result.onCompletion(()->{ |
| 121 | // 点播结束时调用截图接口 | 123 | // 点播结束时调用截图接口 |
| @@ -169,15 +171,13 @@ public class PlayServiceImpl implements IPlayService { | @@ -169,15 +171,13 @@ public class PlayServiceImpl implements IPlayService { | ||
| 169 | } | 171 | } |
| 170 | }, (event) -> { | 172 | }, (event) -> { |
| 171 | // 点播返回sip错误 | 173 | // 点播返回sip错误 |
| 172 | - RequestMessage msg = new RequestMessage(); | ||
| 173 | - msg.setId(DeferredResultHolder.CALLBACK_CMD_PLAY + uuid); | ||
| 174 | Response response = event.getResponse(); | 174 | Response response = event.getResponse(); |
| 175 | mediaServerService.closeRTPServer(playResult.getDevice(), channelId); | 175 | mediaServerService.closeRTPServer(playResult.getDevice(), channelId); |
| 176 | WVPResult wvpResult = new WVPResult(); | 176 | WVPResult wvpResult = new WVPResult(); |
| 177 | wvpResult.setCode(-1); | 177 | wvpResult.setCode(-1); |
| 178 | wvpResult.setMsg(String.format("点播失败, 错误码: %s, %s", response.getStatusCode(), response.getReasonPhrase())); | 178 | wvpResult.setMsg(String.format("点播失败, 错误码: %s, %s", response.getStatusCode(), response.getReasonPhrase())); |
| 179 | msg.setData(wvpResult); | 179 | msg.setData(wvpResult); |
| 180 | - resultHolder.invokeResult(msg); | 180 | + resultHolder.invokeAllResult(msg); |
| 181 | if (errorEvent != null) { | 181 | if (errorEvent != null) { |
| 182 | errorEvent.response(event); | 182 | errorEvent.response(event); |
| 183 | } | 183 | } |
| @@ -186,13 +186,11 @@ public class PlayServiceImpl implements IPlayService { | @@ -186,13 +186,11 @@ public class PlayServiceImpl implements IPlayService { | ||
| 186 | } else { | 186 | } else { |
| 187 | String streamId = streamInfo.getStreamId(); | 187 | String streamId = streamInfo.getStreamId(); |
| 188 | if (streamId == null) { | 188 | if (streamId == null) { |
| 189 | - RequestMessage msg = new RequestMessage(); | ||
| 190 | - msg.setId(DeferredResultHolder.CALLBACK_CMD_PLAY + uuid); | ||
| 191 | WVPResult wvpResult = new WVPResult(); | 189 | WVPResult wvpResult = new WVPResult(); |
| 192 | wvpResult.setCode(-1); | 190 | wvpResult.setCode(-1); |
| 193 | wvpResult.setMsg(String.format("点播失败, redis缓存streamId等于null")); | 191 | wvpResult.setMsg(String.format("点播失败, redis缓存streamId等于null")); |
| 194 | msg.setData(wvpResult); | 192 | msg.setData(wvpResult); |
| 195 | - resultHolder.invokeResult(msg); | 193 | + resultHolder.invokeAllResult(msg); |
| 196 | return playResult; | 194 | return playResult; |
| 197 | } | 195 | } |
| 198 | String mediaServerId = streamInfo.getMediaServerId(); | 196 | String mediaServerId = streamInfo.getMediaServerId(); |
| @@ -200,8 +198,6 @@ public class PlayServiceImpl implements IPlayService { | @@ -200,8 +198,6 @@ public class PlayServiceImpl implements IPlayService { | ||
| 200 | 198 | ||
| 201 | JSONObject rtpInfo = zlmresTfulUtils.getRtpInfo(mediaInfo, streamId); | 199 | JSONObject rtpInfo = zlmresTfulUtils.getRtpInfo(mediaInfo, streamId); |
| 202 | if (rtpInfo != null && rtpInfo.getBoolean("exist")) { | 200 | if (rtpInfo != null && rtpInfo.getBoolean("exist")) { |
| 203 | - RequestMessage msg = new RequestMessage(); | ||
| 204 | - msg.setId(DeferredResultHolder.CALLBACK_CMD_PLAY + uuid); | ||
| 205 | 201 | ||
| 206 | WVPResult wvpResult = new WVPResult(); | 202 | WVPResult wvpResult = new WVPResult(); |
| 207 | wvpResult.setCode(0); | 203 | wvpResult.setCode(0); |
| @@ -209,7 +205,7 @@ public class PlayServiceImpl implements IPlayService { | @@ -209,7 +205,7 @@ public class PlayServiceImpl implements IPlayService { | ||
| 209 | wvpResult.setData(streamInfo); | 205 | wvpResult.setData(streamInfo); |
| 210 | msg.setData(wvpResult); | 206 | msg.setData(wvpResult); |
| 211 | 207 | ||
| 212 | - resultHolder.invokeResult(msg); | 208 | + resultHolder.invokeAllResult(msg); |
| 213 | if (hookEvent != null) { | 209 | if (hookEvent != null) { |
| 214 | hookEvent.response(mediaServerItem, JSONObject.parseObject(JSON.toJSONString(streamInfo))); | 210 | hookEvent.response(mediaServerItem, JSONObject.parseObject(JSON.toJSONString(streamInfo))); |
| 215 | } | 211 | } |
| @@ -229,15 +225,13 @@ public class PlayServiceImpl implements IPlayService { | @@ -229,15 +225,13 @@ public class PlayServiceImpl implements IPlayService { | ||
| 229 | onPublishHandlerForPlay(mediaServerItemInuse, response, deviceId, channelId, uuid.toString()); | 225 | onPublishHandlerForPlay(mediaServerItemInuse, response, deviceId, channelId, uuid.toString()); |
| 230 | }, (event) -> { | 226 | }, (event) -> { |
| 231 | mediaServerService.closeRTPServer(playResult.getDevice(), channelId); | 227 | mediaServerService.closeRTPServer(playResult.getDevice(), channelId); |
| 232 | - RequestMessage msg = new RequestMessage(); | ||
| 233 | - msg.setId(DeferredResultHolder.CALLBACK_CMD_PLAY + uuid); | ||
| 234 | Response response = event.getResponse(); | 228 | Response response = event.getResponse(); |
| 235 | 229 | ||
| 236 | WVPResult wvpResult = new WVPResult(); | 230 | WVPResult wvpResult = new WVPResult(); |
| 237 | wvpResult.setCode(-1); | 231 | wvpResult.setCode(-1); |
| 238 | wvpResult.setMsg(String.format("点播失败, 错误码: %s, %s", response.getStatusCode(), response.getReasonPhrase())); | 232 | wvpResult.setMsg(String.format("点播失败, 错误码: %s, %s", response.getStatusCode(), response.getReasonPhrase())); |
| 239 | msg.setData(wvpResult); | 233 | msg.setData(wvpResult); |
| 240 | - resultHolder.invokeResult(msg); | 234 | + resultHolder.invokeAllResult(msg); |
| 241 | }); | 235 | }); |
| 242 | } | 236 | } |
| 243 | } | 237 | } |
| @@ -248,7 +242,8 @@ public class PlayServiceImpl implements IPlayService { | @@ -248,7 +242,8 @@ public class PlayServiceImpl implements IPlayService { | ||
| 248 | @Override | 242 | @Override |
| 249 | public void onPublishHandlerForPlay(MediaServerItem mediaServerItem, JSONObject resonse, String deviceId, String channelId, String uuid) { | 243 | public void onPublishHandlerForPlay(MediaServerItem mediaServerItem, JSONObject resonse, String deviceId, String channelId, String uuid) { |
| 250 | RequestMessage msg = new RequestMessage(); | 244 | RequestMessage msg = new RequestMessage(); |
| 251 | - msg.setId(DeferredResultHolder.CALLBACK_CMD_PLAY + uuid); | 245 | + msg.setId(uuid); |
| 246 | + msg.setKey(DeferredResultHolder.CALLBACK_CMD_PLAY + deviceId + channelId); | ||
| 252 | StreamInfo streamInfo = onPublishHandler(mediaServerItem, resonse, deviceId, channelId, uuid); | 247 | StreamInfo streamInfo = onPublishHandler(mediaServerItem, resonse, deviceId, channelId, uuid); |
| 253 | if (streamInfo != null) { | 248 | if (streamInfo != null) { |
| 254 | DeviceChannel deviceChannel = storager.queryChannel(deviceId, channelId); | 249 | DeviceChannel deviceChannel = storager.queryChannel(deviceId, channelId); |
| @@ -265,11 +260,11 @@ public class PlayServiceImpl implements IPlayService { | @@ -265,11 +260,11 @@ public class PlayServiceImpl implements IPlayService { | ||
| 265 | wvpResult.setData(streamInfo); | 260 | wvpResult.setData(streamInfo); |
| 266 | msg.setData(wvpResult); | 261 | msg.setData(wvpResult); |
| 267 | 262 | ||
| 268 | - resultHolder.invokeResult(msg); | 263 | + resultHolder.invokeAllResult(msg); |
| 269 | } else { | 264 | } else { |
| 270 | logger.warn("设备预览API调用失败!"); | 265 | logger.warn("设备预览API调用失败!"); |
| 271 | msg.setData("设备预览API调用失败!"); | 266 | msg.setData("设备预览API调用失败!"); |
| 272 | - resultHolder.invokeResult(msg); | 267 | + resultHolder.invokeAllResult(msg); |
| 273 | } | 268 | } |
| 274 | } | 269 | } |
| 275 | 270 |
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/MobilePosition/MobilePositionController.java
| 1 | package com.genersoft.iot.vmp.vmanager.gb28181.MobilePosition; | 1 | package com.genersoft.iot.vmp.vmanager.gb28181.MobilePosition; |
| 2 | 2 | ||
| 3 | import java.util.List; | 3 | import java.util.List; |
| 4 | +import java.util.UUID; | ||
| 4 | 5 | ||
| 5 | import javax.sip.message.Response; | 6 | import javax.sip.message.Response; |
| 6 | 7 | ||
| @@ -111,10 +112,13 @@ public class MobilePositionController { | @@ -111,10 +112,13 @@ public class MobilePositionController { | ||
| 111 | @GetMapping("/realtime/{deviceId}") | 112 | @GetMapping("/realtime/{deviceId}") |
| 112 | public DeferredResult<ResponseEntity<MobilePosition>> realTimePosition(@PathVariable String deviceId) { | 113 | public DeferredResult<ResponseEntity<MobilePosition>> realTimePosition(@PathVariable String deviceId) { |
| 113 | Device device = storager.queryVideoDevice(deviceId); | 114 | Device device = storager.queryVideoDevice(deviceId); |
| 115 | + String uuid = UUID.randomUUID().toString(); | ||
| 116 | + String key = DeferredResultHolder.CALLBACK_CMD_MOBILEPOSITION + deviceId; | ||
| 114 | cmder.mobilePostitionQuery(device, event -> { | 117 | cmder.mobilePostitionQuery(device, event -> { |
| 115 | Response response = event.getResponse(); | 118 | Response response = event.getResponse(); |
| 116 | RequestMessage msg = new RequestMessage(); | 119 | RequestMessage msg = new RequestMessage(); |
| 117 | - msg.setId(DeferredResultHolder.CALLBACK_CMD_MOBILEPOSITION + deviceId); | 120 | + msg.setId(uuid); |
| 121 | + msg.setKey(key); | ||
| 118 | msg.setData(String.format("获取移动位置信息失败,错误码: %s, %s", response.getStatusCode(), response.getReasonPhrase())); | 122 | msg.setData(String.format("获取移动位置信息失败,错误码: %s, %s", response.getStatusCode(), response.getReasonPhrase())); |
| 119 | resultHolder.invokeResult(msg); | 123 | resultHolder.invokeResult(msg); |
| 120 | }); | 124 | }); |
| @@ -123,11 +127,12 @@ public class MobilePositionController { | @@ -123,11 +127,12 @@ public class MobilePositionController { | ||
| 123 | logger.warn(String.format("获取移动位置信息超时")); | 127 | logger.warn(String.format("获取移动位置信息超时")); |
| 124 | // 释放rtpserver | 128 | // 释放rtpserver |
| 125 | RequestMessage msg = new RequestMessage(); | 129 | RequestMessage msg = new RequestMessage(); |
| 126 | - msg.setId(DeferredResultHolder.CALLBACK_CMD_CATALOG+deviceId); | 130 | + msg.setId(uuid); |
| 131 | + msg.setKey(key); | ||
| 127 | msg.setData("Timeout"); | 132 | msg.setData("Timeout"); |
| 128 | resultHolder.invokeResult(msg); | 133 | resultHolder.invokeResult(msg); |
| 129 | }); | 134 | }); |
| 130 | - resultHolder.put(DeferredResultHolder.CALLBACK_CMD_CATALOG+deviceId, result); | 135 | + resultHolder.put(key, uuid, result); |
| 131 | return result; | 136 | return result; |
| 132 | } | 137 | } |
| 133 | 138 |
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/device/DeviceConfig.java
| @@ -28,6 +28,8 @@ import org.springframework.util.StringUtils; | @@ -28,6 +28,8 @@ import org.springframework.util.StringUtils; | ||
| 28 | import org.springframework.web.bind.annotation.*; | 28 | import org.springframework.web.bind.annotation.*; |
| 29 | import org.springframework.web.context.request.async.DeferredResult; | 29 | import org.springframework.web.context.request.async.DeferredResult; |
| 30 | 30 | ||
| 31 | +import java.util.UUID; | ||
| 32 | + | ||
| 31 | @Api(tags = "国标设备配置") | 33 | @Api(tags = "国标设备配置") |
| 32 | @CrossOrigin | 34 | @CrossOrigin |
| 33 | @RestController | 35 | @RestController |
| @@ -66,7 +68,7 @@ public class DeviceConfig { | @@ -66,7 +68,7 @@ public class DeviceConfig { | ||
| 66 | @ApiImplicitParam(name = "heartBeatCount", value ="心跳计数" ,dataTypeClass = String.class), | 68 | @ApiImplicitParam(name = "heartBeatCount", value ="心跳计数" ,dataTypeClass = String.class), |
| 67 | }) | 69 | }) |
| 68 | public DeferredResult<ResponseEntity<String>> homePositionApi(@PathVariable String deviceId, | 70 | public DeferredResult<ResponseEntity<String>> homePositionApi(@PathVariable String deviceId, |
| 69 | - @RequestParam(required = false) String channelId, | 71 | + String channelId, |
| 70 | @RequestParam(required = false) String name, | 72 | @RequestParam(required = false) String name, |
| 71 | @RequestParam(required = false) String expiration, | 73 | @RequestParam(required = false) String expiration, |
| 72 | @RequestParam(required = false) String heartBeatInterval, | 74 | @RequestParam(required = false) String heartBeatInterval, |
| @@ -75,10 +77,13 @@ public class DeviceConfig { | @@ -75,10 +77,13 @@ public class DeviceConfig { | ||
| 75 | logger.debug("报警复位API调用"); | 77 | logger.debug("报警复位API调用"); |
| 76 | } | 78 | } |
| 77 | Device device = storager.queryVideoDevice(deviceId); | 79 | Device device = storager.queryVideoDevice(deviceId); |
| 80 | + String uuid = UUID.randomUUID().toString(); | ||
| 81 | + String key = DeferredResultHolder.CALLBACK_CMD_DEVICECONFIG + deviceId + channelId; | ||
| 78 | cmder.deviceBasicConfigCmd(device, channelId, name, expiration, heartBeatInterval, heartBeatCount, event -> { | 82 | cmder.deviceBasicConfigCmd(device, channelId, name, expiration, heartBeatInterval, heartBeatCount, event -> { |
| 79 | Response response = event.getResponse(); | 83 | Response response = event.getResponse(); |
| 80 | RequestMessage msg = new RequestMessage(); | 84 | RequestMessage msg = new RequestMessage(); |
| 81 | - msg.setId(DeferredResultHolder.CALLBACK_CMD_DEVICECONFIG + (StringUtils.isEmpty(channelId) ? deviceId : channelId)); | 85 | + msg.setId(uuid); |
| 86 | + msg.setKey(key); | ||
| 82 | msg.setData(String.format("设备配置操作失败,错误码: %s, %s", response.getStatusCode(), response.getReasonPhrase())); | 87 | msg.setData(String.format("设备配置操作失败,错误码: %s, %s", response.getStatusCode(), response.getReasonPhrase())); |
| 83 | resultHolder.invokeResult(msg); | 88 | resultHolder.invokeResult(msg); |
| 84 | }); | 89 | }); |
| @@ -87,7 +92,8 @@ public class DeviceConfig { | @@ -87,7 +92,8 @@ public class DeviceConfig { | ||
| 87 | logger.warn(String.format("设备配置操作超时, 设备未返回应答指令")); | 92 | logger.warn(String.format("设备配置操作超时, 设备未返回应答指令")); |
| 88 | // 释放rtpserver | 93 | // 释放rtpserver |
| 89 | RequestMessage msg = new RequestMessage(); | 94 | RequestMessage msg = new RequestMessage(); |
| 90 | - msg.setId(DeferredResultHolder.CALLBACK_CMD_DEVICECONFIG + (StringUtils.isEmpty(channelId) ? deviceId : channelId)); | 95 | + msg.setId(uuid); |
| 96 | + msg.setKey(key); | ||
| 91 | JSONObject json = new JSONObject(); | 97 | JSONObject json = new JSONObject(); |
| 92 | json.put("DeviceID", deviceId); | 98 | json.put("DeviceID", deviceId); |
| 93 | json.put("Status", "Timeout"); | 99 | json.put("Status", "Timeout"); |
| @@ -95,7 +101,7 @@ public class DeviceConfig { | @@ -95,7 +101,7 @@ public class DeviceConfig { | ||
| 95 | msg.setData(json); //("看守位控制操作超时, 设备未返回应答指令"); | 101 | msg.setData(json); //("看守位控制操作超时, 设备未返回应答指令"); |
| 96 | resultHolder.invokeResult(msg); | 102 | resultHolder.invokeResult(msg); |
| 97 | }); | 103 | }); |
| 98 | - resultHolder.put(DeferredResultHolder.CALLBACK_CMD_DEVICECONFIG + (StringUtils.isEmpty(channelId) ? deviceId : channelId), result); | 104 | + resultHolder.put(key, uuid, result); |
| 99 | return result; | 105 | return result; |
| 100 | } | 106 | } |
| 101 | 107 | ||
| @@ -119,11 +125,14 @@ public class DeviceConfig { | @@ -119,11 +125,14 @@ public class DeviceConfig { | ||
| 119 | if (logger.isDebugEnabled()) { | 125 | if (logger.isDebugEnabled()) { |
| 120 | logger.debug("设备状态查询API调用"); | 126 | logger.debug("设备状态查询API调用"); |
| 121 | } | 127 | } |
| 128 | + String key = DeferredResultHolder.CALLBACK_CMD_CONFIGDOWNLOAD + (StringUtils.isEmpty(channelId) ? deviceId : channelId); | ||
| 129 | + String uuid = UUID.randomUUID().toString(); | ||
| 122 | Device device = storager.queryVideoDevice(deviceId); | 130 | Device device = storager.queryVideoDevice(deviceId); |
| 123 | cmder.deviceConfigQuery(device, channelId, configType, event -> { | 131 | cmder.deviceConfigQuery(device, channelId, configType, event -> { |
| 124 | Response response = event.getResponse(); | 132 | Response response = event.getResponse(); |
| 125 | RequestMessage msg = new RequestMessage(); | 133 | RequestMessage msg = new RequestMessage(); |
| 126 | - msg.setId(DeferredResultHolder.CALLBACK_CMD_CONFIGDOWNLOAD + (StringUtils.isEmpty(channelId) ? deviceId : channelId)); | 134 | + msg.setId(uuid); |
| 135 | + msg.setKey(key); | ||
| 127 | msg.setData(String.format("获取设备配置失败,错误码: %s, %s", response.getStatusCode(), response.getReasonPhrase())); | 136 | msg.setData(String.format("获取设备配置失败,错误码: %s, %s", response.getStatusCode(), response.getReasonPhrase())); |
| 128 | resultHolder.invokeResult(msg); | 137 | resultHolder.invokeResult(msg); |
| 129 | }); | 138 | }); |
| @@ -132,11 +141,12 @@ public class DeviceConfig { | @@ -132,11 +141,12 @@ public class DeviceConfig { | ||
| 132 | logger.warn(String.format("获取设备配置超时")); | 141 | logger.warn(String.format("获取设备配置超时")); |
| 133 | // 释放rtpserver | 142 | // 释放rtpserver |
| 134 | RequestMessage msg = new RequestMessage(); | 143 | RequestMessage msg = new RequestMessage(); |
| 135 | - msg.setId(DeferredResultHolder.CALLBACK_CMD_CONFIGDOWNLOAD + (StringUtils.isEmpty(channelId) ? deviceId : channelId)); | 144 | + msg.setId(uuid); |
| 145 | + msg.setKey(key); | ||
| 136 | msg.setData("Timeout. Device did not response to this command."); | 146 | msg.setData("Timeout. Device did not response to this command."); |
| 137 | resultHolder.invokeResult(msg); | 147 | resultHolder.invokeResult(msg); |
| 138 | }); | 148 | }); |
| 139 | - resultHolder.put(DeferredResultHolder.CALLBACK_CMD_CONFIGDOWNLOAD + (StringUtils.isEmpty(channelId) ? deviceId : channelId), result); | 149 | + resultHolder.put(key, uuid, result); |
| 140 | return result; | 150 | return result; |
| 141 | } | 151 | } |
| 142 | 152 |
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/device/DeviceControl.java
| @@ -29,6 +29,8 @@ import org.springframework.util.StringUtils; | @@ -29,6 +29,8 @@ import org.springframework.util.StringUtils; | ||
| 29 | import org.springframework.web.bind.annotation.*; | 29 | import org.springframework.web.bind.annotation.*; |
| 30 | import org.springframework.web.context.request.async.DeferredResult; | 30 | import org.springframework.web.context.request.async.DeferredResult; |
| 31 | 31 | ||
| 32 | +import java.util.UUID; | ||
| 33 | + | ||
| 32 | @Api(tags = "国标设备控制") | 34 | @Api(tags = "国标设备控制") |
| 33 | @CrossOrigin | 35 | @CrossOrigin |
| 34 | @RestController | 36 | @RestController |
| @@ -89,28 +91,36 @@ public class DeviceControl { | @@ -89,28 +91,36 @@ public class DeviceControl { | ||
| 89 | }) | 91 | }) |
| 90 | @GetMapping("/record/{deviceId}/{recordCmdStr}") | 92 | @GetMapping("/record/{deviceId}/{recordCmdStr}") |
| 91 | public DeferredResult<ResponseEntity<String>> recordApi(@PathVariable String deviceId, | 93 | public DeferredResult<ResponseEntity<String>> recordApi(@PathVariable String deviceId, |
| 92 | - @PathVariable String recordCmdStr, @RequestParam(required = false) String channelId) { | 94 | + @PathVariable String recordCmdStr, String channelId) { |
| 93 | if (logger.isDebugEnabled()) { | 95 | if (logger.isDebugEnabled()) { |
| 94 | logger.debug("开始/停止录像API调用"); | 96 | logger.debug("开始/停止录像API调用"); |
| 95 | } | 97 | } |
| 96 | Device device = storager.queryVideoDevice(deviceId); | 98 | Device device = storager.queryVideoDevice(deviceId); |
| 97 | - cmder.recordCmd(device, channelId, recordCmdStr, event -> { | ||
| 98 | - Response response = event.getResponse(); | ||
| 99 | - RequestMessage msg = new RequestMessage(); | ||
| 100 | - msg.setId(DeferredResultHolder.CALLBACK_CMD_DEVICECONTROL + (StringUtils.isEmpty(channelId) ? deviceId : channelId)); | ||
| 101 | - msg.setData(String.format("开始/停止录像操作失败,错误码: %s, %s", response.getStatusCode(), response.getReasonPhrase())); | ||
| 102 | - resultHolder.invokeResult(msg); | ||
| 103 | - }); | ||
| 104 | - DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String>>(3 * 1000L); | 99 | + String uuid = UUID.randomUUID().toString(); |
| 100 | + String key = DeferredResultHolder.CALLBACK_CMD_DEVICECONTROL + deviceId + channelId; | ||
| 101 | + DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String>>(3 * 1000L); | ||
| 105 | result.onTimeout(() -> { | 102 | result.onTimeout(() -> { |
| 106 | logger.warn(String.format("开始/停止录像操作超时, 设备未返回应答指令")); | 103 | logger.warn(String.format("开始/停止录像操作超时, 设备未返回应答指令")); |
| 107 | // 释放rtpserver | 104 | // 释放rtpserver |
| 108 | RequestMessage msg = new RequestMessage(); | 105 | RequestMessage msg = new RequestMessage(); |
| 109 | - msg.setId(DeferredResultHolder.CALLBACK_CMD_DEVICECONTROL + (StringUtils.isEmpty(channelId) ? deviceId : channelId)); | 106 | + msg.setKey(key); |
| 107 | + msg.setId(uuid); | ||
| 110 | msg.setData("Timeout. Device did not response to this command."); | 108 | msg.setData("Timeout. Device did not response to this command."); |
| 111 | - resultHolder.invokeResult(msg); | 109 | + resultHolder.invokeAllResult(msg); |
| 110 | + }); | ||
| 111 | + resultHolder.put(key, uuid, result); | ||
| 112 | + if (resultHolder.exist(key, null)){ | ||
| 113 | + return result; | ||
| 114 | + } | ||
| 115 | + cmder.recordCmd(device, channelId, recordCmdStr, event -> { | ||
| 116 | + Response response = event.getResponse(); | ||
| 117 | + RequestMessage msg = new RequestMessage(); | ||
| 118 | + msg.setId(uuid); | ||
| 119 | + msg.setKey(key); | ||
| 120 | + msg.setData(String.format("开始/停止录像操作失败,错误码: %s, %s", response.getStatusCode(), response.getReasonPhrase())); | ||
| 121 | + resultHolder.invokeAllResult(msg); | ||
| 112 | }); | 122 | }); |
| 113 | - resultHolder.put(DeferredResultHolder.CALLBACK_CMD_DEVICECONTROL + (StringUtils.isEmpty(channelId) ? deviceId : channelId), result); | 123 | + |
| 114 | return result; | 124 | return result; |
| 115 | } | 125 | } |
| 116 | 126 | ||
| @@ -123,32 +133,38 @@ public class DeviceControl { | @@ -123,32 +133,38 @@ public class DeviceControl { | ||
| 123 | @ApiOperation("布防/撤防命令") | 133 | @ApiOperation("布防/撤防命令") |
| 124 | @ApiImplicitParams({ | 134 | @ApiImplicitParams({ |
| 125 | @ApiImplicitParam(name = "deviceId", value = "设备ID", required = true, dataTypeClass = String.class), | 135 | @ApiImplicitParam(name = "deviceId", value = "设备ID", required = true, dataTypeClass = String.class), |
| 136 | + @ApiImplicitParam(name = "channelId", value ="通道编码" ,dataTypeClass = String.class), | ||
| 126 | @ApiImplicitParam(name = "guardCmdStr", value ="命令, 可选值:SetGuard(布防),ResetGuard(撤防)", required = true, | 137 | @ApiImplicitParam(name = "guardCmdStr", value ="命令, 可选值:SetGuard(布防),ResetGuard(撤防)", required = true, |
| 127 | dataTypeClass = String.class) | 138 | dataTypeClass = String.class) |
| 128 | }) | 139 | }) |
| 129 | @GetMapping("/guard/{deviceId}/{guardCmdStr}") | 140 | @GetMapping("/guard/{deviceId}/{guardCmdStr}") |
| 130 | - public DeferredResult<ResponseEntity<String>> guardApi(@PathVariable String deviceId, @PathVariable String guardCmdStr) { | 141 | + public DeferredResult<ResponseEntity<String>> guardApi(@PathVariable String deviceId, String channelId, @PathVariable String guardCmdStr) { |
| 131 | if (logger.isDebugEnabled()) { | 142 | if (logger.isDebugEnabled()) { |
| 132 | logger.debug("布防/撤防API调用"); | 143 | logger.debug("布防/撤防API调用"); |
| 133 | } | 144 | } |
| 134 | Device device = storager.queryVideoDevice(deviceId); | 145 | Device device = storager.queryVideoDevice(deviceId); |
| 146 | + String key = DeferredResultHolder.CALLBACK_CMD_DEVICECONTROL + deviceId + channelId; | ||
| 147 | + String uuid =UUID.randomUUID().toString(); | ||
| 135 | cmder.guardCmd(device, guardCmdStr, event -> { | 148 | cmder.guardCmd(device, guardCmdStr, event -> { |
| 136 | Response response = event.getResponse(); | 149 | Response response = event.getResponse(); |
| 137 | RequestMessage msg = new RequestMessage(); | 150 | RequestMessage msg = new RequestMessage(); |
| 138 | - msg.setId(DeferredResultHolder.CALLBACK_CMD_DEVICECONTROL + deviceId); | 151 | + msg.setId(uuid); |
| 152 | + msg.setKey(key); | ||
| 139 | msg.setData(String.format("布防/撤防操作失败,错误码: %s, %s", response.getStatusCode(), response.getReasonPhrase())); | 153 | msg.setData(String.format("布防/撤防操作失败,错误码: %s, %s", response.getStatusCode(), response.getReasonPhrase())); |
| 140 | resultHolder.invokeResult(msg); | 154 | resultHolder.invokeResult(msg); |
| 141 | }); | 155 | }); |
| 142 | DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String>>(3 * 1000L); | 156 | DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String>>(3 * 1000L); |
| 157 | + resultHolder.put(key, uuid, result); | ||
| 143 | result.onTimeout(() -> { | 158 | result.onTimeout(() -> { |
| 144 | logger.warn(String.format("布防/撤防操作超时, 设备未返回应答指令")); | 159 | logger.warn(String.format("布防/撤防操作超时, 设备未返回应答指令")); |
| 145 | // 释放rtpserver | 160 | // 释放rtpserver |
| 146 | RequestMessage msg = new RequestMessage(); | 161 | RequestMessage msg = new RequestMessage(); |
| 147 | - msg.setId(DeferredResultHolder.CALLBACK_CMD_DEVICECONTROL + deviceId); | 162 | + msg.setKey(key); |
| 163 | + msg.setId(uuid); | ||
| 148 | msg.setData("Timeout. Device did not response to this command."); | 164 | msg.setData("Timeout. Device did not response to this command."); |
| 149 | resultHolder.invokeResult(msg); | 165 | resultHolder.invokeResult(msg); |
| 150 | }); | 166 | }); |
| 151 | - resultHolder.put(DeferredResultHolder.CALLBACK_CMD_DEVICECONTROL + deviceId, result); | 167 | + |
| 152 | return result; | 168 | return result; |
| 153 | } | 169 | } |
| 154 | 170 | ||
| @@ -162,21 +178,25 @@ public class DeviceControl { | @@ -162,21 +178,25 @@ public class DeviceControl { | ||
| 162 | @ApiOperation("报警复位") | 178 | @ApiOperation("报警复位") |
| 163 | @ApiImplicitParams({ | 179 | @ApiImplicitParams({ |
| 164 | @ApiImplicitParam(name = "deviceId", value = "设备ID", required = true, dataTypeClass = String.class), | 180 | @ApiImplicitParam(name = "deviceId", value = "设备ID", required = true, dataTypeClass = String.class), |
| 181 | + @ApiImplicitParam(name = "channelId", value ="通道编码" ,dataTypeClass = String.class), | ||
| 165 | @ApiImplicitParam(name = "alarmMethod", value ="报警方式", dataTypeClass = String.class), | 182 | @ApiImplicitParam(name = "alarmMethod", value ="报警方式", dataTypeClass = String.class), |
| 166 | @ApiImplicitParam(name = "alarmType", value ="报警类型", dataTypeClass = String.class), | 183 | @ApiImplicitParam(name = "alarmType", value ="报警类型", dataTypeClass = String.class), |
| 167 | }) | 184 | }) |
| 168 | @GetMapping("/reset_alarm/{deviceId}") | 185 | @GetMapping("/reset_alarm/{deviceId}") |
| 169 | - public DeferredResult<ResponseEntity<String>> resetAlarmApi(@PathVariable String deviceId, | 186 | + public DeferredResult<ResponseEntity<String>> resetAlarmApi(@PathVariable String deviceId, String channelId, |
| 170 | @RequestParam(required = false) String alarmMethod, | 187 | @RequestParam(required = false) String alarmMethod, |
| 171 | @RequestParam(required = false) String alarmType) { | 188 | @RequestParam(required = false) String alarmType) { |
| 172 | if (logger.isDebugEnabled()) { | 189 | if (logger.isDebugEnabled()) { |
| 173 | logger.debug("报警复位API调用"); | 190 | logger.debug("报警复位API调用"); |
| 174 | } | 191 | } |
| 175 | Device device = storager.queryVideoDevice(deviceId); | 192 | Device device = storager.queryVideoDevice(deviceId); |
| 193 | + String uuid = UUID.randomUUID().toString(); | ||
| 194 | + String key = DeferredResultHolder.CALLBACK_CMD_DEVICECONTROL + deviceId + channelId; | ||
| 176 | cmder.alarmCmd(device, alarmMethod, alarmType, event -> { | 195 | cmder.alarmCmd(device, alarmMethod, alarmType, event -> { |
| 177 | Response response = event.getResponse(); | 196 | Response response = event.getResponse(); |
| 178 | RequestMessage msg = new RequestMessage(); | 197 | RequestMessage msg = new RequestMessage(); |
| 179 | - msg.setId(DeferredResultHolder.CALLBACK_CMD_DEVICECONTROL + deviceId); | 198 | + msg.setId(uuid); |
| 199 | + msg.setKey(key); | ||
| 180 | msg.setData(String.format("报警复位操作失败,错误码: %s, %s", response.getStatusCode(), response.getReasonPhrase())); | 200 | msg.setData(String.format("报警复位操作失败,错误码: %s, %s", response.getStatusCode(), response.getReasonPhrase())); |
| 181 | resultHolder.invokeResult(msg); | 201 | resultHolder.invokeResult(msg); |
| 182 | }); | 202 | }); |
| @@ -185,11 +205,12 @@ public class DeviceControl { | @@ -185,11 +205,12 @@ public class DeviceControl { | ||
| 185 | logger.warn(String.format("报警复位操作超时, 设备未返回应答指令")); | 205 | logger.warn(String.format("报警复位操作超时, 设备未返回应答指令")); |
| 186 | // 释放rtpserver | 206 | // 释放rtpserver |
| 187 | RequestMessage msg = new RequestMessage(); | 207 | RequestMessage msg = new RequestMessage(); |
| 188 | - msg.setId(DeferredResultHolder.CALLBACK_CMD_DEVICECONTROL + deviceId); | 208 | + msg.setId(uuid); |
| 209 | + msg.setKey(key); | ||
| 189 | msg.setData("Timeout. Device did not response to this command."); | 210 | msg.setData("Timeout. Device did not response to this command."); |
| 190 | resultHolder.invokeResult(msg); | 211 | resultHolder.invokeResult(msg); |
| 191 | }); | 212 | }); |
| 192 | - resultHolder.put(DeferredResultHolder.CALLBACK_CMD_DEVICECONTROL + deviceId, result); | 213 | + resultHolder.put(key, uuid, result); |
| 193 | return result; | 214 | return result; |
| 194 | } | 215 | } |
| 195 | 216 | ||
| @@ -236,6 +257,7 @@ public class DeviceControl { | @@ -236,6 +257,7 @@ public class DeviceControl { | ||
| 236 | @ApiOperation("看守位控制") | 257 | @ApiOperation("看守位控制") |
| 237 | @ApiImplicitParams({ | 258 | @ApiImplicitParams({ |
| 238 | @ApiImplicitParam(name = "deviceId", value = "设备ID", required = true, dataTypeClass = String.class), | 259 | @ApiImplicitParam(name = "deviceId", value = "设备ID", required = true, dataTypeClass = String.class), |
| 260 | + @ApiImplicitParam(name = "channelId", value ="通道编码" ,dataTypeClass = String.class), | ||
| 239 | @ApiImplicitParam(name = "enabled", value = "是否开启看守位 1:开启,0:关闭", required = true, dataTypeClass = String.class), | 261 | @ApiImplicitParam(name = "enabled", value = "是否开启看守位 1:开启,0:关闭", required = true, dataTypeClass = String.class), |
| 240 | @ApiImplicitParam(name = "resetTime", value = "自动归位时间间隔", dataTypeClass = String.class), | 262 | @ApiImplicitParam(name = "resetTime", value = "自动归位时间间隔", dataTypeClass = String.class), |
| 241 | @ApiImplicitParam(name = "presetIndex", value = "调用预置位编号", dataTypeClass = String.class), | 263 | @ApiImplicitParam(name = "presetIndex", value = "调用预置位编号", dataTypeClass = String.class), |
| @@ -246,15 +268,18 @@ public class DeviceControl { | @@ -246,15 +268,18 @@ public class DeviceControl { | ||
| 246 | @PathVariable String enabled, | 268 | @PathVariable String enabled, |
| 247 | @RequestParam(required = false) String resetTime, | 269 | @RequestParam(required = false) String resetTime, |
| 248 | @RequestParam(required = false) String presetIndex, | 270 | @RequestParam(required = false) String presetIndex, |
| 249 | - @RequestParam(required = false) String channelId) { | 271 | + String channelId) { |
| 250 | if (logger.isDebugEnabled()) { | 272 | if (logger.isDebugEnabled()) { |
| 251 | logger.debug("报警复位API调用"); | 273 | logger.debug("报警复位API调用"); |
| 252 | } | 274 | } |
| 275 | + String key = DeferredResultHolder.CALLBACK_CMD_DEVICECONTROL + (StringUtils.isEmpty(channelId) ? deviceId : channelId); | ||
| 276 | + String uuid = UUID.randomUUID().toString(); | ||
| 253 | Device device = storager.queryVideoDevice(deviceId); | 277 | Device device = storager.queryVideoDevice(deviceId); |
| 254 | cmder.homePositionCmd(device, channelId, enabled, resetTime, presetIndex, event -> { | 278 | cmder.homePositionCmd(device, channelId, enabled, resetTime, presetIndex, event -> { |
| 255 | Response response = event.getResponse(); | 279 | Response response = event.getResponse(); |
| 256 | RequestMessage msg = new RequestMessage(); | 280 | RequestMessage msg = new RequestMessage(); |
| 257 | - msg.setId(DeferredResultHolder.CALLBACK_CMD_DEVICECONTROL + (StringUtils.isEmpty(channelId) ? deviceId : channelId)); | 281 | + msg.setId(uuid); |
| 282 | + msg.setKey(key); | ||
| 258 | msg.setData(String.format("看守位控制操作失败,错误码: %s, %s", response.getStatusCode(), response.getReasonPhrase())); | 283 | msg.setData(String.format("看守位控制操作失败,错误码: %s, %s", response.getStatusCode(), response.getReasonPhrase())); |
| 259 | resultHolder.invokeResult(msg); | 284 | resultHolder.invokeResult(msg); |
| 260 | }); | 285 | }); |
| @@ -263,7 +288,8 @@ public class DeviceControl { | @@ -263,7 +288,8 @@ public class DeviceControl { | ||
| 263 | logger.warn(String.format("看守位控制操作超时, 设备未返回应答指令")); | 288 | logger.warn(String.format("看守位控制操作超时, 设备未返回应答指令")); |
| 264 | // 释放rtpserver | 289 | // 释放rtpserver |
| 265 | RequestMessage msg = new RequestMessage(); | 290 | RequestMessage msg = new RequestMessage(); |
| 266 | - msg.setId(DeferredResultHolder.CALLBACK_CMD_DEVICECONTROL + (StringUtils.isEmpty(channelId) ? deviceId : channelId)); | 291 | + msg.setId(uuid); |
| 292 | + msg.setKey(key); | ||
| 267 | JSONObject json = new JSONObject(); | 293 | JSONObject json = new JSONObject(); |
| 268 | json.put("DeviceID", deviceId); | 294 | json.put("DeviceID", deviceId); |
| 269 | json.put("Status", "Timeout"); | 295 | json.put("Status", "Timeout"); |
| @@ -271,7 +297,7 @@ public class DeviceControl { | @@ -271,7 +297,7 @@ public class DeviceControl { | ||
| 271 | msg.setData(json); //("看守位控制操作超时, 设备未返回应答指令"); | 297 | msg.setData(json); //("看守位控制操作超时, 设备未返回应答指令"); |
| 272 | resultHolder.invokeResult(msg); | 298 | resultHolder.invokeResult(msg); |
| 273 | }); | 299 | }); |
| 274 | - resultHolder.put(DeferredResultHolder.CALLBACK_CMD_DEVICECONTROL + (StringUtils.isEmpty(channelId) ? deviceId : channelId), result); | 300 | + resultHolder.put(key, uuid, result); |
| 275 | return result; | 301 | return result; |
| 276 | } | 302 | } |
| 277 | } | 303 | } |
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/device/DeviceQuery.java
| @@ -24,6 +24,7 @@ import com.genersoft.iot.vmp.storager.IVideoManagerStorager; | @@ -24,6 +24,7 @@ import com.genersoft.iot.vmp.storager.IVideoManagerStorager; | ||
| 24 | 24 | ||
| 25 | import javax.sip.message.Response; | 25 | import javax.sip.message.Response; |
| 26 | import java.io.UnsupportedEncodingException; | 26 | import java.io.UnsupportedEncodingException; |
| 27 | +import java.util.UUID; | ||
| 27 | 28 | ||
| 28 | @Api(tags = "国标设备查询", value = "国标设备查询") | 29 | @Api(tags = "国标设备查询", value = "国标设备查询") |
| 29 | @SuppressWarnings("rawtypes") | 30 | @SuppressWarnings("rawtypes") |
| @@ -143,23 +144,32 @@ public class DeviceQuery { | @@ -143,23 +144,32 @@ public class DeviceQuery { | ||
| 143 | logger.debug("设备通道信息同步API调用,deviceId:" + deviceId); | 144 | logger.debug("设备通道信息同步API调用,deviceId:" + deviceId); |
| 144 | } | 145 | } |
| 145 | Device device = storager.queryVideoDevice(deviceId); | 146 | Device device = storager.queryVideoDevice(deviceId); |
| 146 | - cmder.catalogQuery(device, event -> { | ||
| 147 | - Response response = event.getResponse(); | ||
| 148 | - RequestMessage msg = new RequestMessage(); | ||
| 149 | - msg.setId(DeferredResultHolder.CALLBACK_CMD_CATALOG+deviceId); | ||
| 150 | - msg.setData(String.format("同步通道失败,错误码: %s, %s", response.getStatusCode(), response.getReasonPhrase())); | ||
| 151 | - resultHolder.invokeResult(msg); | ||
| 152 | - }); | ||
| 153 | - DeferredResult<ResponseEntity<Device>> result = new DeferredResult<ResponseEntity<Device>>(15*1000L); | 147 | + String key = DeferredResultHolder.CALLBACK_CMD_CATALOG + deviceId; |
| 148 | + String uuid = UUID.randomUUID().toString(); | ||
| 149 | + DeferredResult<ResponseEntity<Device>> result = new DeferredResult<ResponseEntity<Device>>(15*1000L); | ||
| 154 | result.onTimeout(()->{ | 150 | result.onTimeout(()->{ |
| 155 | logger.warn(String.format("设备通道信息同步超时")); | 151 | logger.warn(String.format("设备通道信息同步超时")); |
| 156 | // 释放rtpserver | 152 | // 释放rtpserver |
| 157 | RequestMessage msg = new RequestMessage(); | 153 | RequestMessage msg = new RequestMessage(); |
| 158 | - msg.setId(DeferredResultHolder.CALLBACK_CMD_CATALOG+deviceId); | 154 | + msg.setKey(key); |
| 155 | + msg.setId(uuid); | ||
| 159 | msg.setData("Timeout"); | 156 | msg.setData("Timeout"); |
| 160 | - resultHolder.invokeResult(msg); | 157 | + resultHolder.invokeAllResult(msg); |
| 161 | }); | 158 | }); |
| 162 | - resultHolder.put(DeferredResultHolder.CALLBACK_CMD_CATALOG+deviceId, result); | 159 | + // 等待其他相同请求返回时一起返回 |
| 160 | + if (resultHolder.exist(key, null)) { | ||
| 161 | + return result; | ||
| 162 | + } | ||
| 163 | + cmder.catalogQuery(device, event -> { | ||
| 164 | + Response response = event.getResponse(); | ||
| 165 | + RequestMessage msg = new RequestMessage(); | ||
| 166 | + msg.setKey(key); | ||
| 167 | + msg.setId(uuid); | ||
| 168 | + msg.setData(String.format("同步通道失败,错误码: %s, %s", response.getStatusCode(), response.getReasonPhrase())); | ||
| 169 | + resultHolder.invokeAllResult(msg); | ||
| 170 | + }); | ||
| 171 | + | ||
| 172 | + resultHolder.put(key, uuid, result); | ||
| 163 | return result; | 173 | return result; |
| 164 | } | 174 | } |
| 165 | 175 | ||
| @@ -316,10 +326,13 @@ public class DeviceQuery { | @@ -316,10 +326,13 @@ public class DeviceQuery { | ||
| 316 | logger.debug("设备状态查询API调用"); | 326 | logger.debug("设备状态查询API调用"); |
| 317 | } | 327 | } |
| 318 | Device device = storager.queryVideoDevice(deviceId); | 328 | Device device = storager.queryVideoDevice(deviceId); |
| 329 | + String uuid = UUID.randomUUID().toString(); | ||
| 330 | + String key = DeferredResultHolder.CALLBACK_CMD_DEVICESTATUS + deviceId; | ||
| 319 | cmder.deviceStatusQuery(device, event -> { | 331 | cmder.deviceStatusQuery(device, event -> { |
| 320 | Response response = event.getResponse(); | 332 | Response response = event.getResponse(); |
| 321 | RequestMessage msg = new RequestMessage(); | 333 | RequestMessage msg = new RequestMessage(); |
| 322 | - msg.setId(DeferredResultHolder.CALLBACK_CMD_DEVICESTATUS + deviceId); | 334 | + msg.setId(uuid); |
| 335 | + msg.setKey(key); | ||
| 323 | msg.setData(String.format("获取设备状态失败,错误码: %s, %s", response.getStatusCode(), response.getReasonPhrase())); | 336 | msg.setData(String.format("获取设备状态失败,错误码: %s, %s", response.getStatusCode(), response.getReasonPhrase())); |
| 324 | resultHolder.invokeResult(msg); | 337 | resultHolder.invokeResult(msg); |
| 325 | }); | 338 | }); |
| @@ -328,11 +341,12 @@ public class DeviceQuery { | @@ -328,11 +341,12 @@ public class DeviceQuery { | ||
| 328 | logger.warn(String.format("获取设备状态超时")); | 341 | logger.warn(String.format("获取设备状态超时")); |
| 329 | // 释放rtpserver | 342 | // 释放rtpserver |
| 330 | RequestMessage msg = new RequestMessage(); | 343 | RequestMessage msg = new RequestMessage(); |
| 331 | - msg.setId(DeferredResultHolder.CALLBACK_CMD_DEVICESTATUS + deviceId); | 344 | + msg.setId(uuid); |
| 345 | + msg.setKey(key); | ||
| 332 | msg.setData("Timeout. Device did not response to this command."); | 346 | msg.setData("Timeout. Device did not response to this command."); |
| 333 | resultHolder.invokeResult(msg); | 347 | resultHolder.invokeResult(msg); |
| 334 | }); | 348 | }); |
| 335 | - resultHolder.put(DeferredResultHolder.CALLBACK_CMD_DEVICESTATUS + deviceId, result); | 349 | + resultHolder.put(DeferredResultHolder.CALLBACK_CMD_DEVICESTATUS + deviceId, uuid, result); |
| 336 | return result; | 350 | return result; |
| 337 | } | 351 | } |
| 338 | 352 | ||
| @@ -369,10 +383,13 @@ public class DeviceQuery { | @@ -369,10 +383,13 @@ public class DeviceQuery { | ||
| 369 | logger.debug("设备报警查询API调用"); | 383 | logger.debug("设备报警查询API调用"); |
| 370 | } | 384 | } |
| 371 | Device device = storager.queryVideoDevice(deviceId); | 385 | Device device = storager.queryVideoDevice(deviceId); |
| 386 | + String key = DeferredResultHolder.CALLBACK_CMD_ALARM + deviceId; | ||
| 387 | + String uuid = UUID.randomUUID().toString(); | ||
| 372 | cmder.alarmInfoQuery(device, startPriority, endPriority, alarmMethod, alarmType, startTime, endTime, event -> { | 388 | cmder.alarmInfoQuery(device, startPriority, endPriority, alarmMethod, alarmType, startTime, endTime, event -> { |
| 373 | Response response = event.getResponse(); | 389 | Response response = event.getResponse(); |
| 374 | RequestMessage msg = new RequestMessage(); | 390 | RequestMessage msg = new RequestMessage(); |
| 375 | - msg.setId(DeferredResultHolder.CALLBACK_CMD_ALARM + deviceId); | 391 | + msg.setId(uuid); |
| 392 | + msg.setKey(key); | ||
| 376 | msg.setData(String.format("设备报警查询失败,错误码: %s, %s", response.getStatusCode(), response.getReasonPhrase())); | 393 | msg.setData(String.format("设备报警查询失败,错误码: %s, %s", response.getStatusCode(), response.getReasonPhrase())); |
| 377 | resultHolder.invokeResult(msg); | 394 | resultHolder.invokeResult(msg); |
| 378 | }); | 395 | }); |
| @@ -381,11 +398,12 @@ public class DeviceQuery { | @@ -381,11 +398,12 @@ public class DeviceQuery { | ||
| 381 | logger.warn(String.format("设备报警查询超时")); | 398 | logger.warn(String.format("设备报警查询超时")); |
| 382 | // 释放rtpserver | 399 | // 释放rtpserver |
| 383 | RequestMessage msg = new RequestMessage(); | 400 | RequestMessage msg = new RequestMessage(); |
| 384 | - msg.setId(DeferredResultHolder.CALLBACK_CMD_ALARM + deviceId); | 401 | + msg.setId(uuid); |
| 402 | + msg.setKey(key); | ||
| 385 | msg.setData("设备报警查询超时"); | 403 | msg.setData("设备报警查询超时"); |
| 386 | resultHolder.invokeResult(msg); | 404 | resultHolder.invokeResult(msg); |
| 387 | }); | 405 | }); |
| 388 | - resultHolder.put(DeferredResultHolder.CALLBACK_CMD_ALARM + deviceId, result); | 406 | + resultHolder.put(DeferredResultHolder.CALLBACK_CMD_ALARM + deviceId, uuid, result); |
| 389 | return result; | 407 | return result; |
| 390 | } | 408 | } |
| 391 | 409 |
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/play/PlayController.java
| @@ -103,28 +103,31 @@ public class PlayController { | @@ -103,28 +103,31 @@ public class PlayController { | ||
| 103 | 103 | ||
| 104 | logger.debug(String.format("设备预览/回放停止API调用,streamId:%s_%s", deviceId, channelId )); | 104 | logger.debug(String.format("设备预览/回放停止API调用,streamId:%s_%s", deviceId, channelId )); |
| 105 | 105 | ||
| 106 | - UUID uuid = UUID.randomUUID(); | 106 | + String uuid = UUID.randomUUID().toString(); |
| 107 | DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String>>(); | 107 | DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String>>(); |
| 108 | 108 | ||
| 109 | // 录像查询以channelId作为deviceId查询 | 109 | // 录像查询以channelId作为deviceId查询 |
| 110 | - resultHolder.put(DeferredResultHolder.CALLBACK_CMD_STOP + uuid, result); | 110 | + String key = DeferredResultHolder.CALLBACK_CMD_STOP + deviceId + channelId; |
| 111 | + resultHolder.put(key, uuid, result); | ||
| 111 | Device device = storager.queryVideoDevice(deviceId); | 112 | Device device = storager.queryVideoDevice(deviceId); |
| 112 | cmder.streamByeCmd(deviceId, channelId, (event) -> { | 113 | cmder.streamByeCmd(deviceId, channelId, (event) -> { |
| 113 | StreamInfo streamInfo = redisCatchStorage.queryPlayByDevice(deviceId, channelId); | 114 | StreamInfo streamInfo = redisCatchStorage.queryPlayByDevice(deviceId, channelId); |
| 114 | if (streamInfo == null) { | 115 | if (streamInfo == null) { |
| 115 | RequestMessage msg = new RequestMessage(); | 116 | RequestMessage msg = new RequestMessage(); |
| 116 | - msg.setId(DeferredResultHolder.CALLBACK_CMD_STOP + uuid); | 117 | + msg.setId(uuid); |
| 118 | + msg.setKey(key); | ||
| 117 | msg.setData("点播未找到"); | 119 | msg.setData("点播未找到"); |
| 118 | - resultHolder.invokeResult(msg); | 120 | + resultHolder.invokeAllResult(msg); |
| 119 | storager.stopPlay(deviceId, channelId); | 121 | storager.stopPlay(deviceId, channelId); |
| 120 | }else { | 122 | }else { |
| 121 | redisCatchStorage.stopPlay(streamInfo); | 123 | redisCatchStorage.stopPlay(streamInfo); |
| 122 | storager.stopPlay(streamInfo.getDeviceID(), streamInfo.getChannelId()); | 124 | storager.stopPlay(streamInfo.getDeviceID(), streamInfo.getChannelId()); |
| 123 | RequestMessage msg = new RequestMessage(); | 125 | RequestMessage msg = new RequestMessage(); |
| 124 | - msg.setId(DeferredResultHolder.CALLBACK_CMD_STOP + uuid); | 126 | + msg.setId(uuid); |
| 127 | + msg.setKey(key); | ||
| 125 | //Response response = event.getResponse(); | 128 | //Response response = event.getResponse(); |
| 126 | msg.setData(String.format("success")); | 129 | msg.setData(String.format("success")); |
| 127 | - resultHolder.invokeResult(msg); | 130 | + resultHolder.invokeAllResult(msg); |
| 128 | } | 131 | } |
| 129 | mediaServerService.closeRTPServer(device, channelId); | 132 | mediaServerService.closeRTPServer(device, channelId); |
| 130 | }); | 133 | }); |
| @@ -134,24 +137,27 @@ public class PlayController { | @@ -134,24 +137,27 @@ public class PlayController { | ||
| 134 | json.put("deviceId", deviceId); | 137 | json.put("deviceId", deviceId); |
| 135 | json.put("channelId", channelId); | 138 | json.put("channelId", channelId); |
| 136 | RequestMessage msg = new RequestMessage(); | 139 | RequestMessage msg = new RequestMessage(); |
| 137 | - msg.setId(DeferredResultHolder.CALLBACK_CMD_PLAY + uuid); | 140 | + msg.setId(uuid); |
| 141 | + msg.setKey(key); | ||
| 138 | msg.setData(json.toString()); | 142 | msg.setData(json.toString()); |
| 139 | - resultHolder.invokeResult(msg); | 143 | + resultHolder.invokeAllResult(msg); |
| 140 | } else { | 144 | } else { |
| 141 | logger.warn("设备预览/回放停止API调用失败!"); | 145 | logger.warn("设备预览/回放停止API调用失败!"); |
| 142 | RequestMessage msg = new RequestMessage(); | 146 | RequestMessage msg = new RequestMessage(); |
| 143 | - msg.setId(DeferredResultHolder.CALLBACK_CMD_PLAY + uuid); | 147 | + msg.setId(uuid); |
| 148 | + msg.setKey(key); | ||
| 144 | msg.setData("streamId null"); | 149 | msg.setData("streamId null"); |
| 145 | - resultHolder.invokeResult(msg); | 150 | + resultHolder.invokeAllResult(msg); |
| 146 | } | 151 | } |
| 147 | 152 | ||
| 148 | // 超时处理 | 153 | // 超时处理 |
| 149 | result.onTimeout(()->{ | 154 | result.onTimeout(()->{ |
| 150 | logger.warn(String.format("设备预览/回放停止超时,deviceId/channelId:%s_%s ", deviceId, channelId)); | 155 | logger.warn(String.format("设备预览/回放停止超时,deviceId/channelId:%s_%s ", deviceId, channelId)); |
| 151 | RequestMessage msg = new RequestMessage(); | 156 | RequestMessage msg = new RequestMessage(); |
| 152 | - msg.setId(DeferredResultHolder.CALLBACK_CMD_STOP + uuid); | 157 | + msg.setId(uuid); |
| 158 | + msg.setKey(key); | ||
| 153 | msg.setData("Timeout"); | 159 | msg.setData("Timeout"); |
| 154 | - resultHolder.invokeResult(msg); | 160 | + resultHolder.invokeAllResult(msg); |
| 155 | }); | 161 | }); |
| 156 | return result; | 162 | return result; |
| 157 | } | 163 | } |
| @@ -259,10 +265,18 @@ public class PlayController { | @@ -259,10 +265,18 @@ public class PlayController { | ||
| 259 | } | 265 | } |
| 260 | Device device = storager.queryVideoDevice(deviceId); | 266 | Device device = storager.queryVideoDevice(deviceId); |
| 261 | DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String>>(3 * 1000L); | 267 | DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String>>(3 * 1000L); |
| 268 | + String key = DeferredResultHolder.CALLBACK_CMD_BROADCAST + deviceId; | ||
| 269 | + if (resultHolder.exist(key, null)) { | ||
| 270 | + result.setResult(new ResponseEntity<>("设备使用中",HttpStatus.OK)); | ||
| 271 | + return result; | ||
| 272 | + } | ||
| 273 | + String uuid = UUID.randomUUID().toString(); | ||
| 262 | if (device == null) { | 274 | if (device == null) { |
| 263 | - resultHolder.put(DeferredResultHolder.CALLBACK_CMD_BROADCAST + deviceId, result); | 275 | + |
| 276 | + resultHolder.put(key, key, result); | ||
| 264 | RequestMessage msg = new RequestMessage(); | 277 | RequestMessage msg = new RequestMessage(); |
| 265 | - msg.setId(DeferredResultHolder.CALLBACK_CMD_BROADCAST + deviceId); | 278 | + msg.setKey(key); |
| 279 | + msg.setId(uuid); | ||
| 266 | JSONObject json = new JSONObject(); | 280 | JSONObject json = new JSONObject(); |
| 267 | json.put("DeviceID", deviceId); | 281 | json.put("DeviceID", deviceId); |
| 268 | json.put("CmdType", "Broadcast"); | 282 | json.put("CmdType", "Broadcast"); |
| @@ -275,7 +289,8 @@ public class PlayController { | @@ -275,7 +289,8 @@ public class PlayController { | ||
| 275 | cmder.audioBroadcastCmd(device, (event) -> { | 289 | cmder.audioBroadcastCmd(device, (event) -> { |
| 276 | Response response = event.getResponse(); | 290 | Response response = event.getResponse(); |
| 277 | RequestMessage msg = new RequestMessage(); | 291 | RequestMessage msg = new RequestMessage(); |
| 278 | - msg.setId(DeferredResultHolder.CALLBACK_CMD_BROADCAST + deviceId); | 292 | + msg.setKey(key); |
| 293 | + msg.setId(uuid); | ||
| 279 | JSONObject json = new JSONObject(); | 294 | JSONObject json = new JSONObject(); |
| 280 | json.put("DeviceID", deviceId); | 295 | json.put("DeviceID", deviceId); |
| 281 | json.put("CmdType", "Broadcast"); | 296 | json.put("CmdType", "Broadcast"); |
| @@ -288,7 +303,8 @@ public class PlayController { | @@ -288,7 +303,8 @@ public class PlayController { | ||
| 288 | result.onTimeout(() -> { | 303 | result.onTimeout(() -> { |
| 289 | logger.warn(String.format("语音广播操作超时, 设备未返回应答指令")); | 304 | logger.warn(String.format("语音广播操作超时, 设备未返回应答指令")); |
| 290 | RequestMessage msg = new RequestMessage(); | 305 | RequestMessage msg = new RequestMessage(); |
| 291 | - msg.setId(DeferredResultHolder.CALLBACK_CMD_BROADCAST + deviceId); | 306 | + msg.setKey(key); |
| 307 | + msg.setId(uuid); | ||
| 292 | JSONObject json = new JSONObject(); | 308 | JSONObject json = new JSONObject(); |
| 293 | json.put("DeviceID", deviceId); | 309 | json.put("DeviceID", deviceId); |
| 294 | json.put("CmdType", "Broadcast"); | 310 | json.put("CmdType", "Broadcast"); |
| @@ -297,7 +313,7 @@ public class PlayController { | @@ -297,7 +313,7 @@ public class PlayController { | ||
| 297 | msg.setData(json); | 313 | msg.setData(json); |
| 298 | resultHolder.invokeResult(msg); | 314 | resultHolder.invokeResult(msg); |
| 299 | }); | 315 | }); |
| 300 | - resultHolder.put(DeferredResultHolder.CALLBACK_CMD_BROADCAST + deviceId, result); | 316 | + resultHolder.put(key, uuid, result); |
| 301 | return result; | 317 | return result; |
| 302 | } | 318 | } |
| 303 | 319 |
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/playback/DownloadController.java
| @@ -76,30 +76,37 @@ public class DownloadController { | @@ -76,30 +76,37 @@ public class DownloadController { | ||
| 76 | if (logger.isDebugEnabled()) { | 76 | if (logger.isDebugEnabled()) { |
| 77 | logger.debug(String.format("历史媒体下载 API调用,deviceId:%s,channelId:%s,downloadSpeed:%s", deviceId, channelId, downloadSpeed)); | 77 | logger.debug(String.format("历史媒体下载 API调用,deviceId:%s,channelId:%s,downloadSpeed:%s", deviceId, channelId, downloadSpeed)); |
| 78 | } | 78 | } |
| 79 | - UUID uuid = UUID.randomUUID(); | 79 | + String key = DeferredResultHolder.CALLBACK_CMD_PLAY + deviceId + channelId + startTime + endTime; |
| 80 | + String uuid = UUID.randomUUID().toString(); | ||
| 80 | DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String>>(30000L); | 81 | DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String>>(30000L); |
| 81 | // 超时处理 | 82 | // 超时处理 |
| 82 | result.onTimeout(()->{ | 83 | result.onTimeout(()->{ |
| 83 | logger.warn(String.format("设备下载响应超时,deviceId:%s ,channelId:%s", deviceId, channelId)); | 84 | logger.warn(String.format("设备下载响应超时,deviceId:%s ,channelId:%s", deviceId, channelId)); |
| 84 | RequestMessage msg = new RequestMessage(); | 85 | RequestMessage msg = new RequestMessage(); |
| 85 | - msg.setId(DeferredResultHolder.CALLBACK_CMD_PLAY + uuid); | 86 | + msg.setId(uuid); |
| 87 | + msg.setKey(key); | ||
| 86 | msg.setData("Timeout"); | 88 | msg.setData("Timeout"); |
| 87 | - resultHolder.invokeResult(msg); | 89 | + resultHolder.invokeAllResult(msg); |
| 88 | }); | 90 | }); |
| 91 | + resultHolder.put(key, uuid, result); | ||
| 92 | + if(resultHolder.exist(key, null)) { | ||
| 93 | + return result; | ||
| 94 | + } | ||
| 89 | Device device = storager.queryVideoDevice(deviceId); | 95 | Device device = storager.queryVideoDevice(deviceId); |
| 90 | StreamInfo streamInfo = redisCatchStorage.queryPlaybackByDevice(deviceId, channelId); | 96 | StreamInfo streamInfo = redisCatchStorage.queryPlaybackByDevice(deviceId, channelId); |
| 91 | if (streamInfo != null) { | 97 | if (streamInfo != null) { |
| 92 | // 停止之前的下载 | 98 | // 停止之前的下载 |
| 93 | cmder.streamByeCmd(deviceId, channelId); | 99 | cmder.streamByeCmd(deviceId, channelId); |
| 94 | } | 100 | } |
| 95 | - resultHolder.put(DeferredResultHolder.CALLBACK_CMD_PLAY + uuid, result); | 101 | + |
| 96 | MediaServerItem newMediaServerItem = playService.getNewMediaServerItem(device); | 102 | MediaServerItem newMediaServerItem = playService.getNewMediaServerItem(device); |
| 97 | if (newMediaServerItem == null) { | 103 | if (newMediaServerItem == null) { |
| 98 | logger.warn(String.format("设备下载响应超时,deviceId:%s ,channelId:%s", deviceId, channelId)); | 104 | logger.warn(String.format("设备下载响应超时,deviceId:%s ,channelId:%s", deviceId, channelId)); |
| 99 | RequestMessage msg = new RequestMessage(); | 105 | RequestMessage msg = new RequestMessage(); |
| 100 | - msg.setId(DeferredResultHolder.CALLBACK_CMD_PLAY + uuid); | 106 | + msg.setId(uuid); |
| 107 | + msg.setKey(key); | ||
| 101 | msg.setData("Timeout"); | 108 | msg.setData("Timeout"); |
| 102 | - resultHolder.invokeResult(msg); | 109 | + resultHolder.invokeAllResult(msg); |
| 103 | return result; | 110 | return result; |
| 104 | } | 111 | } |
| 105 | 112 | ||
| @@ -111,9 +118,10 @@ public class DownloadController { | @@ -111,9 +118,10 @@ public class DownloadController { | ||
| 111 | }, event -> { | 118 | }, event -> { |
| 112 | Response response = event.getResponse(); | 119 | Response response = event.getResponse(); |
| 113 | RequestMessage msg = new RequestMessage(); | 120 | RequestMessage msg = new RequestMessage(); |
| 114 | - msg.setId(DeferredResultHolder.CALLBACK_CMD_PLAY + uuid); | 121 | + msg.setId(uuid); |
| 122 | + msg.setKey(key); | ||
| 115 | msg.setData(String.format("回放失败, 错误码: %s, %s", response.getStatusCode(), response.getReasonPhrase())); | 123 | msg.setData(String.format("回放失败, 错误码: %s, %s", response.getStatusCode(), response.getReasonPhrase())); |
| 116 | - resultHolder.invokeResult(msg); | 124 | + resultHolder.invokeAllResult(msg); |
| 117 | }); | 125 | }); |
| 118 | 126 | ||
| 119 | return result; | 127 | return result; |
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/playback/PlaybackController.java
| @@ -76,9 +76,9 @@ public class PlaybackController { | @@ -76,9 +76,9 @@ public class PlaybackController { | ||
| 76 | if (logger.isDebugEnabled()) { | 76 | if (logger.isDebugEnabled()) { |
| 77 | logger.debug(String.format("设备回放 API调用,deviceId:%s ,channelId:%s", deviceId, channelId)); | 77 | logger.debug(String.format("设备回放 API调用,deviceId:%s ,channelId:%s", deviceId, channelId)); |
| 78 | } | 78 | } |
| 79 | - UUID uuid = UUID.randomUUID(); | 79 | + String uuid = UUID.randomUUID().toString(); |
| 80 | + String key = DeferredResultHolder.CALLBACK_CMD_PLAY + deviceId + channelId + startTime + endTime; | ||
| 80 | DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String>>(30000L); | 81 | DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String>>(30000L); |
| 81 | - | ||
| 82 | Device device = storager.queryVideoDevice(deviceId); | 82 | Device device = storager.queryVideoDevice(deviceId); |
| 83 | if (device == null) { | 83 | if (device == null) { |
| 84 | result.setResult(new ResponseEntity<>(HttpStatus.BAD_REQUEST)); | 84 | result.setResult(new ResponseEntity<>(HttpStatus.BAD_REQUEST)); |
| @@ -91,7 +91,8 @@ public class PlaybackController { | @@ -91,7 +91,8 @@ public class PlaybackController { | ||
| 91 | result.onTimeout(()->{ | 91 | result.onTimeout(()->{ |
| 92 | logger.warn(String.format("设备回放超时,deviceId:%s ,channelId:%s", deviceId, channelId)); | 92 | logger.warn(String.format("设备回放超时,deviceId:%s ,channelId:%s", deviceId, channelId)); |
| 93 | RequestMessage msg = new RequestMessage(); | 93 | RequestMessage msg = new RequestMessage(); |
| 94 | - msg.setId(DeferredResultHolder.CALLBACK_CMD_PLAY + uuid); | 94 | + msg.setId(uuid); |
| 95 | + msg.setKey(key); | ||
| 95 | msg.setData("Timeout"); | 96 | msg.setData("Timeout"); |
| 96 | resultHolder.invokeResult(msg); | 97 | resultHolder.invokeResult(msg); |
| 97 | }); | 98 | }); |
| @@ -101,12 +102,13 @@ public class PlaybackController { | @@ -101,12 +102,13 @@ public class PlaybackController { | ||
| 101 | // 停止之前的回放 | 102 | // 停止之前的回放 |
| 102 | cmder.streamByeCmd(deviceId, channelId); | 103 | cmder.streamByeCmd(deviceId, channelId); |
| 103 | } | 104 | } |
| 104 | - resultHolder.put(DeferredResultHolder.CALLBACK_CMD_PLAY + uuid, result); | 105 | + resultHolder.put(DeferredResultHolder.CALLBACK_CMD_PLAY + deviceId + channelId + startTime + endTime, uuid, result); |
| 105 | 106 | ||
| 106 | if (newMediaServerItem == null) { | 107 | if (newMediaServerItem == null) { |
| 107 | logger.warn(String.format("设备回放超时,deviceId:%s ,channelId:%s", deviceId, channelId)); | 108 | logger.warn(String.format("设备回放超时,deviceId:%s ,channelId:%s", deviceId, channelId)); |
| 108 | RequestMessage msg = new RequestMessage(); | 109 | RequestMessage msg = new RequestMessage(); |
| 109 | - msg.setId(DeferredResultHolder.CALLBACK_CMD_PLAY + uuid); | 110 | + msg.setId(uuid); |
| 111 | + msg.setKey(key); | ||
| 110 | msg.setData("Timeout"); | 112 | msg.setData("Timeout"); |
| 111 | resultHolder.invokeResult(msg); | 113 | resultHolder.invokeResult(msg); |
| 112 | return result; | 114 | return result; |
| @@ -118,7 +120,8 @@ public class PlaybackController { | @@ -118,7 +120,8 @@ public class PlaybackController { | ||
| 118 | }, event -> { | 120 | }, event -> { |
| 119 | Response response = event.getResponse(); | 121 | Response response = event.getResponse(); |
| 120 | RequestMessage msg = new RequestMessage(); | 122 | RequestMessage msg = new RequestMessage(); |
| 121 | - msg.setId(DeferredResultHolder.CALLBACK_CMD_PLAY + uuid); | 123 | + msg.setId(uuid); |
| 124 | + msg.setKey(key); | ||
| 122 | msg.setData(String.format("回放失败, 错误码: %s, %s", response.getStatusCode(), response.getReasonPhrase())); | 125 | msg.setData(String.format("回放失败, 错误码: %s, %s", response.getStatusCode(), response.getReasonPhrase())); |
| 123 | resultHolder.invokeResult(msg); | 126 | resultHolder.invokeResult(msg); |
| 124 | }); | 127 | }); |
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/ptz/PtzController.java
| @@ -21,6 +21,8 @@ import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage; | @@ -21,6 +21,8 @@ import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage; | ||
| 21 | import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander; | 21 | import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander; |
| 22 | import com.genersoft.iot.vmp.storager.IVideoManagerStorager; | 22 | import com.genersoft.iot.vmp.storager.IVideoManagerStorager; |
| 23 | 23 | ||
| 24 | +import java.util.UUID; | ||
| 25 | + | ||
| 24 | @Api(tags = "云台控制") | 26 | @Api(tags = "云台控制") |
| 25 | @CrossOrigin | 27 | @CrossOrigin |
| 26 | @RestController | 28 | @RestController |
| @@ -101,23 +103,31 @@ public class PtzController { | @@ -101,23 +103,31 @@ public class PtzController { | ||
| 101 | logger.debug("设备预置位查询API调用"); | 103 | logger.debug("设备预置位查询API调用"); |
| 102 | } | 104 | } |
| 103 | Device device = storager.queryVideoDevice(deviceId); | 105 | Device device = storager.queryVideoDevice(deviceId); |
| 104 | - cmder.presetQuery(device, channelId, event -> { | ||
| 105 | - Response response = event.getResponse(); | ||
| 106 | - RequestMessage msg = new RequestMessage(); | ||
| 107 | - msg.setId(DeferredResultHolder.CALLBACK_CMD_PRESETQUERY + (StringUtils.isEmpty(channelId) ? deviceId : channelId)); | ||
| 108 | - msg.setData(String.format("获取设备预置位失败,错误码: %s, %s", response.getStatusCode(), response.getReasonPhrase())); | ||
| 109 | - resultHolder.invokeResult(msg); | ||
| 110 | - }); | ||
| 111 | - DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String >> (3 * 1000L); | 106 | + String uuid = UUID.randomUUID().toString(); |
| 107 | + String key = DeferredResultHolder.CALLBACK_CMD_PRESETQUERY + (StringUtils.isEmpty(channelId) ? deviceId : channelId); | ||
| 108 | + DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String >> (3 * 1000L); | ||
| 112 | result.onTimeout(()->{ | 109 | result.onTimeout(()->{ |
| 113 | logger.warn(String.format("获取设备预置位超时")); | 110 | logger.warn(String.format("获取设备预置位超时")); |
| 114 | // 释放rtpserver | 111 | // 释放rtpserver |
| 115 | RequestMessage msg = new RequestMessage(); | 112 | RequestMessage msg = new RequestMessage(); |
| 116 | - msg.setId(DeferredResultHolder.CALLBACK_CMD_PRESETQUERY + (StringUtils.isEmpty(channelId) ? deviceId : channelId)); | 113 | + msg.setId(uuid); |
| 114 | + msg.setKey(key); | ||
| 117 | msg.setData("获取设备预置位超时"); | 115 | msg.setData("获取设备预置位超时"); |
| 118 | resultHolder.invokeResult(msg); | 116 | resultHolder.invokeResult(msg); |
| 119 | }); | 117 | }); |
| 120 | - resultHolder.put(DeferredResultHolder.CALLBACK_CMD_PRESETQUERY + (StringUtils.isEmpty(channelId) ? deviceId : channelId), result); | 118 | + resultHolder.put(key, uuid, result); |
| 119 | + if (resultHolder.exist(key, null)) { | ||
| 120 | + return result; | ||
| 121 | + } | ||
| 122 | + cmder.presetQuery(device, channelId, event -> { | ||
| 123 | + Response response = event.getResponse(); | ||
| 124 | + RequestMessage msg = new RequestMessage(); | ||
| 125 | + msg.setId(uuid); | ||
| 126 | + msg.setKey(key); | ||
| 127 | + msg.setData(String.format("获取设备预置位失败,错误码: %s, %s", response.getStatusCode(), response.getReasonPhrase())); | ||
| 128 | + resultHolder.invokeResult(msg); | ||
| 129 | + }); | ||
| 130 | + | ||
| 121 | return result; | 131 | return result; |
| 122 | } | 132 | } |
| 123 | } | 133 | } |
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/record/GBRecordController.java
| @@ -22,6 +22,8 @@ import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder; | @@ -22,6 +22,8 @@ import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder; | ||
| 22 | import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander; | 22 | import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander; |
| 23 | import com.genersoft.iot.vmp.storager.IVideoManagerStorager; | 23 | import com.genersoft.iot.vmp.storager.IVideoManagerStorager; |
| 24 | 24 | ||
| 25 | +import java.util.UUID; | ||
| 26 | + | ||
| 25 | @Api(tags = "国标录像") | 27 | @Api(tags = "国标录像") |
| 26 | @CrossOrigin | 28 | @CrossOrigin |
| 27 | @RestController | 29 | @RestController |
| @@ -56,13 +58,15 @@ public class GBRecordController { | @@ -56,13 +58,15 @@ public class GBRecordController { | ||
| 56 | Device device = storager.queryVideoDevice(deviceId); | 58 | Device device = storager.queryVideoDevice(deviceId); |
| 57 | cmder.recordInfoQuery(device, channelId, startTime, endTime); | 59 | cmder.recordInfoQuery(device, channelId, startTime, endTime); |
| 58 | // 指定超时时间 1分钟30秒 | 60 | // 指定超时时间 1分钟30秒 |
| 59 | - DeferredResult<ResponseEntity<RecordInfo>> result = new DeferredResult<ResponseEntity<RecordInfo>>(90*1000L); | 61 | + DeferredResult<ResponseEntity<RecordInfo>> result = new DeferredResult<>(90*1000L); |
| 62 | + String uuid = UUID.randomUUID().toString(); | ||
| 63 | + String key = DeferredResultHolder.CALLBACK_CMD_RECORDINFO + deviceId + channelId; | ||
| 60 | // 录像查询以channelId作为deviceId查询 | 64 | // 录像查询以channelId作为deviceId查询 |
| 61 | - resultHolder.put(DeferredResultHolder.CALLBACK_CMD_RECORDINFO+channelId, result); | 65 | + resultHolder.put(key, uuid, result); |
| 62 | result.onTimeout(()->{ | 66 | result.onTimeout(()->{ |
| 63 | RequestMessage msg = new RequestMessage(); | 67 | RequestMessage msg = new RequestMessage(); |
| 64 | - msg.setDeviceId(deviceId); | ||
| 65 | - msg.setType(DeferredResultHolder.CALLBACK_CMD_RECORDINFO); | 68 | + msg.setId(uuid); |
| 69 | + msg.setKey(key); | ||
| 66 | msg.setData("timeout"); | 70 | msg.setData("timeout"); |
| 67 | resultHolder.invokeResult(msg); | 71 | resultHolder.invokeResult(msg); |
| 68 | }); | 72 | }); |
src/main/java/com/genersoft/iot/vmp/vmanager/onvif/ONVIFController.java
| @@ -40,17 +40,18 @@ public class ONVIFController { | @@ -40,17 +40,18 @@ public class ONVIFController { | ||
| 40 | @ResponseBody | 40 | @ResponseBody |
| 41 | public DeferredResult<ResponseEntity<WVPResult>> search(@RequestParam(required = false)Integer timeout){ | 41 | public DeferredResult<ResponseEntity<WVPResult>> search(@RequestParam(required = false)Integer timeout){ |
| 42 | DeferredResult<ResponseEntity<WVPResult>> result = new DeferredResult<>(timeout + 10L); | 42 | DeferredResult<ResponseEntity<WVPResult>> result = new DeferredResult<>(timeout + 10L); |
| 43 | - UUID uuid = UUID.randomUUID(); | 43 | + String uuid = UUID.randomUUID().toString(); |
| 44 | result.onTimeout(()->{ | 44 | result.onTimeout(()->{ |
| 45 | RequestMessage msg = new RequestMessage(); | 45 | RequestMessage msg = new RequestMessage(); |
| 46 | - msg.setId(DeferredResultHolder.CALLBACK_ONVIF + uuid); | 46 | + msg.setKey(DeferredResultHolder.CALLBACK_ONVIF ); |
| 47 | + msg.setId(uuid); | ||
| 47 | WVPResult<String> wvpResult = new WVPResult(); | 48 | WVPResult<String> wvpResult = new WVPResult(); |
| 48 | wvpResult.setCode(0); | 49 | wvpResult.setCode(0); |
| 49 | wvpResult.setMsg("搜索超时"); | 50 | wvpResult.setMsg("搜索超时"); |
| 50 | msg.setData(wvpResult); | 51 | msg.setData(wvpResult); |
| 51 | resultHolder.invokeResult(msg); | 52 | resultHolder.invokeResult(msg); |
| 52 | }); | 53 | }); |
| 53 | - resultHolder.put(DeferredResultHolder.CALLBACK_ONVIF + uuid, result); | 54 | + resultHolder.put(DeferredResultHolder.CALLBACK_ONVIF, uuid, result); |
| 54 | 55 | ||
| 55 | onvifServer.search(timeout, (errorCode, onvifDevices) ->{ | 56 | onvifServer.search(timeout, (errorCode, onvifDevices) ->{ |
| 56 | RequestMessage msg = new RequestMessage(); | 57 | RequestMessage msg = new RequestMessage(); |
| @@ -87,17 +88,18 @@ public class ONVIFController { | @@ -87,17 +88,18 @@ public class ONVIFController { | ||
| 87 | ){ | 88 | ){ |
| 88 | 89 | ||
| 89 | DeferredResult<ResponseEntity<WVPResult>> result = new DeferredResult<>(timeout + 10L); | 90 | DeferredResult<ResponseEntity<WVPResult>> result = new DeferredResult<>(timeout + 10L); |
| 90 | - UUID uuid = UUID.randomUUID(); | 91 | + String uuid = UUID.randomUUID().toString(); |
| 91 | result.onTimeout(()->{ | 92 | result.onTimeout(()->{ |
| 92 | RequestMessage msg = new RequestMessage(); | 93 | RequestMessage msg = new RequestMessage(); |
| 93 | - msg.setId(DeferredResultHolder.CALLBACK_ONVIF + uuid); | 94 | + msg.setId(uuid); |
| 95 | + msg.setKey(DeferredResultHolder.CALLBACK_ONVIF); | ||
| 94 | WVPResult<String> wvpResult = new WVPResult(); | 96 | WVPResult<String> wvpResult = new WVPResult(); |
| 95 | wvpResult.setCode(0); | 97 | wvpResult.setCode(0); |
| 96 | wvpResult.setMsg("获取onvif的rtsp地址超时"); | 98 | wvpResult.setMsg("获取onvif的rtsp地址超时"); |
| 97 | msg.setData(wvpResult); | 99 | msg.setData(wvpResult); |
| 98 | resultHolder.invokeResult(msg); | 100 | resultHolder.invokeResult(msg); |
| 99 | }); | 101 | }); |
| 100 | - resultHolder.put(DeferredResultHolder.CALLBACK_ONVIF + uuid, result); | 102 | + resultHolder.put(DeferredResultHolder.CALLBACK_ONVIF, uuid, result); |
| 101 | OnvifDevice onvifDevice = new OnvifDevice(hostname, username, password); | 103 | OnvifDevice onvifDevice = new OnvifDevice(hostname, username, password); |
| 102 | onvifServer.getRTSPUrl(timeout, onvifDevice, (errorCode, url) ->{ | 104 | onvifServer.getRTSPUrl(timeout, onvifDevice, (errorCode, url) ->{ |
| 103 | RequestMessage msg = new RequestMessage(); | 105 | RequestMessage msg = new RequestMessage(); |
web_src/src/components/MediaServerManger.vue