Package org.apache.storm.redis.state
Class RedisKeyValueState<K,V>
- java.lang.Object
-
- org.apache.storm.redis.state.RedisKeyValueState<K,V>
-
- All Implemented Interfaces:
Iterable<Map.Entry<K,V>>,KeyValueState<K,V>,State
public class RedisKeyValueState<K,V> extends Object implements KeyValueState<K,V>
A redis based implementation that persists the state in Redis.
-
-
Field Summary
Fields Modifier and Type Field Description static NavigableMap<byte[],byte[]>EMPTY_PENDING_COMMIT_MAPstatic intITERATOR_CHUNK_SIZE
-
Constructor Summary
Constructors Constructor Description RedisKeyValueState(String namespace)RedisKeyValueState(String namespace, JedisClusterConfig jedisClusterConfig, Serializer<K> keySerializer, Serializer<V> valueSerializer)RedisKeyValueState(String namespace, JedisPoolConfig poolConfig)RedisKeyValueState(String namespace, JedisPoolConfig poolConfig, Serializer<K> keySerializer, Serializer<V> valueSerializer)RedisKeyValueState(String namespace, RedisCommandsInstanceContainer container, Serializer<K> keySerializer, Serializer<V> valueSerializer)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcommit()Persist the current state.voidcommit(long txid)Commit a previously prepared transaction.Vdelete(K key)Deletes the value mapped to the key, if there is any.Vget(K key)Returns the value mapped to the key.Vget(K key, V defaultValue)Returns the value mapped to the key or defaultValue if no mapping is found.Iterator<Map.Entry<K,V>>iterator()voidprepareCommit(long txid)Invoked by the framework to prepare a transaction for commit.voidput(K key, V value)Maps the value with the key.voidrollback()Rollback a prepared transaction to the previously committed state.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Field Detail
-
ITERATOR_CHUNK_SIZE
public static final int ITERATOR_CHUNK_SIZE
- See Also:
- Constant Field Values
-
EMPTY_PENDING_COMMIT_MAP
public static final NavigableMap<byte[],byte[]> EMPTY_PENDING_COMMIT_MAP
-
-
Constructor Detail
-
RedisKeyValueState
public RedisKeyValueState(String namespace)
-
RedisKeyValueState
public RedisKeyValueState(String namespace, JedisPoolConfig poolConfig)
-
RedisKeyValueState
public RedisKeyValueState(String namespace, JedisPoolConfig poolConfig, Serializer<K> keySerializer, Serializer<V> valueSerializer)
-
RedisKeyValueState
public RedisKeyValueState(String namespace, JedisClusterConfig jedisClusterConfig, Serializer<K> keySerializer, Serializer<V> valueSerializer)
-
RedisKeyValueState
public RedisKeyValueState(String namespace, RedisCommandsInstanceContainer container, Serializer<K> keySerializer, Serializer<V> valueSerializer)
-
-
Method Detail
-
put
public void put(K key, V value)
Description copied from interface:KeyValueStateMaps the value with the key.- Specified by:
putin interfaceKeyValueState<K,V>- Parameters:
key- the keyvalue- the value
-
get
public V get(K key)
Description copied from interface:KeyValueStateReturns the value mapped to the key.- Specified by:
getin interfaceKeyValueState<K,V>- Parameters:
key- the key- Returns:
- the value or null if no mapping is found
-
get
public V get(K key, V defaultValue)
Description copied from interface:KeyValueStateReturns the value mapped to the key or defaultValue if no mapping is found.- Specified by:
getin interfaceKeyValueState<K,V>- Parameters:
key- the keydefaultValue- the value to return if no mapping is found- Returns:
- the value or defaultValue if no mapping is found
-
delete
public V delete(K key)
Description copied from interface:KeyValueStateDeletes the value mapped to the key, if there is any.- Specified by:
deletein interfaceKeyValueState<K,V>- Parameters:
key- the key
-
prepareCommit
public void prepareCommit(long txid)
Description copied from interface:StateInvoked by the framework to prepare a transaction for commit. It should be possible to commit the prepared state later.The same txid can be prepared again, but the next txid cannot be prepared when previous one is not yet committed.
- Specified by:
prepareCommitin interfaceState- Parameters:
txid- the transaction id
-
commit
public void commit(long txid)
Description copied from interface:StateCommit a previously prepared transaction. It should be possible to retrieve a committed state later.
-
commit
public void commit()
Description copied from interface:StatePersist the current state. This is used when the component manages the state.
-
-