package com.ruoyi.device.simulator;
|
|
import java.util.List;
|
import com.ruoyi.device.simulator.BtsSimulatorStateStore.RecentRequest;
|
import com.ruoyi.device.simulator.BtsSimulatorStateStore.SimulatorState;
|
|
/** 测试和独立协议合同使用的内存状态存储。 */
|
public final class InMemoryBtsSimulatorStateStore implements BtsSimulatorStateStore
|
{
|
private SimulatorState state;
|
private List<RecentRequest> recentRequests = List.of();
|
|
public InMemoryBtsSimulatorStateStore() { }
|
|
public InMemoryBtsSimulatorStateStore(SimulatorState state)
|
{
|
this.state = state;
|
}
|
|
@Override
|
public synchronized SimulatorState loadOrInitialize(SimulatorState defaultState)
|
{
|
if (state == null) state = defaultState;
|
return state;
|
}
|
|
@Override
|
public synchronized void save(SimulatorState state)
|
{
|
this.state = state;
|
}
|
|
@Override
|
public synchronized List<RecentRequest> loadRecentRequests()
|
{
|
return recentRequests;
|
}
|
|
@Override
|
public synchronized void saveRecentRequests(List<RecentRequest> requests)
|
{
|
recentRequests = List.copyOf(requests);
|
}
|
|
@Override
|
public synchronized void reset(SimulatorState defaultState)
|
{
|
state = defaultState;
|
recentRequests = List.of();
|
}
|
}
|