Class MeteredWindowStore<K,V>
- java.lang.Object
-
- org.apache.kafka.streams.state.internals.WrappedStateStore<WindowStore<org.apache.kafka.common.utils.Bytes,byte[]>,Windowed<K>,V>
-
- org.apache.kafka.streams.state.internals.MeteredWindowStore<K,V>
-
- All Implemented Interfaces:
StateStore,CachedStateStore<Windowed<K>,V>,ReadOnlyWindowStore<K,V>,WindowStore<K,V>
public class MeteredWindowStore<K,V> extends WrappedStateStore<WindowStore<org.apache.kafka.common.utils.Bytes,byte[]>,Windowed<K>,V> implements WindowStore<K,V>
-
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description KeyValueIterator<Windowed<K>,V>all()Gets all the key-value pairs in the existing windows.voidclose()Close the storage engine.Vfetch(K key, long timestamp)Get the value of key from a window.WindowStoreIterator<V>fetch(K key, long timeFrom, long timeTo)Get all the key-value pairs with the given key and the time range from all the existing windows.KeyValueIterator<Windowed<K>,V>fetch(K from, K to, long timeFrom, long timeTo)Get all the key-value pairs in the given key range and time range from all the existing windows.KeyValueIterator<Windowed<K>,V>fetchAll(long timeFrom, long timeTo)Gets all the key-value pairs that belong to the windows within in the given time range.voidflush()Flush any cached datavoidinit(ProcessorContext context, StateStore root)Initializes this state store.protected org.apache.kafka.common.serialization.Serde<V>prepareValueSerde(org.apache.kafka.common.serialization.Serde<V> valueSerde, org.apache.kafka.common.serialization.Serde<?> contextKeySerde, org.apache.kafka.common.serialization.Serde<?> contextValueSerde)voidput(K key, V value)Deprecated.voidput(K key, V value, long windowStartTimestamp)Put a key-value pair into the window with given window start timestampbooleansetFlushListener(CacheFlushListener<Windowed<K>,V> listener, boolean sendOldValues)Set theCacheFlushListenerto 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
-
Methods inherited from interface org.apache.kafka.streams.state.WindowStore
fetch, fetch, fetchAll
-
-
-
-
Method Detail
-
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- Overrides:
initin classWrappedStateStore<WindowStore<org.apache.kafka.common.utils.Bytes,byte[]>,Windowed<K>,V>
-
prepareValueSerde
protected org.apache.kafka.common.serialization.Serde<V> prepareValueSerde(org.apache.kafka.common.serialization.Serde<V> valueSerde, org.apache.kafka.common.serialization.Serde<?> contextKeySerde, org.apache.kafka.common.serialization.Serde<?> contextValueSerde)
-
setFlushListener
public boolean setFlushListener(CacheFlushListener<Windowed<K>,V> listener, boolean sendOldValues)
Description copied from interface:CachedStateStoreSet theCacheFlushListenerto be notified when entries are flushed from the cache to the underlyingStateStore- Specified by:
setFlushListenerin interfaceCachedStateStore<K,V>- Overrides:
setFlushListenerin classWrappedStateStore<WindowStore<org.apache.kafka.common.utils.Bytes,byte[]>,Windowed<K>,V>
-
put
@Deprecated public void put(K key, V value)
Deprecated.Description copied from interface:WindowStoreUse the current record timestamp as thewindowStartTimestampand delegate toWindowStore.put(Object, Object, long).It's highly recommended to use
WindowStore.put(Object, Object, long)instead, as the record timestamp is unlikely to be the correct windowStartTimestamp in general.- Specified by:
putin interfaceWindowStore<K,V>- Parameters:
key- The key to associate the value tovalue- The value to update, it can be null; if the serialized bytes are also null it is interpreted as delete
-
put
public void put(K key, V value, long windowStartTimestamp)
Description copied from interface:WindowStorePut a key-value pair into the window with given window start timestampIf serialized value bytes are null it is interpreted as delete. Note that deletes will be ignored in the case of an underlying store that retains duplicates.
- Specified by:
putin interfaceWindowStore<K,V>- Parameters:
key- The key to associate the value tovalue- The value; can be nullwindowStartTimestamp- The timestamp of the beginning of the window to put the key/value into
-
fetch
public V fetch(K key, long timestamp)
Description copied from interface:ReadOnlyWindowStoreGet the value of key from a window.- Specified by:
fetchin interfaceReadOnlyWindowStore<K,V>- Parameters:
key- the key to fetchtimestamp- start timestamp (inclusive) of the window- Returns:
- The value or
nullif no value is found in the window
-
fetch
public WindowStoreIterator<V> fetch(K key, long timeFrom, long timeTo)
Description copied from interface:WindowStoreGet all the key-value pairs with the given key and the time range from all the existing windows.This iterator must be closed after use.
The time range is inclusive and applies to the starting timestamp of the window. For example, if we have the following windows:
+-------------------------------+ | key | start time | end time | +-------+------------+----------+ | A | 10 | 20 | +-------+------------+----------+ | A | 15 | 25 | +-------+------------+----------+ | A | 20 | 30 | +-------+------------+----------+ | A | 25 | 35 | +--------------------------------
And we callstore.fetch("A", 10, 20)then the results will contain the first three windows from the table above, i.e., all those where 10 <= start time <= 20.For each key, the iterator guarantees ordering of windows, starting from the oldest/earliest available window to the newest/latest window.
- Specified by:
fetchin interfaceReadOnlyWindowStore<K,V>- Specified by:
fetchin interfaceWindowStore<K,V>- Parameters:
key- the key to fetchtimeFrom- time range start (inclusive)timeTo- time range end (inclusive)- Returns:
- an iterator over key-value pairs
<timestamp, value>
-
fetch
public KeyValueIterator<Windowed<K>,V> fetch(K from, K to, long timeFrom, long timeTo)
Description copied from interface:WindowStoreGet all the key-value pairs in the given key range and time range from all the existing windows.This iterator must be closed after use.
- Specified by:
fetchin interfaceReadOnlyWindowStore<K,V>- Specified by:
fetchin interfaceWindowStore<K,V>- Parameters:
from- the first key in the rangeto- the last key in the rangetimeFrom- time range start (inclusive)timeTo- time range end (inclusive)- Returns:
- an iterator over windowed key-value pairs
<Windowed<K>, value>
-
fetchAll
public KeyValueIterator<Windowed<K>,V> fetchAll(long timeFrom, long timeTo)
Description copied from interface:WindowStoreGets all the key-value pairs that belong to the windows within in the given time range.- Specified by:
fetchAllin interfaceReadOnlyWindowStore<K,V>- Specified by:
fetchAllin interfaceWindowStore<K,V>- Parameters:
timeFrom- the beginning of the time slot from which to search (inclusive)timeTo- the end of the time slot from which to search (inclusive)- Returns:
- an iterator over windowed key-value pairs
<Windowed<K>, value>
-
all
public KeyValueIterator<Windowed<K>,V> all()
Description copied from interface:ReadOnlyWindowStoreGets all the key-value pairs in the existing windows.- Specified by:
allin interfaceReadOnlyWindowStore<K,V>- Returns:
- an iterator over windowed key-value pairs
<Windowed<K>, value>
-
flush
public void flush()
Description copied from interface:StateStoreFlush any cached data- Specified by:
flushin interfaceStateStore- Overrides:
flushin classWrappedStateStore<WindowStore<org.apache.kafka.common.utils.Bytes,byte[]>,Windowed<K>,V>
-
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- Overrides:
closein classWrappedStateStore<WindowStore<org.apache.kafka.common.utils.Bytes,byte[]>,Windowed<K>,V>
-
-