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
public abstract class MemoryStateStore extends AbstractStateStore
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 Constructor Description MemoryStateStore()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcommit()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
-
-
-
-
Method Detail
-
create
public static MemoryStateStore create()
Initialize an in-memory state store.- Returns:
- the state store.
-
load
public void load() throws ExceptionLoad the states from the persistent store.- Specified by:
loadin interfaceStateStore- Specified by:
loadin classAbstractStateStore- Throws:
Exception
-
commit
public void commit() throws ExceptionCommit 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.
-
-