public class InMemoryKeyValueStore<K,V> extends java.lang.Object implements KeyValueStore<K,V>
Constructor and Description |
---|
InMemoryKeyValueStore(java.lang.String name,
org.apache.kafka.common.serialization.Serde<K> keySerde,
org.apache.kafka.common.serialization.Serde<V> valueSerde) |
Modifier and Type | Method and Description |
---|---|
KeyValueIterator<K,V> |
all()
Return an iterator over all keys in this store.
|
long |
approximateNumEntries()
Return an approximate count of key-value mappings in this store.
|
void |
close()
Close the storage engine.
|
V |
delete(K key)
Delete the value from the store (if there is one).
|
KeyValueStore<K,V> |
enableLogging() |
void |
flush()
Flush any cached data
|
V |
get(K key)
Get the value corresponding to this key.
|
void |
init(ProcessorContext context,
StateStore root)
Initializes this state store.
|
boolean |
isOpen()
Is this store open for reading and writing
|
java.lang.String |
name()
The name of this store.
|
boolean |
persistent()
Return if the storage is persistent or not.
|
void |
put(K key,
V value)
Update the value associated with this key.
|
void |
putAll(java.util.List<KeyValue<K,V>> entries)
Update all the given key/value pairs.
|
V |
putIfAbsent(K key,
V value)
Update the value associated with this key, unless a value is already associated with the key.
|
KeyValueIterator<K,V> |
range(K from,
K to)
Get an iterator over a given range of keys.
|
public KeyValueStore<K,V> enableLogging()
public java.lang.String name()
StateStore
name
in interface StateStore
public void init(ProcessorContext context, StateStore root)
StateStore
The implementation of this function must register the root store in the context via the
ProcessorContext.register(StateStore, StateRestoreCallback)
function, where the
first StateStore
parameter should always be the passed-in root
object, and
the second parameter should be an object of user's implementation
of the StateRestoreCallback
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 extends StateRestoreCallback
to
let users implement bulk-load restoration logic instead of restoring one record at a time.
init
in interface StateStore
public boolean persistent()
StateStore
persistent
in interface StateStore
true
if the storage is persistent—false
otherwisepublic boolean isOpen()
StateStore
isOpen
in interface StateStore
true
if the store is openpublic V get(K key)
ReadOnlyKeyValueStore
get
in interface ReadOnlyKeyValueStore<K,V>
key
- The key to fetchpublic void put(K key, V value)
KeyValueStore
put
in interface KeyValueStore<K,V>
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 deletespublic V putIfAbsent(K key, V value)
KeyValueStore
putIfAbsent
in interface KeyValueStore<K,V>
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 deletesnull
if there is no such key.public void putAll(java.util.List<KeyValue<K,V>> entries)
KeyValueStore
putAll
in interface KeyValueStore<K,V>
entries
- A list of entries to put into the store;
if the serialized bytes are also null
it is interpreted as deletespublic V delete(K key)
KeyValueStore
delete
in interface KeyValueStore<K,V>
key
- The keynull
if there is no such key.public KeyValueIterator<K,V> range(K from, K to)
ReadOnlyKeyValueStore
ConcurrentModificationException
s
and must not return null values. No ordering guarantees are provided.range
in interface ReadOnlyKeyValueStore<K,V>
from
- The first key that could be in the rangeto
- The last key that could be in the rangepublic KeyValueIterator<K,V> all()
ReadOnlyKeyValueStore
ConcurrentModificationException
s
and must not return null values. No ordering guarantees are provided.all
in interface ReadOnlyKeyValueStore<K,V>
public long approximateNumEntries()
ReadOnlyKeyValueStore
approximateNumEntries
in interface ReadOnlyKeyValueStore<K,V>
public void flush()
StateStore
flush
in interface StateStore
public void close()
StateStore
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
close
in interface StateStore