| | |
| | | package com.ruoyi.device.simulator; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.LinkedHashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import com.ruoyi.device.simulator.BtsSimulatorStateStore.CollectorHistoryAppend; |
| | | import com.ruoyi.device.simulator.BtsSimulatorStateStore.CollectorMeasurementRecord; |
| | | import com.ruoyi.device.simulator.BtsSimulatorStateStore.RecentRequest; |
| | | import com.ruoyi.device.simulator.BtsSimulatorStateStore.SimulatorState; |
| | | |
| | |
| | | { |
| | | private SimulatorState state; |
| | | private List<RecentRequest> recentRequests = List.of(); |
| | | private final Map<String, List<CollectorMeasurementRecord>> collectorHistory = new LinkedHashMap<>(); |
| | | |
| | | public InMemoryBtsSimulatorStateStore() { } |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | public synchronized void save(SimulatorState state, List<CollectorHistoryAppend> historyAppends) |
| | | { |
| | | for (CollectorHistoryAppend append : historyAppends) |
| | | { |
| | | List<CollectorMeasurementRecord> records = new ArrayList<>( |
| | | collectorHistory.getOrDefault(append.collectorCode(), List.of())); |
| | | records.addAll(append.records()); |
| | | collectorHistory.put(append.collectorCode(), List.copyOf(records)); |
| | | } |
| | | this.state = state; |
| | | } |
| | | |
| | | @Override |
| | | public synchronized List<CollectorMeasurementRecord> loadCollectorHistory(String collectorCode) |
| | | { |
| | | return collectorHistory.getOrDefault(collectorCode, List.of()); |
| | | } |
| | | |
| | | @Override |
| | | public synchronized void saveAndDeleteCollectorHistory(SimulatorState state, String collectorCode) |
| | | { |
| | | collectorHistory.remove(collectorCode); |
| | | this.state = state; |
| | | } |
| | | |
| | | @Override |
| | | public synchronized List<RecentRequest> loadRecentRequests() |
| | | { |
| | | return recentRequests; |
| | |
| | | { |
| | | state = defaultState; |
| | | recentRequests = List.of(); |
| | | collectorHistory.clear(); |
| | | } |
| | | } |