| | |
| | | import com.ruoyi.device.simulator.BtsSimulatorStateStore.BtsHistoryBatch; |
| | | import com.ruoyi.device.simulator.BtsSimulatorStateStore.RecentRequest; |
| | | import com.ruoyi.device.simulator.BtsSimulatorStateStore.SimulatorState; |
| | | import com.ruoyi.device.simulator.BtsSimulatorStateStore.BtsPlaybackState; |
| | | |
| | | /** 测试和独立协议合同使用的内存状态存储。 */ |
| | | public final class InMemoryBtsSimulatorStateStore implements BtsSimulatorStateStore |
| | |
| | | private List<RecentRequest> recentRequests = List.of(); |
| | | private final Map<String, ArrayList<CollectorMeasurementRecord>> collectorHistory = new LinkedHashMap<>(); |
| | | private final Map<String, ArrayList<BtsHistoryRecord>> btsHistory = new LinkedHashMap<>(); |
| | | private final Map<String, BtsPlaybackState> btsPlayback = new LinkedHashMap<>(); |
| | | |
| | | public InMemoryBtsSimulatorStateStore() { } |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | public synchronized BtsPlaybackState loadBtsPlaybackState(String historyKey) |
| | | { |
| | | return btsPlayback.get(historyKey); |
| | | } |
| | | |
| | | @Override |
| | | public synchronized void saveBtsPlaybackState(String historyKey, BtsPlaybackState playback) |
| | | { |
| | | btsPlayback.put(historyKey, playback); |
| | | } |
| | | |
| | | @Override |
| | | public synchronized void deleteBtsPlaybackState(String historyKey) |
| | | { |
| | | btsPlayback.remove(historyKey); |
| | | } |
| | | |
| | | @Override |
| | | public synchronized void deleteBtsHistory(String historyKey) |
| | | { |
| | | btsHistory.remove(historyKey); |
| | | } |
| | | |
| | | @Override |
| | | public synchronized void saveBtsPlaybackAndAppendHistory(String historyKey, BtsPlaybackState playback, |
| | | List<BtsHistoryRecord> records) |
| | | { |
| | | ArrayList<BtsHistoryRecord> history = btsHistory.computeIfAbsent(historyKey, key -> new ArrayList<>()); |
| | | history.addAll(records); |
| | | int overflow = history.size() - (int) MAX_HISTORY_RECORDS; |
| | | if (overflow > 0) history.subList(0, overflow).clear(); |
| | | btsPlayback.put(historyKey, playback); |
| | | } |
| | | |
| | | @Override |
| | | public synchronized List<RecentRequest> loadRecentRequests() |
| | | { |
| | | return recentRequests; |
| | |
| | | recentRequests = List.of(); |
| | | collectorHistory.clear(); |
| | | btsHistory.clear(); |
| | | btsPlayback.clear(); |
| | | } |
| | | } |