Package com.cognite.client.statestore
Class AbstractStateStore
java.lang.Object
com.cognite.client.statestore.AbstractStateStore
- All Implemented Interfaces:
StateStore,Closeable,AutoCloseable
- Direct Known Subclasses:
LocalStateStore,MemoryStateStore,RawStateStore
Abstract parent class for all state store implementations.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final Stringprotected static final Stringprotected static final Durationprotected final ScheduledThreadPoolExecutorprotected final org.slf4j.Loggerprotected static final Durationprotected static final Durationprotected ScheduledFuture<?>protected ConcurrentMap<String,com.google.protobuf.Struct> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()A mirror of thestop()method to support auto close in atry-with-resourcesstatement.abstract voidcommit()Commit the current states to the persistent store.voiddeleteState(String key) Delete the state(s) for a given id.voidexpandHigh(String key, long value) LikeStateStore.setHigh(String, long), but only sets the state if the proposed state is higher than the current state.voidLikeStateStore.setLow(String, long), but only sets the state if the proposed state is lower than the current state.Get the high watermark state for a single id.Get the low watermark state for a single id.Optional<com.google.protobuf.Struct>Get the set of states for a single id.booleanisOutsideState(String key, long value) Check if a state is outside the stored state interval.keySet()Returns a read-only set of all state keys.abstract voidload()Load the states from the persistent store.voidSet/update the high watermark for a single id.voidSet/update the low watermark for a single id.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.protected boolean
-
Field Details
-
COLUMN_KEY_LOW
- See Also:
-
COLUMN_KEY_HIGH
- See Also:
-
MIN_MAX_COMMIT_INTERVAL
-
DEFAULT_MAX_COMMIT_INTERVAL
-
MAX_MAX_COMMIT_INTERVAL
-
LOG
protected final org.slf4j.Logger LOG -
stateMap
-
modifiedEntries
-
deletedEntries
-
executor
-
recurringTask
-
-
Constructor Details
-
AbstractStateStore
public AbstractStateStore()
-
-
Method Details
-
setHigh
Set/update the high watermark for a single id.- Specified by:
setHighin interfaceStateStore- Parameters:
key- The id to store the state of.value- The value of the high watermark.
-
expandHigh
LikeStateStore.setHigh(String, long), but only sets the state if the proposed state is higher than the current state.- Specified by:
expandHighin interfaceStateStore- Parameters:
key- key The id to store the state of.value- The value of the high watermark.
-
getHigh
Get the high watermark state for a single id.- Specified by:
getHighin interfaceStateStore- Parameters:
key- The id to get the state of.- Returns:
- The value of the high watermark. An empty optional in case the state does not exist.
-
setLow
Set/update the low watermark for a single id.- Specified by:
setLowin interfaceStateStore- Parameters:
key- The id to store the state of.value- The value of the low watermark.
-
expandLow
LikeStateStore.setLow(String, long), but only sets the state if the proposed state is lower than the current state.- Specified by:
expandLowin interfaceStateStore- Parameters:
key- key The id to store the state of.value- The value of the low watermark.
-
getLow
Get the low watermark state for a single id.- Specified by:
getLowin interfaceStateStore- Parameters:
key- The id to get the state of.- Returns:
- The value of the low watermark. An empty optional in case the state does not exist.
-
isOutsideState
Check if a state is outside the stored state interval. I.e. if a state is higher than the current high watermark or lower than the current low watermark. The method can be used for determining if a data object should be processed or not.- Specified by:
isOutsideStatein interfaceStateStore- Parameters:
key- the id to test.value- the state to test.- Returns:
Trueif the state is outside of stored state or if the key is previously unseen.
-
getState
Get the set of states for a single id. This will give you both the low and high watermark (if set) as aStruct. The returnedStructis a read-only view of the state values.- Specified by:
getStatein interfaceStateStore- Parameters:
key- The id to get the state of.- Returns:
- All the states in a Struct.
-
deleteState
Delete the state(s) for a given id.- Specified by:
deleteStatein interfaceStateStore- Parameters:
key- The id to delete the state(s) of.
-
keySet
Returns a read-only set of all state keys.- Specified by:
keySetin interfaceStateStore- Returns:
- An immutable Set of all state keys.
-
load
Load the states from the persistent store.- Specified by:
loadin interfaceStateStore- Throws:
Exception
-
commit
Commit the current states to the persistent store. Will overwrite/replace previously persisted states.- Specified by:
commitin interfaceStateStore- Throws:
Exception
-
verifyStateMap
protected boolean verifyStateMap() -
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- Returns:
trueif the upload thread started successfully,falseif the background thread has already been started.
-
close
public void close()A mirror of thestop()method to support auto close in atry-with-resourcesstatement.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- See Also:
-
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- Returns:
trueif the upload thread stopped successfully,falseif the upload thread was not started in the first place.
-