Class TableStateProvider
java.lang.Object
com.kingsrook.qqq.backend.core.state.TableStateProvider
- All Implemented Interfaces:
StateProviderInterface
Process and async job state shared through a QQQ table, so any node of a
multi-node application can serve any process step, status poll or cancel
(spec 2026-10-15-cluster-ha-design, section B). Works on any backend; the
table is defined by defineTable and created by the application's migrations.
Every operation runs as the system user with no transaction of its own, so
state is visible to other nodes immediately, whatever the caller's
transaction does. Values are serialized by StateSerialization (gzip, and
AES-GCM with a key). Entries expire after ttlHours; every node sweeps
expired rows every cleanIntervalMinutes.
A value that cannot be serialized is kept in this node's memory instead (and
logged once per class), so a process keeps working on a single node.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionTableStateProvider(QInstance instance, StateProviderMetaData metaData) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidDelete entries that expired before now (the argument is ignored: expiry is per entry).static QTableMetaDatadefineTable(String tableName, String backendName) The state table: stateKey (primary key), stateType, payload (text), nodeId, createDate, modifyDate, expiresAt; columns are snake_case.<T extends Serializable>
Optional<T> get(Class<? extends T> type, AbstractStateKey key) Read a value.The meta data.booleanWhether stored values are encrypted (a state encryption key is configured).<T extends Serializable>
voidput(AbstractStateKey key, T data) Store a value.voidremove(AbstractStateKey key) Remove a value.voidStart the expired-entry sweeper (idempotent).status()Status text.voidStop the sweeper.static StringThe stored key for a state key.
-
Field Details
-
FIELD_STATE_KEY
- See Also:
-
FIELD_STATE_TYPE
- See Also:
-
FIELD_PAYLOAD
- See Also:
-
FIELD_NODE_ID
- See Also:
-
FIELD_CREATE_DATE
- See Also:
-
FIELD_MODIFY_DATE
- See Also:
-
FIELD_EXPIRES_AT
- See Also:
-
-
Constructor Details
-
TableStateProvider
Constructor.- Throws:
QException
-
-
Method Details
-
defineTable
The state table: stateKey (primary key), stateType, payload (text), nodeId, createDate, modifyDate, expiresAt; columns are snake_case. Only holders of the table's permissions see it (the payload is opaque - and encrypted with a key); the provider reads and writes it as the system user. -
storedKey
The stored key for a state key. -
startSweeper
public void startSweeper()Start the expired-entry sweeper (idempotent). -
stopSweeper
public void stopSweeper()Stop the sweeper. -
put
Store a value.- Specified by:
putin interfaceStateProviderInterface
-
get
Read a value.- Specified by:
getin interfaceStateProviderInterface
-
remove
Remove a value.- Specified by:
removein interfaceStateProviderInterface
-
status
-
clean
Delete entries that expired before now (the argument is ignored: expiry is per entry).- Specified by:
cleanin interfaceStateProviderInterface
-
isEncrypted
public boolean isEncrypted()Whether stored values are encrypted (a state encryption key is configured). -
getMetaData
The meta data.
-