Class MeteredSessionStore<K,V>
- java.lang.Object
-
- org.apache.kafka.streams.state.internals.WrappedStateStore<SessionStore<org.apache.kafka.common.utils.Bytes,byte[]>,Windowed<K>,V>
-
- org.apache.kafka.streams.state.internals.MeteredSessionStore<K,V>
-
- All Implemented Interfaces:
StateStore
,CachedStateStore<Windowed<K>,V>
,ReadOnlySessionStore<K,V>
,SessionStore<K,V>
public class MeteredSessionStore<K,V> extends WrappedStateStore<SessionStore<org.apache.kafka.common.utils.Bytes,byte[]>,Windowed<K>,V> implements SessionStore<K,V>
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Close the storage engine.KeyValueIterator<Windowed<K>,V>
fetch(K key)
Retrieve all aggregated sessions for the provided key.KeyValueIterator<Windowed<K>,V>
fetch(K from, K to)
Retrieve all aggregated sessions for the given range of keys.V
fetchSession(K key, long startTime, long endTime)
Get the value of key from a single session.KeyValueIterator<Windowed<K>,V>
findSessions(K key, long earliestSessionEndTime, long latestSessionStartTime)
Fetch 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.KeyValueIterator<Windowed<K>,V>
findSessions(K keyFrom, K keyTo, long earliestSessionEndTime, long latestSessionStartTime)
Fetch 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.void
flush()
Flush any cached datavoid
init(ProcessorContext context, StateStore root)
Initializes this state store.void
put(Windowed<K> sessionKey, V aggregate)
Write the aggregated value for the provided key to the storevoid
remove(Windowed<K> sessionKey)
Remove the session aggregated with providedWindowed
key from the storeboolean
setFlushListener(CacheFlushListener<Windowed<K>,V> listener, boolean sendOldValues)
Set theCacheFlushListener
to be notified when entries are flushed from the cache to the underlyingStateStore
-
Methods inherited from class org.apache.kafka.streams.state.internals.WrappedStateStore
isOpen, isTimestamped, name, persistent, wrapped
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.kafka.streams.processor.StateStore
isOpen, name, persistent
-
-
-
-
Method Detail
-
init
public void init(ProcessorContext context, StateStore root)
Description copied from interface:StateStore
Initializes 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 firstStateStore
parameter should always be the passed-inroot
object, and the second parameter should be an object of user's implementation of theStateRestoreCallback
interface 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
BatchingStateRestoreCallback
which extendsStateRestoreCallback
to let users implement bulk-load restoration logic instead of restoring one record at a time.- Specified by:
init
in interfaceStateStore
- Overrides:
init
in classWrappedStateStore<SessionStore<org.apache.kafka.common.utils.Bytes,byte[]>,Windowed<K>,V>
-
setFlushListener
public boolean setFlushListener(CacheFlushListener<Windowed<K>,V> listener, boolean sendOldValues)
Description copied from interface:CachedStateStore
Set theCacheFlushListener
to be notified when entries are flushed from the cache to the underlyingStateStore
- Specified by:
setFlushListener
in interfaceCachedStateStore<K,V>
- Overrides:
setFlushListener
in classWrappedStateStore<SessionStore<org.apache.kafka.common.utils.Bytes,byte[]>,Windowed<K>,V>
-
put
public void put(Windowed<K> sessionKey, V aggregate)
Description copied from interface:SessionStore
Write the aggregated value for the provided key to the store- Specified by:
put
in interfaceSessionStore<K,V>
- 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<K> sessionKey)
Description copied from interface:SessionStore
Remove the session aggregated with providedWindowed
key from the store- Specified by:
remove
in interfaceSessionStore<K,V>
- Parameters:
sessionKey
- key of the session to remove
-
fetchSession
public V fetchSession(K key, long startTime, long endTime)
Description copied from interface:SessionStore
Get the value of key from a single session.- Specified by:
fetchSession
in interfaceSessionStore<K,V>
- Parameters:
key
- the key to fetchstartTime
- start timestamp of the sessionendTime
- end timestamp of the session- Returns:
- The value or
null
if no session associated with the key can be found
-
fetch
public KeyValueIterator<Windowed<K>,V> fetch(K key)
Description copied from interface:ReadOnlySessionStore
Retrieve 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:
fetch
in interfaceReadOnlySessionStore<K,V>
- Parameters:
key
- record key to find aggregated session values for- Returns:
- KeyValueIterator containing all sessions for the provided key.
-
fetch
public KeyValueIterator<Windowed<K>,V> fetch(K from, K to)
Description copied from interface:ReadOnlySessionStore
Retrieve 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:
fetch
in interfaceReadOnlySessionStore<K,V>
- 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.
-
findSessions
public KeyValueIterator<Windowed<K>,V> findSessions(K key, long earliestSessionEndTime, long latestSessionStartTime)
Description copied from interface:SessionStore
Fetch 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:
findSessions
in interfaceSessionStore<K,V>
- 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
public KeyValueIterator<Windowed<K>,V> findSessions(K keyFrom, K keyTo, long earliestSessionEndTime, long latestSessionStartTime)
Description copied from interface:SessionStore
Fetch 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:
findSessions
in interfaceSessionStore<K,V>
- 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
-
flush
public void flush()
Description copied from interface:StateStore
Flush any cached data- Specified by:
flush
in interfaceStateStore
- Overrides:
flush
in classWrappedStateStore<SessionStore<org.apache.kafka.common.utils.Bytes,byte[]>,Windowed<K>,V>
-
close
public void close()
Description copied from interface:StateStore
Close 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:
close
in interfaceStateStore
- Overrides:
close
in classWrappedStateStore<SessionStore<org.apache.kafka.common.utils.Bytes,byte[]>,Windowed<K>,V>
-
-