org.apache.ignite.streamer.index

## Class StreamerIndexProviderAdapter<E,K,V>

- java.lang.Object
- - org.apache.ignite.streamer.index.StreamerIndexProviderAdapter<E,K,V>

All Implemented Interfaces:
  StreamerIndexProvider<E,K,V>, StreamerIndexProviderMBean

Direct Known Subclasses:
  StreamerHashIndexProvider, StreamerTreeIndexProvider

    public abstract class StreamerIndexProviderAdapter<E,K,V>
    extends Object
    implements StreamerIndexProvider<E,K,V>

Convenient `StreamerIndexProvider` adapter implementing base configuration methods.

### Nested Class Summary

Nested Classes
`protected static class` `StreamerIndexProviderAdapter.DedupTrackingEntry<E,K,V>` Entry with index policy `StreamerIndexPolicy.EVENT_TRACKING_ON_DEDUP`.
`protected static class` `StreamerIndexProviderAdapter.Entry<E,K,V>` Streamer window index entry.
`protected static class` `StreamerIndexProviderAdapter.EventTrackingEntry<E,K,V>` Entry with index policy `StreamerIndexPolicy.EVENT_TRACKING_ON`.
`protected static interface` `StreamerIndexProviderAdapter.IndexKey<V>` Streamer window index key.
`protected static class` `StreamerIndexProviderAdapter.NonTrackingEntry<E,K,V>` Entry with index policy `StreamerIndexPolicy.EVENT_TRACKING_OFF`.

### Field Summary

Fields
`protected IgniteClosure<StreamerIndexEntry<E,K,V>,K>` `entryToKey`
`protected IgniteClosure<StreamerIndexEntry<E,K,V>,V>` `entryToVal`

### Constructor Summary

Constructors
Constructor and Description
`StreamerIndexProviderAdapter()`

### Method Summary

Methods
`protected abstract void` `add(E evt, K key, StreamerIndexUpdateSync sync)` Add event to the index.
`void` `add(StreamerIndexUpdateSync sync, E evt)` Add event to the index.
`protected StreamerIndexProviderAdapter.Entry<E,K,V>` `addEvent(StreamerIndexEntry<E,K,V> oldEntry, K key, V val, StreamerIndexProviderAdapter.IndexKey<V> idxKey, E evt)`
`protected static <E> Collection<E>` `addToCollection(Collection<E> col, E evt)`
`protected static <E> Map<E,Integer>` `addToMap(Map<E,Integer> map, E evt)`
`void` `dispose()` Disposes the index.
`void` `endUpdate(StreamerIndexUpdateSync sync, E evt, boolean rollback, boolean rmv)` Finalizes an update operation.
`protected abstract void` `endUpdate0(StreamerIndexUpdateSync sync, E evt, K key, boolean rollback)`
`protected int` `eventsCount()`
`String` `getName()` Gets index name.
`StreamerIndexPolicy` `getPolicy()` Gets event indexing policy, which defines how events are tracked within an index.
`StreamerIndexUpdater<E,K,V>` `getUpdater()` Gets index updater.
`StreamerIndex<E,K,V>` `index()` Gets user view for this index.
`protected abstract StreamerIndex<E,K,V>` `index0()`
`boolean` `isUnique()` Checks whether this index is unique or not.
`protected void` `lockIndexKey(StreamerIndexProviderAdapter.IndexKey<V> key, StreamerIndexUpdateSync sync)` Lock updates on particular key.
`String` `name()` Index name.
`protected StreamerIndexProviderAdapter.Entry<E,K,V>` `newEntry(K key, V val, StreamerIndexProviderAdapter.IndexKey<V> idxKey, E evt)`
`StreamerIndexPolicy` `policy()` Gets index policy.
`protected void` `readLock()`
`protected void` `readUnlock()`
`protected abstract void` `remove(E evt, K key, StreamerIndexUpdateSync sync)` Remove event from the index.
`void` `remove(StreamerIndexUpdateSync sync, E evt)` Remove event from the index.
`protected StreamerIndexProviderAdapter.Entry<E,K,V>` `removeEvent(StreamerIndexEntry<E,K,V> oldEntry, K key, V val, StreamerIndexProviderAdapter.IndexKey<V> idxKey, E evt)`
`protected static <E> Collection<E>` `removeFromCollection(Collection<E> col, E evt)`
`protected static <E> Map<E,Integer>` `removeFromMap(Map<E,Integer> map, E evt)`
`void` `reset()` Resets the index to an initial empty state.
`protected abstract void` `reset0()` Called on reset.
`void` `setName(String name)` Sets index name.
`void` `setPolicy(StreamerIndexPolicy plc)` Sets index policy.
`void` `setUnique(boolean unique)` Sets unique flag.
`void` `setUpdater(StreamerIndexUpdater<E,K,V> updater)` Sets index updater.
`int` `size()` Gets current index size.
`String` `toString()`
`protected static <K,V> V` `trieGet(K key, TrieMap<K,V> map)` Utility method to safely get values from TrieMap.
`boolean` `unique()` Gets index unique flag.
`protected void` `unlockIndexKey(StreamerIndexProviderAdapter.IndexKey<V> key, StreamerIndexUpdateSync sync)` Unlock updates on particular key.
`String` `updaterClass()` Gets index updater class name.
`protected void` `writeLock()`
`protected void` `writeUnlock()`

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

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

