Package io.cloudstub.core.internal.store
Class JsonFileStateStore
java.lang.Object
io.cloudstub.core.internal.store.JsonFileStateStore
- All Implemented Interfaces:
StateStore
Persistent
StateStore that serialises state to a JSON file on every mutation.
Reads the existing file on construction (if present) so state survives a CloudStub restart.
Writes are flushed synchronously — put returns only once the value has been written via
an atomic temp-file rename to {storeDir}/cloudstub-state.json, which prevents partial
writes.
Type fidelity: the mapper records each value's concrete type, so a value
stored as a Foo is read back as a Foo after a restart — not as a generic map.
This matches the in-memory store's behaviour. Stored value types must be on the classpath when
the store is reloaded. Default typing is safe here because the store only ever reads back its own
locally-written file, never untrusted input.
Thread-safe: mutations are serialised through writeLock.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidDelete all entries whose key begins withprefix.voidclearAll()Delete all entries in the store across all services.voidDelete a single entry.Retrieve the value stored underkey, ornullif the key does not exist.List all keys whose path begins withprefix.voidStore a value underkey.
-
Constructor Details
-
JsonFileStateStore
-
-
Method Details
-
put
Description copied from interface:StateStoreStore a value underkey. Overwrites any existing entry at the same key.- Specified by:
putin interfaceStateStore- Parameters:
key- path-style key, e.g."sqs/queues/my-queue/messages/abc-123"value- the value to store; must be JSON-serialisable
-
get
Description copied from interface:StateStoreRetrieve the value stored underkey, ornullif the key does not exist.- Specified by:
getin interfaceStateStore- Parameters:
key- path-style key- Returns:
- the stored value, or
null
-
list
Description copied from interface:StateStoreList all keys whose path begins withprefix. Passing"sqs/"lists every key the SQS module has written.- Specified by:
listin interfaceStateStore- Parameters:
prefix- key prefix to match- Returns:
- sorted list of matching keys; empty if none match
-
delete
Description copied from interface:StateStoreDelete a single entry. No-op if the key does not exist.- Specified by:
deletein interfaceStateStore- Parameters:
key- the key to delete
-
clear
Description copied from interface:StateStoreDelete all entries whose key begins withprefix. Passing"sqs/"clears all SQS state.- Specified by:
clearin interfaceStateStore- Parameters:
prefix- the key prefix to clear
-
clearAll
public void clearAll()Description copied from interface:StateStoreDelete all entries in the store across all services. Called by the global reset endpoint.- Specified by:
clearAllin interfaceStateStore
-