| | |
| | | package com.ard.work.domain.cache; |
| | | |
| | | import com.ard.work.domain.dto.state.UavState; |
| | | import com.ard.work.domain.dto.telemetry.TelemetryData; |
| | | |
| | | import java.util.Collection; |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | | import java.util.function.BiConsumer; |
| | | |
| | | /** |
| | | * 无人机遥测数据缓存 |
| | |
| | | public class UavTelemetryDataCache { |
| | | |
| | | // 使用 ConcurrentHashMap 来缓存无人机遥测数据,key 是 boxSn(无人机序列号) |
| | | private static final ConcurrentHashMap<String, TelemetryData> uavTelemetryDataCache = new ConcurrentHashMap<>(); |
| | | private static final ConcurrentHashMap<String, TelemetryData> cache = new ConcurrentHashMap<>(); |
| | | |
| | | // 存储无人机遥测数据到缓存 |
| | | public static void putUavTelemetryData(TelemetryData telemetryData) { |
| | | uavTelemetryDataCache.put(telemetryData.getBoxSn(), telemetryData); |
| | | public static void put(TelemetryData telemetryData) { |
| | | cache.put(telemetryData.getBoxSn(), telemetryData); |
| | | } |
| | | |
| | | // 从缓存中获取无人机遥测数据 |
| | | public static TelemetryData getUavTelemetryData(String boxSn) { |
| | | return uavTelemetryDataCache.get(boxSn); |
| | | public static TelemetryData get(String boxSn) { |
| | | return cache.get(boxSn); |
| | | } |
| | | |
| | | // 删除缓存中的无人机遥测数据 |
| | | public static void removeUavTelemetryData(String boxSn) { |
| | | uavTelemetryDataCache.remove(boxSn); |
| | | public static void remove(String boxSn) { |
| | | cache.remove(boxSn); |
| | | } |
| | | |
| | | |
| | | // 遍历并处理每条 TelemetryData |
| | | public static void forEach(BiConsumer<String, TelemetryData> consumer) { |
| | | cache.forEach(consumer); |
| | | } |
| | | } |