| | |
| | | import com.ruoyi.device.simulator.BtsSimulatorStateStore.CollectorHistoryAppend; |
| | | import com.ruoyi.device.simulator.BtsSimulatorStateStore.CollectorHistoryBatch; |
| | | import com.ruoyi.device.simulator.BtsSimulatorStateStore.CollectorMeasurementRecord; |
| | | import com.ruoyi.device.simulator.BtsSimulatorStateStore.BtsHistoryRecord; |
| | | import com.ruoyi.device.simulator.BtsSimulatorStateStore.BtsHistoryBatch; |
| | | 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, ArrayList<CollectorMeasurementRecord>> collectorHistory = new LinkedHashMap<>(); |
| | | private final Map<String, ArrayList<BtsHistoryRecord>> btsHistory = new LinkedHashMap<>(); |
| | | |
| | | public InMemoryBtsSimulatorStateStore() { } |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | public synchronized BtsHistoryBatch loadBtsHistoryPage(String historyKey, long offset, int limit) |
| | | { |
| | | List<BtsHistoryRecord> history = btsHistory.getOrDefault(historyKey, new ArrayList<>()); |
| | | int from = (int) Math.min(offset, history.size()); |
| | | int count = Math.min(limit, history.size() - from); |
| | | List<BtsHistoryRecord> records = new ArrayList<>(history.subList(from, from + count)); |
| | | long next = from + records.size(); |
| | | return new BtsHistoryBatch(offset, next, next < history.size(), history.size(), records); |
| | | } |
| | | |
| | | @Override |
| | | public synchronized void appendBtsHistory(String historyKey, BtsHistoryRecord record) |
| | | { |
| | | ArrayList<BtsHistoryRecord> history = btsHistory.computeIfAbsent(historyKey, key -> new ArrayList<>()); |
| | | history.add(record); |
| | | if (history.size() > MAX_HISTORY_RECORDS) history.remove(0); |
| | | } |
| | | |
| | | @Override |
| | | public synchronized List<RecentRequest> loadRecentRequests() |
| | | { |
| | | return recentRequests; |
| | |
| | | state = defaultState; |
| | | recentRequests = List.of(); |
| | | collectorHistory.clear(); |
| | | btsHistory.clear(); |
| | | } |
| | | } |