public class InMemoryKeyValueState<K,V> extends java.lang.Object implements KeyValueState<K,V>
State
Constructor and Description |
---|
InMemoryKeyValueState() |
Modifier and Type | Method and Description |
---|---|
void |
commit()
Persist the current state.
|
void |
commit(long txid)
Commit a previously prepared transaction.
|
V |
delete(K key)
Deletes the value mapped to the key, if there is any
|
V |
get(K key)
Returns the value mapped to the key
|
V |
get(K key,
V defaultValue)
Returns the value mapped to the key or defaultValue if no mapping is found.
|
java.util.Iterator<java.util.Map.Entry<K,V>> |
iterator() |
void |
prepareCommit(long txid)
Invoked by the framework to prepare a transaction for commit.
|
void |
put(K key,
V value)
Maps the value with the key
|
void |
rollback()
Rollback a prepared transaction to the previously committed state.
|
java.lang.String |
toString() |
public void put(K key, V value)
KeyValueState
put
in interface KeyValueState<K,V>
key
- the keyvalue
- the valuepublic V get(K key)
KeyValueState
get
in interface KeyValueState<K,V>
key
- the keypublic V get(K key, V defaultValue)
KeyValueState
get
in interface KeyValueState<K,V>
key
- the keydefaultValue
- the value to return if no mapping is foundpublic V delete(K key)
KeyValueState
delete
in interface KeyValueState<K,V>
key
- the keypublic void commit()
State
public void prepareCommit(long txid)
State
The same txid can be prepared again, but the next txid cannot be prepared when previous one is not yet committed.
prepareCommit
in interface State
txid
- the transaction idpublic void commit(long txid)
State
public void rollback()
State
public java.lang.String toString()
toString
in class java.lang.Object