### Methods inherited from interface org.apache.ignite.streamer.index.StreamerIndexProvider

`initialize`

### Methods inherited from interface org.apache.ignite.streamer.index.StreamerIndexProviderMBean

`sorted`

### Field Detail

#### entryToVal

    protected final IgniteClosure<StreamerIndexEntry<E,K,V>,V> entryToVal

#### entryToKey

    protected final IgniteClosure<StreamerIndexEntry<E,K,V>,K> entryToKey

### Constructor Detail

#### StreamerIndexProviderAdapter

    public StreamerIndexProviderAdapter()

### Method Detail

#### setName

    public void setName(String name)

Sets index name.

Parameters:
  `name` - Index name.

#### getName

    public String getName()

Gets index name.

Specified by:
  `getName` in interface `StreamerIndexProvider<E,K,V>`
Returns:
  Name of the index.

#### setPolicy

    public void setPolicy(StreamerIndexPolicy plc)

Sets index policy.

Parameters:
  `plc` - Policy.

#### getPolicy

    public StreamerIndexPolicy getPolicy()

Gets event indexing policy, which defines how events are tracked within an index.

Specified by:
  `getPolicy` in interface `StreamerIndexProvider<E,K,V>`
Returns:
  index policy.

#### setUnique

    public void setUnique(boolean unique)

Sets unique flag.

Parameters:
  `unique` - `True` for unique index.

#### isUnique

    public boolean isUnique()

Checks whether this index is unique or not. If it is, equal events are not allowed, which means that if a newly-added event is found to be equal to one of the already present events (`Object.equals(Object)` returns `true`), an exception is thrown.

Specified by:
  `isUnique` in interface `StreamerIndexProvider<E,K,V>`
Returns:
  `True` for unique index.

#### setUpdater

    public void setUpdater(StreamerIndexUpdater<E,K,V> updater)

Sets index updater.

Parameters:
  `updater` - Updater.

#### getUpdater

    public StreamerIndexUpdater<E,K,V> getUpdater()

Gets index updater.

Returns:
  Updater.

#### dispose

    public void dispose()

Disposes the index.

Specified by:
  `dispose` in interface `StreamerIndexProvider<E,K,V>`

#### add

    public void add(StreamerIndexUpdateSync sync,
           E evt)

Add event to the index.

Specified by:
  `add` in interface `StreamerIndexProvider<E,K,V>`
Parameters:
  `sync` - Sync.
  `evt` - Event.

#### remove

    public void remove(StreamerIndexUpdateSync sync,
              E evt)

Remove event from the index.

Specified by:
  `remove` in interface `StreamerIndexProvider<E,K,V>`
Parameters:
  `sync` - Sync.
  `evt` - Event.

#### endUpdate

    public void endUpdate(StreamerIndexUpdateSync sync,
                 E evt,
                 boolean rollback,
                 boolean rmv)

Finalizes an update operation.

Specified by:
  `endUpdate` in interface `StreamerIndexProvider<E,K,V>`
Parameters:
  `sync` - Index update synchronizer.
  `evt` - Updated event.
  `rollback` - Rollback flag. If `true`, a rollback was made.
  `rmv` - Remove flag. If `true`, the event was removed from index.

#### endUpdate0

    protected abstract void endUpdate0(StreamerIndexUpdateSync sync,
                  E evt,
                  K key,
                  boolean rollback)

Parameters:
  `sync` - Sync.
  `evt` - Event.
  `key` - Key.
  `rollback` - Rollback flag.

#### reset

    public void reset()

Resets the index to an initial empty state.

Specified by:
  `reset` in interface `StreamerIndexProvider<E,K,V>`

#### index

    public StreamerIndex<E,K,V> index()

Gets user view for this index. This view is a snapshot of a current index state. Once returned, it does not change over time.

Specified by:
  `index` in interface `StreamerIndexProvider<E,K,V>`
Returns:
  User view for this index.

#### reset0

    protected abstract void reset0()

Called on reset.

#### index0

    protected abstract StreamerIndex<E,K,V> index0()

Returns:
  Index

#### readLock

    protected void readLock()

#### readUnlock

    protected void readUnlock()

#### writeLock

    protected void writeLock()

#### writeUnlock

    protected void writeUnlock()

#### eventsCount

    protected int eventsCount()

Returns:
  Events count,

