Class InMemoryWindowStore
- java.lang.Object
-
- org.apache.kafka.streams.state.internals.InMemoryWindowStore
-
- All Implemented Interfaces:
StateStore
,ReadOnlyWindowStore<org.apache.kafka.common.utils.Bytes,byte[]>
,WindowStore<org.apache.kafka.common.utils.Bytes,byte[]>
public class InMemoryWindowStore extends Object implements WindowStore<org.apache.kafka.common.utils.Bytes,byte[]>
-
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description KeyValueIterator<Windowed<org.apache.kafka.common.utils.Bytes>,byte[]>
all()
Gets all the key-value pairs in the existing windows.void
close()
Close the storage engine.byte[]
fetch(org.apache.kafka.common.utils.Bytes key, long windowStartTimestamp)
Get the value of key from a window.WindowStoreIterator<byte[]>
fetch(org.apache.kafka.common.utils.Bytes key, long timeFrom, long timeTo)
Deprecated.KeyValueIterator<Windowed<org.apache.kafka.common.utils.Bytes>,byte[]>
fetch(org.apache.kafka.common.utils.Bytes from, org.apache.kafka.common.utils.Bytes to, long timeFrom, long timeTo)
Deprecated.KeyValueIterator<Windowed<org.apache.kafka.common.utils.Bytes>,byte[]>
fetchAll(long timeFrom, long timeTo)
Deprecated.void
flush()
Flush any cached datavoid
init(ProcessorContext context, StateStore root)
Initializes this state store.boolean
isOpen()
Is this store open for reading and writingString
name()
The name of this store.boolean
persistent()
Return if the storage is persistent or not.void
put(org.apache.kafka.common.utils.Bytes key, byte[] value)
Deprecated.void
put(org.apache.kafka.common.utils.Bytes key, byte[] value, long windowStartTimestamp)
Put a key-value pair into the window with given window start timestamp-
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.state.WindowStore
fetch, fetch, fetchAll
-
-
-
-
Method Detail
-
name
public String name()
Description copied from interface:StateStore
The name of this store.- Specified by:
name
in interfaceStateStore
- Returns:
- the storage name
-
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
-
put
@Deprecated public void put(org.apache.kafka.common.utils.Bytes key, byte[] value)
Deprecated.Description copied from interface:WindowStore
Use the current record timestamp as thewindowStartTimestamp
and 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:
put
in interfaceWindowStore<org.apache.kafka.common.utils.Bytes,byte[]>
- 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(org.apache.kafka.common.utils.Bytes key, byte[] value, long windowStartTimestamp)
Description copied from interface:WindowStore
Put 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:
put
in interfaceWindowStore<org.apache.kafka.common.utils.Bytes,byte[]>
- 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 byte[] fetch(org.apache.kafka.common.utils.Bytes key, long windowStartTimestamp)
Description copied from interface:ReadOnlyWindowStore
Get the value of key from a window.- Specified by:
fetch
in interfaceReadOnlyWindowStore<org.apache.kafka.common.utils.Bytes,byte[]>
- Parameters:
key
- the key to fetchwindowStartTimestamp
- start timestamp (inclusive) of the window- Returns:
- The value or
null
if no value is found in the window
-
fetch
@Deprecated public WindowStoreIterator<byte[]> fetch(org.apache.kafka.common.utils.Bytes key, long timeFrom, long timeTo)
Deprecated.Description copied from interface:WindowStore
Get 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:
fetch
in interfaceReadOnlyWindowStore<org.apache.kafka.common.utils.Bytes,byte[]>
- Specified by:
fetch
in interfaceWindowStore<org.apache.kafka.common.utils.Bytes,byte[]>
- 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
@Deprecated 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, long timeFrom, long timeTo)
Deprecated.Description copied from interface:WindowStore
Get 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:
fetch
in interfaceReadOnlyWindowStore<org.apache.kafka.common.utils.Bytes,byte[]>
- Specified by:
fetch
in interfaceWindowStore<org.apache.kafka.common.utils.Bytes,byte[]>
- 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
@Deprecated public KeyValueIterator<Windowed<org.apache.kafka.common.utils.Bytes>,byte[]> fetchAll(long timeFrom, long timeTo)
Deprecated.Description copied from interface:WindowStore
Gets all the key-value pairs that belong to the windows within in the given time range.- Specified by:
fetchAll
in interfaceReadOnlyWindowStore<org.apache.kafka.common.utils.Bytes,byte[]>
- Specified by:
fetchAll
in interfaceWindowStore<org.apache.kafka.common.utils.Bytes,byte[]>
- 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<org.apache.kafka.common.utils.Bytes>,byte[]> all()
Description copied from interface:ReadOnlyWindowStore
Gets all the key-value pairs in the existing windows.- Specified by:
all
in interfaceReadOnlyWindowStore<org.apache.kafka.common.utils.Bytes,byte[]>
- Returns:
- an iterator over windowed key-value pairs
<Windowed<K>, value>
-
persistent
public boolean persistent()
Description copied from interface:StateStore
Return if the storage is persistent or not.- Specified by:
persistent
in interfaceStateStore
- Returns:
true
if the storage is persistent—false
otherwise
-
isOpen
public boolean isOpen()
Description copied from interface:StateStore
Is this store open for reading and writing- Specified by:
isOpen
in interfaceStateStore
- Returns:
true
if the store is open
-
flush
public void flush()
Description copied from interface:StateStore
Flush any cached data- Specified by:
flush
in interfaceStateStore
-
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
-
-