yeg
2026-08-31 6c38637d89f346a660618558451f2dd7286dc7a5
ruoyi-device/src/main/java/com/ruoyi/device/simulator/InMemoryBtsSimulatorStateStore.java
@@ -11,6 +11,7 @@
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
@@ -19,6 +20,7 @@
    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() { }
@@ -107,6 +109,41 @@
    }
    @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;
@@ -125,5 +162,6 @@
        recentRequests = List.of();
        collectorHistory.clear();
        btsHistory.clear();
        btsPlayback.clear();
    }
}