Package org.apache.storm.state

## Class BaseStateIterator<K,​V,​KENCODEDT,​VENCODEDT>

- java.lang.Object
- - org.apache.storm.state.BaseStateIterator<K,​V,​KENCODEDT,​VENCODEDT>

- All Implemented Interfaces:
    `Iterator<Map.Entry<K,​V>>`
  Direct Known Subclasses:
    `BaseBinaryStateIterator`

      public abstract class BaseStateIterator<K,​V,​KENCODEDT,​VENCODEDT>
      extends Object
      implements Iterator<Map.Entry<K,​V>>

  Base implementation of iterator over `KeyValueState`. Encoded/Decoded types of key and value are all generic.

- - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `BaseStateIterator​(Iterator<Map.Entry<KENCODEDT,​VENCODEDT>> pendingPrepareIterator, Iterator<Map.Entry<KENCODEDT,​VENCODEDT>> pendingCommitIterator, Set<KENCODEDT> initialProvidedKeys)` | Constructor.

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `protected abstract K` | `decodeKey​(KENCODEDT key)` | Decode key to convert encoded type of key to state key type.
    `protected abstract V` | `decodeValue​(VENCODEDT value)` | Decode value to convert encoded type of value to state value type.
    `boolean` | `hasNext()` |
    `protected abstract boolean` | `isEndOfDataFromStorage()` | Check whether end of data is reached from storage state KVs.
    `protected abstract boolean` | `isTombstoneValue​(VENCODEDT value)` | Check whether the value is tombstone (deletion mark) value.
    `protected abstract Iterator<Map.Entry<KENCODEDT,​VENCODEDT>>` | `loadChunkFromStateStorage()` | Load some part of state KVs from storage and returns iterator of cached data from storage.
    `Map.Entry<K,​V>` | `next()` |
    `void` | `remove()` |

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

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

    - ### Methods inherited from interface java.util.Iterator

      `forEachRemaining`

- - ### Constructor Detail

    - #### BaseStateIterator

          public BaseStateIterator​(Iterator<Map.Entry<KENCODEDT,​VENCODEDT>> pendingPrepareIterator,
                                   Iterator<Map.Entry<KENCODEDT,​VENCODEDT>> pendingCommitIterator,
                                   Set<KENCODEDT> initialProvidedKeys)

      Constructor.
      Parameters:
        `pendingPrepareIterator` - The iterator of pendingPrepare
        `pendingCommitIterator` - The iterator of pendingCommit
        `initialProvidedKeys` - The initial value of provided keys

  - ### Method Detail

    - #### hasNext

          public boolean hasNext()

      Specified by:
        `hasNext` in interface `Iterator<K>`

    - #### next

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

      Specified by:
        `next` in interface `Iterator<K>`

    - #### remove

          public void remove()

      Specified by:
        `remove` in interface `Iterator<K>`

    - #### loadChunkFromStateStorage

          protected abstract Iterator<Map.Entry<KENCODEDT,​VENCODEDT>> loadChunkFromStateStorage()

      Load some part of state KVs from storage and returns iterator of cached data from storage.
      Returns:
        Iterator of loaded state KVs

    - #### isEndOfDataFromStorage

          protected abstract boolean isEndOfDataFromStorage()

      Check whether end of data is reached from storage state KVs.
      Returns:
        whether end of data is reached from storage state KVs

    - #### decodeKey

          protected abstract K decodeKey​(KENCODEDT key)

      Decode key to convert encoded type of key to state key type.
      Parameters:
        `key` - raw type of encoded key
      Returns:
        Decoded value of key

    - #### decodeValue

          protected abstract V decodeValue​(VENCODEDT value)

      Decode value to convert encoded type of value to state value type.
      Parameters:
        `value` - raw type of encoded value
      Returns:
        Decoded value of value

    - #### isTombstoneValue

          protected abstract boolean isTombstoneValue​(VENCODEDT value)

      Check whether the value is tombstone (deletion mark) value.
      Parameters:
        `value` - the value to check
      Returns:
        true if the value is tombstone, false otherwise