#### add

    protected abstract void add(E evt,
           K key,
           StreamerIndexUpdateSync sync)
                         throws IgniteException

Add event to the index.

Parameters:
  `evt` - Event.
  `key` - key.
  `sync` - Sync.
Throws:
  `IgniteException` - If failed.

#### remove

    protected abstract void remove(E evt,
              K key,
              StreamerIndexUpdateSync sync)
                            throws IgniteException

Remove event from the index.

Parameters:
  `evt` - Event.
  `key` - Key.
  `sync` - Sync.
Throws:
  `IgniteException` - If failed.

#### lockIndexKey

    protected void lockIndexKey(StreamerIndexProviderAdapter.IndexKey<V> key,
                    StreamerIndexUpdateSync sync)
                         throws IgniteException

Lock updates on particular key.

Parameters:
  `key` - Key.
  `sync` - Sync.
Throws:
  `IgniteException` - If failed.

#### unlockIndexKey

    protected void unlockIndexKey(StreamerIndexProviderAdapter.IndexKey<V> key,
                      StreamerIndexUpdateSync sync)

Unlock updates on particular key.

Parameters:
  `key` - Key.
  `sync` - Sync.

#### newEntry

    protected StreamerIndexProviderAdapter.Entry<E,K,V> newEntry(K key,
                                                     V val,
                                                     @Nullable
                                                     StreamerIndexProviderAdapter.IndexKey<V> idxKey,
                                                     E evt)

Parameters:
  `key` - Key,
  `val` - Value.
  `idxKey` - Index key.
  `evt` - Event.
Returns:
  Entry.

#### addEvent

    protected StreamerIndexProviderAdapter.Entry<E,K,V> addEvent(StreamerIndexEntry<E,K,V> oldEntry,
                                                     K key,
                                                     V val,
                                                     @Nullable
                                                     StreamerIndexProviderAdapter.IndexKey<V> idxKey,
                                                     E evt)

Parameters:
  `oldEntry` - Old entry.
  `key` - Key,
  `val` - Value.
  `idxKey` - Index key.
  `evt` - Event.
Returns:
  Entry.

#### removeEvent

    protected StreamerIndexProviderAdapter.Entry<E,K,V> removeEvent(StreamerIndexEntry<E,K,V> oldEntry,
                                                        K key,
                                                        V val,
                                                        @Nullable
                                                        StreamerIndexProviderAdapter.IndexKey<V> idxKey,
                                                        E evt)

Parameters:
  `oldEntry` - Old entry.
  `key` - Key,
  `val` - Value.
  `idxKey` - Index key.
  `evt` - Event.
Returns:
  Entry.

#### addToCollection

    protected static <E> Collection<E> addToCollection(@Nullable
                                    Collection<E> col,
                                    E evt)

Parameters:
  `col` - Collection.
  `evt` - Event.
Returns:
  Cloned collection.

#### addToMap

    protected static <E> Map<E,Integer> addToMap(@Nullable
                              Map<E,Integer> map,
                              E evt)

Parameters:
  `map` - Collection.
  `evt` - Event.
Returns:
  Cloned map.

#### removeFromCollection

    @Nullable
    protected static <E> Collection<E> removeFromCollection(@Nullable
                                                  Collection<E> col,
                                                  E evt)

Parameters:
  `col` - Collection.
  `evt` - Event.
Returns:
  Cloned collection.

#### removeFromMap

    @Nullable
    protected static <E> Map<E,Integer> removeFromMap(@Nullable
                                            Map<E,Integer> map,
                                            E evt)

Parameters:
  `map` - Collection.
  `evt` - Event.
Returns:
  Cloned map.

#### name

    public String name()

Index name.

Specified by:
  `name` in interface `StreamerIndexProviderMBean`
Returns:
  Index name.

#### updaterClass

    public String updaterClass()

Gets index updater class name.

Specified by:
  `updaterClass` in interface `StreamerIndexProviderMBean`
Returns:
  Index updater class.

#### unique

    public boolean unique()

Gets index unique flag.

Specified by:
  `unique` in interface `StreamerIndexProviderMBean`
Returns:
  Index unique flag.

#### policy

    public StreamerIndexPolicy policy()

Gets index policy.

Specified by:
  `policy` in interface `StreamerIndexProviderMBean`
Returns:
  Index policy.

#### size

    public int size()

Gets current index size.

Specified by:
  `size` in interface `StreamerIndexProviderMBean`
Returns:
  Current index size.

#### toString

    public String toString()

Overrides:
  `toString` in class `Object`

#### trieGet

    protected static <K,V> V trieGet(K key,
                  TrieMap<K,V> map)

Utility method to safely get values from TrieMap. See: https://github.com/romix/java-concurrent-hash-trie-map/issues/4

Parameters:
  `key` - Key.
  `map` - Trie map.
Returns:
  Value from map.

2015 Copyright © Apache Software Foundation

Follow @ApacheIgnite

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