| | |
| | | |
| | | import com.ruoyi.alarm.globalAlarm.domain.GuidePriorityQueue; |
| | | import com.ruoyi.alarm.globalAlarm.domain.GuideTask; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.tomcat.util.threads.TaskThread; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; |
| | |
| | | import java.util.Map; |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | | import java.util.concurrent.PriorityBlockingQueue; |
| | | |
| | | import static jdk.nashorn.internal.runtime.regexp.joni.Config.log; |
| | | |
| | | /** |
| | | * @ClassName QueueManager |
| | |
| | | */ |
| | | |
| | | @Component |
| | | @Slf4j(topic = "guideQueue") |
| | | public class QueueManager { |
| | | |
| | | @Autowired |
| | |
| | | public void addTaskToQueue(String cameraId, GuideTask task) { |
| | | /*通过相机ID获取引导队列,并将引导任务加入队列*/ |
| | | PriorityBlockingQueue<GuideTask> guideTaskQueue = GuidePriorityQueue.cameraQueueMap.get(cameraId); |
| | | if(StringUtils.isNull(guideTaskQueue)) |
| | | { |
| | | log.info("相机未登录,没有队列,无法入队引导"); |
| | | return; |
| | | } |
| | | log.debug("新任务入队:"+task.getAlarmId()); |
| | | guideTaskQueue.add(task); |
| | | /*获取该相机的当前执行线程*/ |
| | | TaskThread currentTaskThread = threadMap.get(cameraId); |
| | |
| | | while (!Thread.currentThread().isInterrupted()) { |
| | | try { |
| | | GuideTask task = queue.take(); |
| | | log.debug("取出队列数据:"+task.getAlarmId()); |
| | | taskExecutor.processTask(task); |
| | | GuidePriorityQueue.printPriorityQueue(); |
| | | // 更新线程的当前任务 |
| | | TaskThread currentTaskThread = threadMap.get(queueName); |
| | | if (currentTaskThread != null) { |
| | | currentTaskThread.setCurrentTask(task); |
| | | } |
| | | } catch (InterruptedException e) { |
| | | log.info("中断当前线程"); |
| | | //线程中断,退出循环 |
| | | Thread.currentThread().interrupt(); |
| | | } |