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`

      public class InMemoryKeyValueState<K,​V>
      extends Object
      implements KeyValueState<K,​V>

  An in-memory implementation of the `State`.

- - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `InMemoryKeyValueState()` |

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | 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.
    `Iterator<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.
    `String` | `toString()` |

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

    - ### Methods inherited from interface java.lang.Iterable

      `forEach, spliterator`

- - ### Constructor Detail

    - #### InMemoryKeyValueState

          public InMemoryKeyValueState()

  - ### Method Detail

    - #### put

          public void put​(K key,
                          V value)

      Description copied from interface: `KeyValueState`
      Maps the value with the key.
      Specified by:
        `put` in interface `KeyValueState<K,​V>`
      Parameters:
        `key` - the key
        `value` - the value

    - #### get

          public V get​(K key)

      Description copied from interface: `KeyValueState`
      Returns the value mapped to the key.
      Specified by:
        `get` in interface `KeyValueState<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: `KeyValueState`
      Returns the value mapped to the key or defaultValue if no mapping is found.
      Specified by:
        `get` in interface `KeyValueState<K,​V>`
      Parameters:
        `key` - the key
        `defaultValue` - 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: `KeyValueState`
      Deletes the value mapped to the key, if there is any.
      Specified by:
        `delete` in interface `KeyValueState<K,​V>`
      Parameters:
        `key` - the key

    - #### iterator

          public Iterator<Map.Entry<K,​V>> iterator()

      Specified by:
        `iterator` in interface `Iterable<K>`

    - #### commit

          public void commit()

      Description copied from interface: `State`
      Persist the current state. This is used when the component manages the state.
      Specified by:
        `commit` in interface `State`

    - #### commit

          public void commit​(long txid)

      Description copied from interface: `State`
      Commit a previously prepared transaction. It should be possible to retrieve a committed state later.
      Specified by:
        `commit` in interface `State`
      Parameters:
        `txid` - the transaction id

    - #### prepareCommit

          public void prepareCommit​(long txid)

      Description copied from interface: `State`
      Invoked 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:
        `prepareCommit` in interface `State`
      Parameters:
        `txid` - the transaction id

    - #### rollback

          public void rollback()

      Description copied from interface: `State`
      Rollback a prepared transaction to the previously committed state.
      Specified by:
        `rollback` in interface `State`

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`