Package org.apache.storm.state
Class InMemoryKeyValueState<K,V>
java.lang.Object
org.apache.storm.state.InMemoryKeyValueState<K,V>
- All Implemented Interfaces:
Iterable<Map.Entry<K,,V>> KeyValueState<K,,V> State
An in-memory implementation of the
State.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcommit()Persist the current state.voidcommit(long txid) Commit a previously prepared transaction.Deletes the value mapped to the key, if there is any.Returns the value mapped to the key.Returns the value mapped to the key or defaultValue if no mapping is found.iterator()voidprepareCommit(long txid) Invoked by the framework to prepare a transaction for commit.voidMaps the value with the key.voidrollback()Rollback a prepared transaction to the previously committed state.toString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
InMemoryKeyValueState
public InMemoryKeyValueState()
-
-
Method Details
-
put
Description copied from interface:KeyValueStateMaps the value with the key.- Specified by:
putin interfaceKeyValueState<K,V> - Parameters:
key- the keyvalue- the value
-
get
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
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
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
-
iterator
-
commit
public void commit()Description copied from interface:StatePersist the current state. This is used when the component manages the state. -
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. -
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
-
rollback
public void rollback()Description copied from interface:StateRollback a prepared transaction to the previously committed state. -
toString
-