Class InMemorySessionStore
- java.lang.Object
-
- org.apache.kafka.streams.state.internals.InMemorySessionStore
-
- All Implemented Interfaces:
StateStore,ReadOnlySessionStore<org.apache.kafka.common.utils.Bytes,byte[]>,SessionStore<org.apache.kafka.common.utils.Bytes,byte[]>
public class InMemorySessionStore extends java.lang.Object implements SessionStore<org.apache.kafka.common.utils.Bytes,byte[]>
-
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidclose()Close the storage engine.KeyValueIterator<Windowed<org.apache.kafka.common.utils.Bytes>,byte[]>fetch(org.apache.kafka.common.utils.Bytes key)Retrieve all aggregated sessions for the provided key.KeyValueIterator<Windowed<org.apache.kafka.common.utils.Bytes>,byte[]>fetch(org.apache.kafka.common.utils.Bytes from, org.apache.kafka.common.utils.Bytes to)Retrieve all aggregated sessions for the given range of keys.byte[]fetchSession(org.apache.kafka.common.utils.Bytes key, long startTime, long endTime)Get the value of key from a single session.KeyValueIterator<Windowed<org.apache.kafka.common.utils.Bytes>,byte[]>findSessions(org.apache.kafka.common.utils.Bytes key, long earliestSessionEndTime, long latestSessionStartTime)Deprecated.KeyValueIterator<Windowed<org.apache.kafka.common.utils.Bytes>,byte[]>findSessions(org.apache.kafka.common.utils.Bytes keyFrom, org.apache.kafka.common.utils.Bytes keyTo, long earliestSessionEndTime, long latestSessionStartTime)Deprecated.voidflush()Flush any cached datavoidinit(ProcessorContext context, StateStore root)Initializes this state store.booleanisOpen()Is this store open for reading and writingjava.lang.Stringname()The name of this store.booleanpersistent()Return if the storage is persistent or not.voidput(Windowed<org.apache.kafka.common.utils.Bytes> sessionKey, byte[] aggregate)Write the aggregated value for the provided key to the storevoidremove(Windowed<org.apache.kafka.common.utils.Bytes> sessionKey)Remove the session aggregated with providedWindowedkey from the store
-
-
-
Method Detail
-
name
public java.lang.String name()
Description copied from interface:StateStoreThe name of this store.- Specified by:
namein interfaceStateStore- Returns:
- the storage name
-
init
public void init(ProcessorContext context, StateStore root)
Description copied from interface:StateStoreInitializes this state store.The implementation of this function must register the root store in the context via the
ProcessorContext.register(StateStore, StateRestoreCallback)function, where the firstStateStoreparameter should always be the passed-inrootobject, and the second parameter should be an object of user's implementation of theStateRestoreCallbackinterface used for restoring the state store from the changelog.Note that if the state store engine itself supports bulk writes, users can implement another interface
BatchingStateRestoreCallbackwhich extendsStateRestoreCallbackto let users implement bulk-load restoration logic instead of restoring one record at a time.- Specified by:
initin interfaceStateStore
-
put
public void put(Windowed<org.apache.kafka.common.utils.Bytes> sessionKey, byte[] aggregate)
Description copied from interface:SessionStoreWrite the aggregated value for the provided key to the store- Specified by:
putin interfaceSessionStore<org.apache.kafka.common.utils.Bytes,byte[]>- Parameters:
sessionKey- key of the session to writeaggregate- the aggregated value for the session, it can be null; if the serialized bytes are also null it is interpreted as deletes
-
remove
public void remove(Windowed<org.apache.kafka.common.utils.Bytes> sessionKey)
Description copied from interface:SessionStoreRemove the session aggregated with providedWindowedkey from the store- Specified by:
removein interfaceSessionStore<org.apache.kafka.common.utils.Bytes,byte[]>- Parameters:
sessionKey- key of the session to remove
-
fetchSession
public byte[] fetchSession(org.apache.kafka.common.utils.Bytes key, long startTime, long endTime)Description copied from interface:SessionStoreGet the value of key from a single session.- Specified by:
fetchSessionin interfaceSessionStore<org.apache.kafka.common.utils.Bytes,byte[]>- Parameters:
key- the key to fetchstartTime- start timestamp of the sessionendTime- end timestamp of the session- Returns:
- The value or
nullif no session associated with the key can be found
-
findSessions
@Deprecated public KeyValueIterator<Windowed<org.apache.kafka.common.utils.Bytes>,byte[]> findSessions(org.apache.kafka.common.utils.Bytes key, long earliestSessionEndTime, long latestSessionStartTime)
Deprecated.Description copied from interface:SessionStoreFetch any sessions with the matching key and the sessions end is ≥ earliestSessionEndTime and the sessions start is ≤ latestSessionStartTime This iterator must be closed after use.- Specified by:
findSessionsin interfaceSessionStore<org.apache.kafka.common.utils.Bytes,byte[]>- Parameters:
key- the key to return sessions forearliestSessionEndTime- the end timestamp of the earliest session to search forlatestSessionStartTime- the end timestamp of the latest session to search for- Returns:
- iterator of sessions with the matching key and aggregated values
-
findSessions
@Deprecated public KeyValueIterator<Windowed<org.apache.kafka.common.utils.Bytes>,byte[]> findSessions(org.apache.kafka.common.utils.Bytes keyFrom, org.apache.kafka.common.utils.Bytes keyTo, long earliestSessionEndTime, long latestSessionStartTime)
Deprecated.Description copied from interface:SessionStoreFetch any sessions in the given range of keys and the sessions end is ≥ earliestSessionEndTime and the sessions start is ≤ latestSessionStartTime This iterator must be closed after use.- Specified by:
findSessionsin interfaceSessionStore<org.apache.kafka.common.utils.Bytes,byte[]>- Parameters:
keyFrom- The first key that could be in the rangekeyTo- The last key that could be in the rangeearliestSessionEndTime- the end timestamp of the earliest session to search forlatestSessionStartTime- the end timestamp of the latest session to search for- Returns:
- iterator of sessions with the matching keys and aggregated values
-
fetch
public KeyValueIterator<Windowed<org.apache.kafka.common.utils.Bytes>,byte[]> fetch(org.apache.kafka.common.utils.Bytes key)
Description copied from interface:ReadOnlySessionStoreRetrieve all aggregated sessions for the provided key. This iterator must be closed after use. For each key, the iterator guarantees ordering of sessions, starting from the oldest/earliest available session to the newest/latest session.- Specified by:
fetchin interfaceReadOnlySessionStore<org.apache.kafka.common.utils.Bytes,byte[]>- Parameters:
key- record key to find aggregated session values for- Returns:
- KeyValueIterator containing all sessions for the provided key.
-
fetch
public KeyValueIterator<Windowed<org.apache.kafka.common.utils.Bytes>,byte[]> fetch(org.apache.kafka.common.utils.Bytes from, org.apache.kafka.common.utils.Bytes to)
Description copied from interface:ReadOnlySessionStoreRetrieve all aggregated sessions for the given range of keys. This iterator must be closed after use. For each key, the iterator guarantees ordering of sessions, starting from the oldest/earliest available session to the newest/latest session.- Specified by:
fetchin interfaceReadOnlySessionStore<org.apache.kafka.common.utils.Bytes,byte[]>- Parameters:
from- first key in the range to find aggregated session values forto- last key in the range to find aggregated session values for- Returns:
- KeyValueIterator containing all sessions for the provided key.
-
persistent
public boolean persistent()
Description copied from interface:StateStoreReturn if the storage is persistent or not.- Specified by:
persistentin interfaceStateStore- Returns:
trueif the storage is persistent—falseotherwise
-
isOpen
public boolean isOpen()
Description copied from interface:StateStoreIs this store open for reading and writing- Specified by:
isOpenin interfaceStateStore- Returns:
trueif the store is open
-
flush
public void flush()
Description copied from interface:StateStoreFlush any cached data- Specified by:
flushin interfaceStateStore
-
close
public void close()
Description copied from interface:StateStoreClose the storage engine. Note that this function needs to be idempotent since it may be called several times on the same state store.Users only need to implement this function but should NEVER need to call this api explicitly as it will be called by the library automatically when necessary
- Specified by:
closein interfaceStateStore
-
-