Package com.cognite.client.statestore
Class MemoryStateStore
java.lang.Object
com.cognite.client.statestore.AbstractStateStore
com.cognite.client.statestore.MemoryStateStore
- All Implemented Interfaces:
StateStore,Closeable,AutoCloseable
A state store in-memory only. Not backed by any persisted storage.
Abstract parent class for all state store implementations.
-
Field Summary
Fields inherited from class com.cognite.client.statestore.AbstractStateStore
COLUMN_KEY_HIGH, COLUMN_KEY_LOW, DEFAULT_MAX_COMMIT_INTERVAL, deletedEntries, executor, LOG, MAX_MAX_COMMIT_INTERVAL, MIN_MAX_COMMIT_INTERVAL, modifiedEntries, recurringTask, stateMap -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcommit()Commit the current states to the persistent store.static MemoryStateStorecreate()Initialize an in-memory state store.voidload()Load the states from the persistent store.booleanstart()Start a background thread to perform a commit everymaxUploadInterval.booleanstop()Stops the background thread if it is running and ensures the upload queue is empty by callingupload()one last time after shutting down the thread.Methods inherited from class com.cognite.client.statestore.AbstractStateStore
close, deleteState, expandHigh, expandLow, getHigh, getLow, getState, isOutsideState, keySet, setHigh, setLow, verifyStateMap
-
Constructor Details
-
MemoryStateStore
public MemoryStateStore()
-
-
Method Details
-
create
Initialize an in-memory state store.- Returns:
- the state store.
-
load
Load the states from the persistent store.- Specified by:
loadin interfaceStateStore- Specified by:
loadin classAbstractStateStore- Throws:
Exception
-
commit
Commit the current states to the persistent store. Will overwrite/replace previously persisted states.- Specified by:
commitin interfaceStateStore- Specified by:
commitin classAbstractStateStore- Throws:
Exception
-
start
public boolean start()Start a background thread to perform a commit everymaxUploadInterval. The default upload interval is every 20 seconds. If the background thread has already been started (for example by an earlier call tostart()then this method does nothing and returnsfalse.- Specified by:
startin interfaceStateStore- Overrides:
startin classAbstractStateStore- Returns:
trueif the upload thread started successfully,falseif the background thread has already been started.
-
stop
public boolean stop()Stops the background thread if it is running and ensures the upload queue is empty by callingupload()one last time after shutting down the thread.- Specified by:
stopin interfaceStateStore- Overrides:
stopin classAbstractStateStore- Returns:
trueif the upload thread stopped successfully,falseif the upload thread was not started in the first place.
-