Commit 9a80e10f6ead2382503a4059f4472471bfd45b8b
1 parent
95642d0b
使用 java.time.Instant代替 java.util.Date
Showing
11 changed files
with
78 additions
and
109 deletions
src/main/java/com/genersoft/iot/vmp/conf/DynamicTask.java
| 1 | package com.genersoft.iot.vmp.conf; | 1 | package com.genersoft.iot.vmp.conf; |
| 2 | 2 | ||
| 3 | import com.genersoft.iot.vmp.gb28181.task.ISubscribeTask; | 3 | import com.genersoft.iot.vmp.gb28181.task.ISubscribeTask; |
| 4 | -import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.cmd.CatalogResponseMessageHandler; | ||
| 5 | import org.slf4j.Logger; | 4 | import org.slf4j.Logger; |
| 6 | import org.slf4j.LoggerFactory; | 5 | import org.slf4j.LoggerFactory; |
| 7 | import org.springframework.beans.factory.annotation.Autowired; | 6 | import org.springframework.beans.factory.annotation.Autowired; |
| @@ -9,25 +8,27 @@ import org.springframework.context.annotation.Bean; | @@ -9,25 +8,27 @@ import org.springframework.context.annotation.Bean; | ||
| 9 | import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; | 8 | import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; |
| 10 | import org.springframework.stereotype.Component; | 9 | import org.springframework.stereotype.Component; |
| 11 | 10 | ||
| 12 | -import java.util.Date; | 11 | +import java.time.Instant; |
| 13 | import java.util.Map; | 12 | import java.util.Map; |
| 14 | import java.util.Set; | 13 | import java.util.Set; |
| 15 | import java.util.concurrent.ConcurrentHashMap; | 14 | import java.util.concurrent.ConcurrentHashMap; |
| 16 | import java.util.concurrent.ScheduledFuture; | 15 | import java.util.concurrent.ScheduledFuture; |
| 16 | +import java.util.concurrent.TimeUnit; | ||
| 17 | 17 | ||
| 18 | /** | 18 | /** |
| 19 | * 动态定时任务 | 19 | * 动态定时任务 |
| 20 | + * @author lin | ||
| 20 | */ | 21 | */ |
| 21 | @Component | 22 | @Component |
| 22 | public class DynamicTask { | 23 | public class DynamicTask { |
| 23 | 24 | ||
| 24 | - private Logger logger = LoggerFactory.getLogger(DynamicTask.class); | 25 | + private final Logger logger = LoggerFactory.getLogger(DynamicTask.class); |
| 25 | 26 | ||
| 26 | @Autowired | 27 | @Autowired |
| 27 | private ThreadPoolTaskScheduler threadPoolTaskScheduler; | 28 | private ThreadPoolTaskScheduler threadPoolTaskScheduler; |
| 28 | 29 | ||
| 29 | - private Map<String, ScheduledFuture<?>> futureMap = new ConcurrentHashMap<>(); | ||
| 30 | - private Map<String, Runnable> runnableMap = new ConcurrentHashMap<>(); | 30 | + private final Map<String, ScheduledFuture<?>> futureMap = new ConcurrentHashMap<>(); |
| 31 | + private final Map<String, Runnable> runnableMap = new ConcurrentHashMap<>(); | ||
| 31 | 32 | ||
| 32 | @Bean | 33 | @Bean |
| 33 | public ThreadPoolTaskScheduler threadPoolTaskScheduler() { | 34 | public ThreadPoolTaskScheduler threadPoolTaskScheduler() { |
| @@ -47,7 +48,7 @@ public class DynamicTask { | @@ -47,7 +48,7 @@ public class DynamicTask { | ||
| 47 | * @return | 48 | * @return |
| 48 | */ | 49 | */ |
| 49 | public void startCron(String key, Runnable task, int cycleForCatalog) { | 50 | public void startCron(String key, Runnable task, int cycleForCatalog) { |
| 50 | - ScheduledFuture future = futureMap.get(key); | 51 | + ScheduledFuture<?> future = futureMap.get(key); |
| 51 | if (future != null) { | 52 | if (future != null) { |
| 52 | if (future.isCancelled()) { | 53 | if (future.isCancelled()) { |
| 53 | logger.debug("任务【{}】已存在但是关闭状态!!!", key); | 54 | logger.debug("任务【{}】已存在但是关闭状态!!!", key); |
| @@ -76,7 +77,9 @@ public class DynamicTask { | @@ -76,7 +77,9 @@ public class DynamicTask { | ||
| 76 | */ | 77 | */ |
| 77 | public void startDelay(String key, Runnable task, int delay) { | 78 | public void startDelay(String key, Runnable task, int delay) { |
| 78 | stop(key); | 79 | stop(key); |
| 79 | - Date starTime = new Date(System.currentTimeMillis() + delay); | 80 | + |
| 81 | + // 获取执行的时刻 | ||
| 82 | + Instant startInstant = Instant.now().plusMillis(TimeUnit.MILLISECONDS.toMillis(delay)); | ||
| 80 | 83 | ||
| 81 | ScheduledFuture future = futureMap.get(key); | 84 | ScheduledFuture future = futureMap.get(key); |
| 82 | if (future != null) { | 85 | if (future != null) { |
| @@ -88,7 +91,7 @@ public class DynamicTask { | @@ -88,7 +91,7 @@ public class DynamicTask { | ||
| 88 | } | 91 | } |
| 89 | } | 92 | } |
| 90 | // scheduleWithFixedDelay 必须等待上一个任务结束才开始计时period, cycleForCatalog表示执行的间隔 | 93 | // scheduleWithFixedDelay 必须等待上一个任务结束才开始计时period, cycleForCatalog表示执行的间隔 |
| 91 | - future = threadPoolTaskScheduler.schedule(task, starTime); | 94 | + future = threadPoolTaskScheduler.schedule(task, startInstant); |
| 92 | if (future != null){ | 95 | if (future != null){ |
| 93 | futureMap.put(key, future); | 96 | futureMap.put(key, future); |
| 94 | runnableMap.put(key, task); | 97 | runnableMap.put(key, task); |
src/main/java/com/genersoft/iot/vmp/gb28181/auth/DigestServerAuthenticationHelper.java
| @@ -27,8 +27,7 @@ package com.genersoft.iot.vmp.gb28181.auth; | @@ -27,8 +27,7 @@ package com.genersoft.iot.vmp.gb28181.auth; | ||
| 27 | 27 | ||
| 28 | import java.security.MessageDigest; | 28 | import java.security.MessageDigest; |
| 29 | import java.security.NoSuchAlgorithmException; | 29 | import java.security.NoSuchAlgorithmException; |
| 30 | -import java.text.DecimalFormat; | ||
| 31 | -import java.util.Date; | 30 | +import java.time.Instant; |
| 32 | import java.util.Random; | 31 | import java.util.Random; |
| 33 | 32 | ||
| 34 | import javax.sip.address.URI; | 33 | import javax.sip.address.URI; |
| @@ -90,17 +89,12 @@ public class DigestServerAuthenticationHelper { | @@ -90,17 +89,12 @@ public class DigestServerAuthenticationHelper { | ||
| 90 | * @return a generated nonce. | 89 | * @return a generated nonce. |
| 91 | */ | 90 | */ |
| 92 | private String generateNonce() { | 91 | private String generateNonce() { |
| 93 | - // Get the time of day and run MD5 over it. | ||
| 94 | - Date date = new Date(); | ||
| 95 | - long time = date.getTime(); | 92 | + long time = Instant.now().toEpochMilli(); |
| 96 | Random rand = new Random(); | 93 | Random rand = new Random(); |
| 97 | long pad = rand.nextLong(); | 94 | long pad = rand.nextLong(); |
| 98 | - // String nonceString = (new Long(time)).toString() | ||
| 99 | - // + (new Long(pad)).toString(); | ||
| 100 | String nonceString = Long.valueOf(time).toString() | 95 | String nonceString = Long.valueOf(time).toString() |
| 101 | + Long.valueOf(pad).toString(); | 96 | + Long.valueOf(pad).toString(); |
| 102 | byte mdbytes[] = messageDigest.digest(nonceString.getBytes()); | 97 | byte mdbytes[] = messageDigest.digest(nonceString.getBytes()); |
| 103 | - // Convert the mdbytes array into a hex string. | ||
| 104 | return toHexString(mdbytes); | 98 | return toHexString(mdbytes); |
| 105 | } | 99 | } |
| 106 | 100 |
src/main/java/com/genersoft/iot/vmp/gb28181/bean/CatalogData.java
| 1 | package com.genersoft.iot.vmp.gb28181.bean; | 1 | package com.genersoft.iot.vmp.gb28181.bean; |
| 2 | 2 | ||
| 3 | -import java.util.Date; | 3 | +import java.time.Instant; |
| 4 | import java.util.List; | 4 | import java.util.List; |
| 5 | 5 | ||
| 6 | public class CatalogData { | 6 | public class CatalogData { |
| 7 | private int sn; // 命令序列号 | 7 | private int sn; // 命令序列号 |
| 8 | private int total; | 8 | private int total; |
| 9 | private List<DeviceChannel> channelList; | 9 | private List<DeviceChannel> channelList; |
| 10 | - private Date lastTime; | 10 | + private Instant lastTime; |
| 11 | private Device device; | 11 | private Device device; |
| 12 | private String errorMsg; | 12 | private String errorMsg; |
| 13 | 13 | ||
| @@ -41,11 +41,11 @@ public class CatalogData { | @@ -41,11 +41,11 @@ public class CatalogData { | ||
| 41 | this.channelList = channelList; | 41 | this.channelList = channelList; |
| 42 | } | 42 | } |
| 43 | 43 | ||
| 44 | - public Date getLastTime() { | 44 | + public Instant getLastTime() { |
| 45 | return lastTime; | 45 | return lastTime; |
| 46 | } | 46 | } |
| 47 | 47 | ||
| 48 | - public void setLastTime(Date lastTime) { | 48 | + public void setLastTime(Instant lastTime) { |
| 49 | this.lastTime = lastTime; | 49 | this.lastTime = lastTime; |
| 50 | } | 50 | } |
| 51 | 51 |
src/main/java/com/genersoft/iot/vmp/gb28181/bean/RecordInfo.java
| 1 | package com.genersoft.iot.vmp.gb28181.bean; | 1 | package com.genersoft.iot.vmp.gb28181.bean; |
| 2 | 2 | ||
| 3 | -import java.util.Date; | 3 | +import java.time.Instant; |
| 4 | import java.util.List; | 4 | import java.util.List; |
| 5 | 5 | ||
| 6 | /** | 6 | /** |
| @@ -20,7 +20,7 @@ public class RecordInfo { | @@ -20,7 +20,7 @@ public class RecordInfo { | ||
| 20 | 20 | ||
| 21 | private int sumNum; | 21 | private int sumNum; |
| 22 | 22 | ||
| 23 | - private Date lastTime; | 23 | + private Instant lastTime; |
| 24 | 24 | ||
| 25 | private List<RecordItem> recordList; | 25 | private List<RecordItem> recordList; |
| 26 | 26 | ||
| @@ -72,11 +72,11 @@ public class RecordInfo { | @@ -72,11 +72,11 @@ public class RecordInfo { | ||
| 72 | this.sn = sn; | 72 | this.sn = sn; |
| 73 | } | 73 | } |
| 74 | 74 | ||
| 75 | - public Date getLastTime() { | 75 | + public Instant getLastTime() { |
| 76 | return lastTime; | 76 | return lastTime; |
| 77 | } | 77 | } |
| 78 | 78 | ||
| 79 | - public void setLastTime(Date lastTime) { | 79 | + public void setLastTime(Instant lastTime) { |
| 80 | this.lastTime = lastTime; | 80 | this.lastTime = lastTime; |
| 81 | } | 81 | } |
| 82 | } | 82 | } |
src/main/java/com/genersoft/iot/vmp/gb28181/bean/RecordItem.java
| @@ -5,7 +5,8 @@ import com.genersoft.iot.vmp.utils.DateUtil; | @@ -5,7 +5,8 @@ import com.genersoft.iot.vmp.utils.DateUtil; | ||
| 5 | import org.jetbrains.annotations.NotNull; | 5 | import org.jetbrains.annotations.NotNull; |
| 6 | 6 | ||
| 7 | import java.text.ParseException; | 7 | import java.text.ParseException; |
| 8 | -import java.util.Date; | 8 | +import java.time.Instant; |
| 9 | +import java.time.temporal.TemporalAccessor; | ||
| 9 | 10 | ||
| 10 | /** | 11 | /** |
| 11 | * @description:设备录像bean | 12 | * @description:设备录像bean |
| @@ -116,17 +117,17 @@ public class RecordItem implements Comparable<RecordItem>{ | @@ -116,17 +117,17 @@ public class RecordItem implements Comparable<RecordItem>{ | ||
| 116 | 117 | ||
| 117 | @Override | 118 | @Override |
| 118 | public int compareTo(@NotNull RecordItem recordItem) { | 119 | public int compareTo(@NotNull RecordItem recordItem) { |
| 119 | - try { | ||
| 120 | - Date startTime_now = DateUtil.format.parse(startTime); | ||
| 121 | - Date startTime_param = DateUtil.format.parse(recordItem.getStartTime()); | ||
| 122 | - if (startTime_param.compareTo(startTime_now) > 0) { | ||
| 123 | - return -1; | ||
| 124 | - }else { | ||
| 125 | - return 1; | ||
| 126 | - } | ||
| 127 | - } catch (ParseException e) { | ||
| 128 | - e.printStackTrace(); | 120 | + TemporalAccessor startTimeNow = DateUtil.formatter.parse(startTime); |
| 121 | + TemporalAccessor startTimeParam = DateUtil.formatter.parse(recordItem.getStartTime()); | ||
| 122 | + Instant startTimeParamInstant = Instant.from(startTimeParam); | ||
| 123 | + Instant startTimeNowInstant = Instant.from(startTimeNow); | ||
| 124 | + if (startTimeNowInstant.equals(startTimeParamInstant)) { | ||
| 125 | + return 0; | ||
| 126 | + }else if (Instant.from(startTimeParam).isAfter(Instant.from(startTimeNow)) ) { | ||
| 127 | + return -1; | ||
| 128 | + }else { | ||
| 129 | + return 1; | ||
| 129 | } | 130 | } |
| 130 | - return 0; | 131 | + |
| 131 | } | 132 | } |
| 132 | } | 133 | } |
src/main/java/com/genersoft/iot/vmp/gb28181/event/SipSubscribe.java
| @@ -9,11 +9,14 @@ import org.springframework.stereotype.Component; | @@ -9,11 +9,14 @@ import org.springframework.stereotype.Component; | ||
| 9 | import javax.sip.*; | 9 | import javax.sip.*; |
| 10 | import javax.sip.header.CallIdHeader; | 10 | import javax.sip.header.CallIdHeader; |
| 11 | import javax.sip.message.Response; | 11 | import javax.sip.message.Response; |
| 12 | -import java.util.Calendar; | ||
| 13 | -import java.util.Date; | 12 | +import java.time.Instant; |
| 14 | import java.util.Map; | 13 | import java.util.Map; |
| 15 | import java.util.concurrent.ConcurrentHashMap; | 14 | import java.util.concurrent.ConcurrentHashMap; |
| 15 | +import java.util.concurrent.TimeUnit; | ||
| 16 | 16 | ||
| 17 | +/** | ||
| 18 | + * @author lin | ||
| 19 | + */ | ||
| 17 | @Component | 20 | @Component |
| 18 | public class SipSubscribe { | 21 | public class SipSubscribe { |
| 19 | 22 | ||
| @@ -23,28 +26,25 @@ public class SipSubscribe { | @@ -23,28 +26,25 @@ public class SipSubscribe { | ||
| 23 | 26 | ||
| 24 | private Map<String, SipSubscribe.Event> okSubscribes = new ConcurrentHashMap<>(); | 27 | private Map<String, SipSubscribe.Event> okSubscribes = new ConcurrentHashMap<>(); |
| 25 | 28 | ||
| 26 | - private Map<String, Date> okTimeSubscribes = new ConcurrentHashMap<>(); | ||
| 27 | - private Map<String, Date> errorTimeSubscribes = new ConcurrentHashMap<>(); | 29 | + private Map<String, Instant> okTimeSubscribes = new ConcurrentHashMap<>(); |
| 30 | + private Map<String, Instant> errorTimeSubscribes = new ConcurrentHashMap<>(); | ||
| 28 | 31 | ||
| 29 | // @Scheduled(cron="*/5 * * * * ?") //每五秒执行一次 | 32 | // @Scheduled(cron="*/5 * * * * ?") //每五秒执行一次 |
| 30 | -// @Scheduled(fixedRate= 100 * 60 * 60 ) | 33 | + // @Scheduled(fixedRate= 100 * 60 * 60 ) |
| 31 | @Scheduled(cron="0 0/5 * * * ?") //每5分钟执行一次 | 34 | @Scheduled(cron="0 0/5 * * * ?") //每5分钟执行一次 |
| 32 | public void execute(){ | 35 | public void execute(){ |
| 33 | logger.info("[定时任务] 清理过期的SIP订阅信息"); | 36 | logger.info("[定时任务] 清理过期的SIP订阅信息"); |
| 34 | - Calendar calendar = Calendar.getInstance(); | ||
| 35 | - calendar.setTime(new Date()); | ||
| 36 | - calendar.set(Calendar.MINUTE, calendar.get(Calendar.MINUTE) - 5); | 37 | + |
| 38 | + Instant instant = Instant.now().minusMillis(TimeUnit.MINUTES.toMillis(5)); | ||
| 37 | 39 | ||
| 38 | for (String key : okTimeSubscribes.keySet()) { | 40 | for (String key : okTimeSubscribes.keySet()) { |
| 39 | - if (okTimeSubscribes.get(key).before(calendar.getTime())){ | ||
| 40 | -// logger.info("[定时任务] 清理过期的订阅信息: {}", key); | 41 | + if (okTimeSubscribes.get(key).isBefore(instant)){ |
| 41 | okSubscribes.remove(key); | 42 | okSubscribes.remove(key); |
| 42 | okTimeSubscribes.remove(key); | 43 | okTimeSubscribes.remove(key); |
| 43 | } | 44 | } |
| 44 | } | 45 | } |
| 45 | for (String key : errorTimeSubscribes.keySet()) { | 46 | for (String key : errorTimeSubscribes.keySet()) { |
| 46 | - if (errorTimeSubscribes.get(key).before(calendar.getTime())){ | ||
| 47 | -// logger.info("[定时任务] 清理过期的订阅信息: {}", key); | 47 | + if (errorTimeSubscribes.get(key).isBefore(instant)){ |
| 48 | errorSubscribes.remove(key); | 48 | errorSubscribes.remove(key); |
| 49 | errorTimeSubscribes.remove(key); | 49 | errorTimeSubscribes.remove(key); |
| 50 | } | 50 | } |
| @@ -117,12 +117,12 @@ public class SipSubscribe { | @@ -117,12 +117,12 @@ public class SipSubscribe { | ||
| 117 | 117 | ||
| 118 | public void addErrorSubscribe(String key, SipSubscribe.Event event) { | 118 | public void addErrorSubscribe(String key, SipSubscribe.Event event) { |
| 119 | errorSubscribes.put(key, event); | 119 | errorSubscribes.put(key, event); |
| 120 | - errorTimeSubscribes.put(key, new Date()); | 120 | + errorTimeSubscribes.put(key, Instant.now()); |
| 121 | } | 121 | } |
| 122 | 122 | ||
| 123 | public void addOkSubscribe(String key, SipSubscribe.Event event) { | 123 | public void addOkSubscribe(String key, SipSubscribe.Event event) { |
| 124 | okSubscribes.put(key, event); | 124 | okSubscribes.put(key, event); |
| 125 | - okTimeSubscribes.put(key, new Date()); | 125 | + okTimeSubscribes.put(key, Instant.now()); |
| 126 | } | 126 | } |
| 127 | 127 | ||
| 128 | public SipSubscribe.Event getErrorSubscribe(String key) { | 128 | public SipSubscribe.Event getErrorSubscribe(String key) { |
src/main/java/com/genersoft/iot/vmp/gb28181/session/CatalogDataCatch.java
| @@ -4,16 +4,15 @@ import com.genersoft.iot.vmp.gb28181.bean.CatalogData; | @@ -4,16 +4,15 @@ import com.genersoft.iot.vmp.gb28181.bean.CatalogData; | ||
| 4 | import com.genersoft.iot.vmp.gb28181.bean.Device; | 4 | import com.genersoft.iot.vmp.gb28181.bean.Device; |
| 5 | import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; | 5 | import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; |
| 6 | import com.genersoft.iot.vmp.gb28181.bean.SyncStatus; | 6 | import com.genersoft.iot.vmp.gb28181.bean.SyncStatus; |
| 7 | -import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder; | ||
| 8 | -import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage; | ||
| 9 | import com.genersoft.iot.vmp.storager.IVideoManagerStorage; | 7 | import com.genersoft.iot.vmp.storager.IVideoManagerStorage; |
| 10 | -import com.genersoft.iot.vmp.vmanager.bean.WVPResult; | ||
| 11 | import org.springframework.beans.factory.annotation.Autowired; | 8 | import org.springframework.beans.factory.annotation.Autowired; |
| 12 | import org.springframework.scheduling.annotation.Scheduled; | 9 | import org.springframework.scheduling.annotation.Scheduled; |
| 13 | import org.springframework.stereotype.Component; | 10 | import org.springframework.stereotype.Component; |
| 14 | 11 | ||
| 12 | +import java.time.Instant; | ||
| 15 | import java.util.*; | 13 | import java.util.*; |
| 16 | import java.util.concurrent.ConcurrentHashMap; | 14 | import java.util.concurrent.ConcurrentHashMap; |
| 15 | +import java.util.concurrent.TimeUnit; | ||
| 17 | 16 | ||
| 18 | @Component | 17 | @Component |
| 19 | public class CatalogDataCatch { | 18 | public class CatalogDataCatch { |
| @@ -21,9 +20,6 @@ public class CatalogDataCatch { | @@ -21,9 +20,6 @@ public class CatalogDataCatch { | ||
| 21 | public static Map<String, CatalogData> data = new ConcurrentHashMap<>(); | 20 | public static Map<String, CatalogData> data = new ConcurrentHashMap<>(); |
| 22 | 21 | ||
| 23 | @Autowired | 22 | @Autowired |
| 24 | - private DeferredResultHolder deferredResultHolder; | ||
| 25 | - | ||
| 26 | - @Autowired | ||
| 27 | private IVideoManagerStorage storager; | 23 | private IVideoManagerStorage storager; |
| 28 | 24 | ||
| 29 | public void addReady(Device device, int sn ) { | 25 | public void addReady(Device device, int sn ) { |
| @@ -34,7 +30,7 @@ public class CatalogDataCatch { | @@ -34,7 +30,7 @@ public class CatalogDataCatch { | ||
| 34 | catalogData.setDevice(device); | 30 | catalogData.setDevice(device); |
| 35 | catalogData.setSn(sn); | 31 | catalogData.setSn(sn); |
| 36 | catalogData.setStatus(CatalogData.CatalogDataStatus.ready); | 32 | catalogData.setStatus(CatalogData.CatalogDataStatus.ready); |
| 37 | - catalogData.setLastTime(new Date(System.currentTimeMillis())); | 33 | + catalogData.setLastTime(Instant.now()); |
| 38 | data.put(device.getDeviceId(), catalogData); | 34 | data.put(device.getDeviceId(), catalogData); |
| 39 | } | 35 | } |
| 40 | } | 36 | } |
| @@ -48,7 +44,7 @@ public class CatalogDataCatch { | @@ -48,7 +44,7 @@ public class CatalogDataCatch { | ||
| 48 | catalogData.setDevice(device); | 44 | catalogData.setDevice(device); |
| 49 | catalogData.setChannelList(Collections.synchronizedList(new ArrayList<>())); | 45 | catalogData.setChannelList(Collections.synchronizedList(new ArrayList<>())); |
| 50 | catalogData.setStatus(CatalogData.CatalogDataStatus.runIng); | 46 | catalogData.setStatus(CatalogData.CatalogDataStatus.runIng); |
| 51 | - catalogData.setLastTime(new Date(System.currentTimeMillis())); | 47 | + catalogData.setLastTime(Instant.now()); |
| 52 | data.put(deviceId, catalogData); | 48 | data.put(deviceId, catalogData); |
| 53 | }else { | 49 | }else { |
| 54 | // 同一个设备的通道同步请求只考虑一个,其他的直接忽略 | 50 | // 同一个设备的通道同步请求只考虑一个,其他的直接忽略 |
| @@ -59,7 +55,7 @@ public class CatalogDataCatch { | @@ -59,7 +55,7 @@ public class CatalogDataCatch { | ||
| 59 | catalogData.setDevice(device); | 55 | catalogData.setDevice(device); |
| 60 | catalogData.setStatus(CatalogData.CatalogDataStatus.runIng); | 56 | catalogData.setStatus(CatalogData.CatalogDataStatus.runIng); |
| 61 | catalogData.getChannelList().addAll(deviceChannelList); | 57 | catalogData.getChannelList().addAll(deviceChannelList); |
| 62 | - catalogData.setLastTime(new Date(System.currentTimeMillis())); | 58 | + catalogData.setLastTime(Instant.now()); |
| 63 | } | 59 | } |
| 64 | } | 60 | } |
| 65 | 61 | ||
| @@ -102,16 +98,13 @@ public class CatalogDataCatch { | @@ -102,16 +98,13 @@ public class CatalogDataCatch { | ||
| 102 | @Scheduled(fixedRate = 5 * 1000) //每5秒执行一次, 发现数据5秒未更新则移除数据并认为数据接收超时 | 98 | @Scheduled(fixedRate = 5 * 1000) //每5秒执行一次, 发现数据5秒未更新则移除数据并认为数据接收超时 |
| 103 | private void timerTask(){ | 99 | private void timerTask(){ |
| 104 | Set<String> keys = data.keySet(); | 100 | Set<String> keys = data.keySet(); |
| 105 | - Calendar calendarBefore5S = Calendar.getInstance(); | ||
| 106 | - calendarBefore5S.setTime(new Date()); | ||
| 107 | - calendarBefore5S.set(Calendar.SECOND, calendarBefore5S.get(Calendar.SECOND) - 5); | ||
| 108 | 101 | ||
| 109 | - Calendar calendarBefore30S = Calendar.getInstance(); | ||
| 110 | - calendarBefore30S.setTime(new Date()); | ||
| 111 | - calendarBefore30S.set(Calendar.SECOND, calendarBefore30S.get(Calendar.SECOND) - 30); | 102 | + Instant instantBefore5S = Instant.now().minusMillis(TimeUnit.SECONDS.toMillis(5)); |
| 103 | + Instant instantBefore30S = Instant.now().minusMillis(TimeUnit.SECONDS.toMillis(30)); | ||
| 104 | + | ||
| 112 | for (String deviceId : keys) { | 105 | for (String deviceId : keys) { |
| 113 | CatalogData catalogData = data.get(deviceId); | 106 | CatalogData catalogData = data.get(deviceId); |
| 114 | - if ( catalogData.getLastTime().before(calendarBefore5S.getTime())) { // 超过五秒收不到消息任务超时, 只更新这一部分数据 | 107 | + if ( catalogData.getLastTime().isBefore(instantBefore5S)) { // 超过五秒收不到消息任务超时, 只更新这一部分数据 |
| 115 | if (catalogData.getStatus().equals(CatalogData.CatalogDataStatus.runIng)) { | 108 | if (catalogData.getStatus().equals(CatalogData.CatalogDataStatus.runIng)) { |
| 116 | storager.resetChannels(catalogData.getDevice().getDeviceId(), catalogData.getChannelList()); | 109 | storager.resetChannels(catalogData.getDevice().getDeviceId(), catalogData.getChannelList()); |
| 117 | if (catalogData.getTotal() != catalogData.getChannelList().size()) { | 110 | if (catalogData.getTotal() != catalogData.getChannelList().size()) { |
| @@ -124,7 +117,7 @@ public class CatalogDataCatch { | @@ -124,7 +117,7 @@ public class CatalogDataCatch { | ||
| 124 | } | 117 | } |
| 125 | catalogData.setStatus(CatalogData.CatalogDataStatus.end); | 118 | catalogData.setStatus(CatalogData.CatalogDataStatus.end); |
| 126 | } | 119 | } |
| 127 | - if (catalogData.getStatus().equals(CatalogData.CatalogDataStatus.end) && catalogData.getLastTime().before(calendarBefore30S.getTime())) { // 超过三十秒,如果标记为end则删除 | 120 | + if (catalogData.getStatus().equals(CatalogData.CatalogDataStatus.end) && catalogData.getLastTime().isBefore(instantBefore30S)) { // 超过三十秒,如果标记为end则删除 |
| 128 | data.remove(deviceId); | 121 | data.remove(deviceId); |
| 129 | } | 122 | } |
| 130 | } | 123 | } |
src/main/java/com/genersoft/iot/vmp/gb28181/session/RecordDataCatch.java
| @@ -3,16 +3,15 @@ package com.genersoft.iot.vmp.gb28181.session; | @@ -3,16 +3,15 @@ package com.genersoft.iot.vmp.gb28181.session; | ||
| 3 | import com.genersoft.iot.vmp.gb28181.bean.*; | 3 | import com.genersoft.iot.vmp.gb28181.bean.*; |
| 4 | import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder; | 4 | import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder; |
| 5 | import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage; | 5 | import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage; |
| 6 | -import com.genersoft.iot.vmp.storager.IVideoManagerStorage; | ||
| 7 | -import com.genersoft.iot.vmp.utils.DateUtil; | ||
| 8 | import com.genersoft.iot.vmp.vmanager.bean.WVPResult; | 6 | import com.genersoft.iot.vmp.vmanager.bean.WVPResult; |
| 9 | import org.springframework.beans.factory.annotation.Autowired; | 7 | import org.springframework.beans.factory.annotation.Autowired; |
| 10 | import org.springframework.scheduling.annotation.Scheduled; | 8 | import org.springframework.scheduling.annotation.Scheduled; |
| 11 | import org.springframework.stereotype.Component; | 9 | import org.springframework.stereotype.Component; |
| 12 | 10 | ||
| 13 | -import java.text.SimpleDateFormat; | 11 | +import java.time.Instant; |
| 14 | import java.util.*; | 12 | import java.util.*; |
| 15 | import java.util.concurrent.ConcurrentHashMap; | 13 | import java.util.concurrent.ConcurrentHashMap; |
| 14 | +import java.util.concurrent.TimeUnit; | ||
| 16 | 15 | ||
| 17 | /** | 16 | /** |
| 18 | * @author lin | 17 | * @author lin |
| @@ -35,7 +34,7 @@ public class RecordDataCatch { | @@ -35,7 +34,7 @@ public class RecordDataCatch { | ||
| 35 | recordInfo.setSn(sn.trim()); | 34 | recordInfo.setSn(sn.trim()); |
| 36 | recordInfo.setSumNum(sumNum); | 35 | recordInfo.setSumNum(sumNum); |
| 37 | recordInfo.setRecordList(Collections.synchronizedList(new ArrayList<>())); | 36 | recordInfo.setRecordList(Collections.synchronizedList(new ArrayList<>())); |
| 38 | - recordInfo.setLastTime(new Date(System.currentTimeMillis())); | 37 | + recordInfo.setLastTime(Instant.now()); |
| 39 | recordInfo.getRecordList().addAll(recordItems); | 38 | recordInfo.getRecordList().addAll(recordItems); |
| 40 | data.put(key, recordInfo); | 39 | data.put(key, recordInfo); |
| 41 | }else { | 40 | }else { |
| @@ -44,7 +43,7 @@ public class RecordDataCatch { | @@ -44,7 +43,7 @@ public class RecordDataCatch { | ||
| 44 | return 0; | 43 | return 0; |
| 45 | } | 44 | } |
| 46 | recordInfo.getRecordList().addAll(recordItems); | 45 | recordInfo.getRecordList().addAll(recordItems); |
| 47 | - recordInfo.setLastTime(new Date(System.currentTimeMillis())); | 46 | + recordInfo.setLastTime(Instant.now()); |
| 48 | } | 47 | } |
| 49 | return recordInfo.getRecordList().size(); | 48 | return recordInfo.getRecordList().size(); |
| 50 | } | 49 | } |
| @@ -52,14 +51,12 @@ public class RecordDataCatch { | @@ -52,14 +51,12 @@ public class RecordDataCatch { | ||
| 52 | @Scheduled(fixedRate = 5 * 1000) //每5秒执行一次, 发现数据5秒未更新则移除数据并认为数据接收超时 | 51 | @Scheduled(fixedRate = 5 * 1000) //每5秒执行一次, 发现数据5秒未更新则移除数据并认为数据接收超时 |
| 53 | private void timerTask(){ | 52 | private void timerTask(){ |
| 54 | Set<String> keys = data.keySet(); | 53 | Set<String> keys = data.keySet(); |
| 55 | - Calendar calendarBefore5S = Calendar.getInstance(); | ||
| 56 | - calendarBefore5S.setTime(new Date()); | ||
| 57 | - calendarBefore5S.set(Calendar.SECOND, calendarBefore5S.get(Calendar.SECOND) - 5); | ||
| 58 | - | 54 | + // 获取五秒前的时刻 |
| 55 | + Instant instantBefore5S = Instant.now().minusMillis(TimeUnit.SECONDS.toMillis(5)); | ||
| 59 | for (String key : keys) { | 56 | for (String key : keys) { |
| 60 | RecordInfo recordInfo = data.get(key); | 57 | RecordInfo recordInfo = data.get(key); |
| 61 | // 超过五秒收不到消息任务超时, 只更新这一部分数据 | 58 | // 超过五秒收不到消息任务超时, 只更新这一部分数据 |
| 62 | - if ( recordInfo.getLastTime().before(calendarBefore5S.getTime())) { | 59 | + if ( recordInfo.getLastTime().isBefore(instantBefore5S)) { |
| 63 | // 处理录像数据, 返回给前端 | 60 | // 处理录像数据, 返回给前端 |
| 64 | String msgKey = DeferredResultHolder.CALLBACK_CMD_RECORDINFO + recordInfo.getDeviceId() + recordInfo.getSn(); | 61 | String msgKey = DeferredResultHolder.CALLBACK_CMD_RECORDINFO + recordInfo.getDeviceId() + recordInfo.getSn(); |
| 65 | 62 |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/InviteRequestProcessor.java
| @@ -40,7 +40,7 @@ import javax.sip.header.CallIdHeader; | @@ -40,7 +40,7 @@ import javax.sip.header.CallIdHeader; | ||
| 40 | import javax.sip.message.Request; | 40 | import javax.sip.message.Request; |
| 41 | import javax.sip.message.Response; | 41 | import javax.sip.message.Response; |
| 42 | import java.text.ParseException; | 42 | import java.text.ParseException; |
| 43 | -import java.util.Date; | 43 | +import java.time.Instant; |
| 44 | import java.util.Vector; | 44 | import java.util.Vector; |
| 45 | 45 | ||
| 46 | /** | 46 | /** |
| @@ -180,16 +180,16 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements | @@ -180,16 +180,16 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements | ||
| 180 | 180 | ||
| 181 | Long startTime = null; | 181 | Long startTime = null; |
| 182 | Long stopTime = null; | 182 | Long stopTime = null; |
| 183 | - Date start = null; | ||
| 184 | - Date end = null; | 183 | + Instant start = null; |
| 184 | + Instant end = null; | ||
| 185 | if (sdp.getTimeDescriptions(false) != null && sdp.getTimeDescriptions(false).size() > 0) { | 185 | if (sdp.getTimeDescriptions(false) != null && sdp.getTimeDescriptions(false).size() > 0) { |
| 186 | TimeDescriptionImpl timeDescription = (TimeDescriptionImpl)(sdp.getTimeDescriptions(false).get(0)); | 186 | TimeDescriptionImpl timeDescription = (TimeDescriptionImpl)(sdp.getTimeDescriptions(false).get(0)); |
| 187 | TimeField startTimeFiled = (TimeField)timeDescription.getTime(); | 187 | TimeField startTimeFiled = (TimeField)timeDescription.getTime(); |
| 188 | startTime = startTimeFiled.getStartTime(); | 188 | startTime = startTimeFiled.getStartTime(); |
| 189 | stopTime = startTimeFiled.getStopTime(); | 189 | stopTime = startTimeFiled.getStopTime(); |
| 190 | 190 | ||
| 191 | - start = new Date(startTime*1000); | ||
| 192 | - end = new Date(stopTime*1000); | 191 | + start = Instant.ofEpochMilli(startTime*1000); |
| 192 | + end = Instant.ofEpochMilli(stopTime*1000); | ||
| 193 | } | 193 | } |
| 194 | // 获取支持的格式 | 194 | // 获取支持的格式 |
| 195 | Vector mediaDescriptions = sdp.getMediaDescriptions(true); | 195 | Vector mediaDescriptions = sdp.getMediaDescriptions(true); |
| @@ -335,8 +335,8 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements | @@ -335,8 +335,8 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements | ||
| 335 | sendRtpItem.setStreamId(ssrcInfo.getStream()); | 335 | sendRtpItem.setStreamId(ssrcInfo.getStream()); |
| 336 | // 写入redis, 超时时回复 | 336 | // 写入redis, 超时时回复 |
| 337 | redisCatchStorage.updateSendRTPSever(sendRtpItem); | 337 | redisCatchStorage.updateSendRTPSever(sendRtpItem); |
| 338 | - playService.playBack(mediaServerItem, ssrcInfo, device.getDeviceId(), channelId, DateUtil.format.format(start), | ||
| 339 | - DateUtil.format.format(end), null, result -> { | 338 | + playService.playBack(mediaServerItem, ssrcInfo, device.getDeviceId(), channelId, DateUtil.formatter.format(start), |
| 339 | + DateUtil.formatter.format(end), null, result -> { | ||
| 340 | if (result.getCode() != 0){ | 340 | if (result.getCode() != 0){ |
| 341 | logger.warn("录像回放失败"); | 341 | logger.warn("录像回放失败"); |
| 342 | if (result.getEvent() != null) { | 342 | if (result.getEvent() != null) { |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/KeepaliveNotifyMessageHandler.java
| @@ -24,8 +24,6 @@ import javax.sip.SipException; | @@ -24,8 +24,6 @@ import javax.sip.SipException; | ||
| 24 | import javax.sip.header.ViaHeader; | 24 | import javax.sip.header.ViaHeader; |
| 25 | import javax.sip.message.Response; | 25 | import javax.sip.message.Response; |
| 26 | import java.text.ParseException; | 26 | import java.text.ParseException; |
| 27 | -import java.util.Calendar; | ||
| 28 | -import java.util.Date; | ||
| 29 | 27 | ||
| 30 | @Component | 28 | @Component |
| 31 | public class KeepaliveNotifyMessageHandler extends SIPRequestProcessorParent implements InitializingBean, IMessageHandler { | 29 | public class KeepaliveNotifyMessageHandler extends SIPRequestProcessorParent implements InitializingBean, IMessageHandler { |
src/main/java/com/genersoft/iot/vmp/service/impl/DeviceServiceImpl.java
| @@ -11,24 +11,18 @@ import com.genersoft.iot.vmp.gb28181.task.impl.CatalogSubscribeTask; | @@ -11,24 +11,18 @@ import com.genersoft.iot.vmp.gb28181.task.impl.CatalogSubscribeTask; | ||
| 11 | import com.genersoft.iot.vmp.gb28181.task.impl.MobilePositionSubscribeTask; | 11 | import com.genersoft.iot.vmp.gb28181.task.impl.MobilePositionSubscribeTask; |
| 12 | import com.genersoft.iot.vmp.gb28181.bean.SyncStatus; | 12 | import com.genersoft.iot.vmp.gb28181.bean.SyncStatus; |
| 13 | import com.genersoft.iot.vmp.service.IMediaServerService; | 13 | import com.genersoft.iot.vmp.service.IMediaServerService; |
| 14 | -import com.genersoft.iot.vmp.service.IMediaService; | ||
| 15 | import com.genersoft.iot.vmp.storager.IRedisCatchStorage; | 14 | import com.genersoft.iot.vmp.storager.IRedisCatchStorage; |
| 16 | import com.genersoft.iot.vmp.storager.dao.DeviceMapper; | 15 | import com.genersoft.iot.vmp.storager.dao.DeviceMapper; |
| 17 | import com.genersoft.iot.vmp.utils.DateUtil; | 16 | import com.genersoft.iot.vmp.utils.DateUtil; |
| 18 | import org.slf4j.Logger; | 17 | import org.slf4j.Logger; |
| 19 | import org.slf4j.LoggerFactory; | 18 | import org.slf4j.LoggerFactory; |
| 20 | import org.springframework.beans.factory.annotation.Autowired; | 19 | import org.springframework.beans.factory.annotation.Autowired; |
| 21 | -import org.springframework.beans.factory.annotation.Qualifier; | ||
| 22 | -import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; | ||
| 23 | import org.springframework.stereotype.Service; | 20 | import org.springframework.stereotype.Service; |
| 24 | import org.springframework.util.StringUtils; | 21 | import org.springframework.util.StringUtils; |
| 25 | 22 | ||
| 26 | -import javax.sip.DialogState; | ||
| 27 | -import javax.sip.TimeoutEvent; | ||
| 28 | -import java.text.ParseException; | ||
| 29 | -import java.util.Calendar; | ||
| 30 | -import java.util.Date; | 23 | +import java.time.Instant; |
| 31 | import java.util.List; | 24 | import java.util.List; |
| 25 | +import java.util.concurrent.TimeUnit; | ||
| 32 | 26 | ||
| 33 | /** | 27 | /** |
| 34 | * 设备业务(目录订阅) | 28 | * 设备业务(目录订阅) |
| @@ -101,9 +95,7 @@ public class DeviceServiceImpl implements IDeviceService { | @@ -101,9 +95,7 @@ public class DeviceServiceImpl implements IDeviceService { | ||
| 101 | // 刷新过期任务 | 95 | // 刷新过期任务 |
| 102 | String registerExpireTaskKey = registerExpireTaskKeyPrefix + device.getDeviceId(); | 96 | String registerExpireTaskKey = registerExpireTaskKeyPrefix + device.getDeviceId(); |
| 103 | dynamicTask.stop(registerExpireTaskKey); | 97 | dynamicTask.stop(registerExpireTaskKey); |
| 104 | - dynamicTask.startDelay(registerExpireTaskKey, ()->{ | ||
| 105 | - offline(device.getDeviceId()); | ||
| 106 | - }, device.getExpires() * 1000); | 98 | + dynamicTask.startDelay(registerExpireTaskKey, ()-> offline(device.getDeviceId()), device.getExpires() * 1000); |
| 107 | } | 99 | } |
| 108 | 100 | ||
| 109 | @Override | 101 | @Override |
| @@ -217,18 +209,9 @@ public class DeviceServiceImpl implements IDeviceService { | @@ -217,18 +209,9 @@ public class DeviceServiceImpl implements IDeviceService { | ||
| 217 | 209 | ||
| 218 | @Override | 210 | @Override |
| 219 | public boolean expire(Device device) { | 211 | public boolean expire(Device device) { |
| 220 | - Date registerTimeDate; | ||
| 221 | - try { | ||
| 222 | - registerTimeDate = DateUtil.format.parse(device.getRegisterTime()); | ||
| 223 | - } catch (ParseException e) { | ||
| 224 | - logger.error("设备时间格式化失败:{}->{} ", device.getDeviceId(), device.getRegisterTime() ); | ||
| 225 | - return false; | ||
| 226 | - } | ||
| 227 | - int expires = device.getExpires(); | ||
| 228 | - Calendar calendarForExpire = Calendar.getInstance(); | ||
| 229 | - calendarForExpire.setTime(registerTimeDate); | ||
| 230 | - calendarForExpire.set(Calendar.SECOND, calendarForExpire.get(Calendar.SECOND) + expires); | ||
| 231 | - return calendarForExpire.before(DateUtil.getNow()); | 212 | + Instant registerTimeDate = Instant.from(DateUtil.formatter.parse(device.getRegisterTime())); |
| 213 | + Instant expireInstant = registerTimeDate.plusMillis(TimeUnit.SECONDS.toMillis(device.getExpires())); | ||
| 214 | + return expireInstant.isBefore(Instant.now()); | ||
| 232 | } | 215 | } |
| 233 | 216 | ||
| 234 | @Override | 217 | @Override |