录像增加延迟队列
parent
83bb760e98
commit
1b14f41e6f
@ -0,0 +1,9 @@
|
|||||||
|
package com.zhehekeji.web.lib;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class DownloadConsumer {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,33 @@
|
|||||||
|
package com.zhehekeji.web.lib;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.concurrent.Delayed;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class DownloadMp4Delayed implements Delayed {
|
||||||
|
|
||||||
|
private Integer cameraId;
|
||||||
|
|
||||||
|
private LocalDateTime startTime;
|
||||||
|
|
||||||
|
private LocalDateTime endTime;
|
||||||
|
|
||||||
|
private String path;
|
||||||
|
|
||||||
|
private long executeTime;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getDelay(TimeUnit unit) {
|
||||||
|
return unit.convert(this.executeTime - System.nanoTime(), TimeUnit.NANOSECONDS);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareTo(Delayed o) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,42 @@
|
|||||||
|
package com.zhehekeji.web.lib;
|
||||||
|
|
||||||
|
import com.zhehekeji.common.util.SpringContextUtil;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.concurrent.DelayQueue;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
|
public class DownloadMp4Executor {
|
||||||
|
|
||||||
|
private static ExecutorService exec = Executors.newFixedThreadPool(1);
|
||||||
|
|
||||||
|
private static DelayQueue<DownloadMp4Delayed> queue = new DelayQueue<>();
|
||||||
|
|
||||||
|
public static void addDelayTask(Integer cameraId, String path,LocalDateTime startTime, LocalDateTime endTime, Long delayTime) {
|
||||||
|
DownloadMp4Delayed downloadMp4Delayed = new DownloadMp4Delayed(cameraId, startTime, endTime,path, delayTime);
|
||||||
|
queue.add(downloadMp4Delayed);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void runMp4DownloadExecutor(){
|
||||||
|
exec.execute(new Consumer());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class Consumer implements Runnable {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
while (true) {
|
||||||
|
try {
|
||||||
|
DownloadMp4Delayed downloadMp4Delayed = queue.take();
|
||||||
|
CameraControlModule cameraControlModule = SpringContextUtil.getBean(CameraControlModule.class);
|
||||||
|
cameraControlModule.downloadMp4(downloadMp4Delayed.getCameraId(), downloadMp4Delayed.getPath(),downloadMp4Delayed.getStartTime(),downloadMp4Delayed.getEndTime());
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,32 @@
|
|||||||
|
package com.zhehekeji.web.pojo;
|
||||||
|
|
||||||
|
public enum Cmd {
|
||||||
|
|
||||||
|
A,
|
||||||
|
C,
|
||||||
|
|
||||||
|
//放货到位
|
||||||
|
C1,
|
||||||
|
//放货完成
|
||||||
|
C2,
|
||||||
|
//取货到位
|
||||||
|
C3,
|
||||||
|
//取货完成
|
||||||
|
C4,
|
||||||
|
//原点位
|
||||||
|
C5,
|
||||||
|
|
||||||
|
B,
|
||||||
|
B1,
|
||||||
|
B2,
|
||||||
|
D,
|
||||||
|
D1,
|
||||||
|
D2,
|
||||||
|
E,
|
||||||
|
E1,
|
||||||
|
|
||||||
|
;
|
||||||
|
public static Boolean isBaseAction(String code){
|
||||||
|
return code.equals(C1.name()) || code.equals(C2.name()) || code.equals(C3.name()) || code.equals(C4.name());
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue