org.apache.ignite.streamer.index

## Interface StreamerIndexUpdater<E,K,V>

    public interface StreamerIndexUpdater<E,K,V>

Index updater. The main responsibility of index updater is to maintain index values up to date whenever events are added or removed from window.

Updater is provided to index provider in configuration usually via `StreamerIndexProviderAdapter.setUpdater(StreamerIndexUpdater)` method.

### Method Summary

Methods
`K` `indexKey(E evt)` Given an event, extract index key.
`V` `initialValue(E evt, K key)` Gets initial value for the index or `null` if event should be ignored.
`V` `onAdded(StreamerIndexEntry<E,K,V> entry, E evt)` Callback invoked whenever an event is being added to the window.
`V` `onRemoved(StreamerIndexEntry<E,K,V> entry, E evt)` Callback invoked whenever an event is being removed from the window and has index entry for given key.

### Method Detail

#### indexKey

    @Nullable
    K indexKey(E evt)

Given an event, extract index key. For example, if you have a 'Person' object with field 'age' and need to index based on this field, then this method should return the value of age field.

If `null` is returned then event will be ignored by the index.

Parameters:
  `evt` - Event being added or removed from the window.
Returns:
  Index key for this event.

#### initialValue

    @Nullable
    V initialValue(E evt,
                          K key)

Gets initial value for the index or `null` if event should be ignored. This method is called every time when an entry is added to the window in order to get initial value for given key.

Parameters:
  `evt` - Event being added to or removed from window.
  `key` - Index key return by `indexKey(Object)` method.
Returns:
  Initial value for given key, if `null` then event will be ignored and index entry will not be created.

#### onAdded

    @Nullable
    V onAdded(StreamerIndexEntry<E,K,V> entry,
                     E evt)
              throws IgniteException

Callback invoked whenever an event is being added to the window. Given a key and a current index value for this key, the implementation should return the new value for this key. If returned value is `null`, then current entry will be removed from the index.

If index is sorted, then sorting happens based on the returned value.

Parameters:
  `entry` - Current index entry.
  `evt` - New event.
Returns:
  New index value for given key, if `null`, then current index entry will be removed the index.
Throws:
  `IgniteException` - If entry should not be added to index (e.g. if uniqueness is violated).

#### onRemoved

    @Nullable
    V onRemoved(StreamerIndexEntry<E,K,V> entry,
                       E evt)

Callback invoked whenever an event is being removed from the window and has index entry for given key. If there was no entry for given key, then `onRemoved()` will not be called.

Given a key and a current index value for this key, the implementation should return the new value for this key. If returned value is `null`, then current entry will be removed from the index.

If index is sorted, then sorting happens based on the returned value.

Parameters:
  `entry` - Current index entry.
  `evt` - Event being removed from the window.
Returns:
  New index value for given key, if `null`, then current index entry will be removed the index.

2015 Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Fabric | : ver. 1.0.0-RC3
Release Date | : March 24 2015