org.apache.ignite.streamer.window

## Class StreamerWindowAdapter<E>

- java.lang.Object
- - org.apache.ignite.streamer.window.StreamerWindowAdapter<E>

All Implemented Interfaces:
  Iterable<E>, LifecycleAware, StreamerWindow<E>, StreamerWindowMBean

Direct Known Subclasses:
  StreamerBoundedSizeBatchWindow, StreamerBoundedSizeSortedWindow, StreamerBoundedSizeWindow, StreamerBoundedTimeBatchWindow, StreamerBoundedTimeWindow, StreamerUnboundedWindow

    public abstract class StreamerWindowAdapter<E>
    extends Object
    implements LifecycleAware, StreamerWindow<E>, StreamerWindowMBean

Streamer window adapter.

### Constructor Summary

Constructors
Constructor and Description
`StreamerWindowAdapter()`

### Method Summary

Methods
`protected abstract void` `checkConfiguration()` Check window configuration.
`void` `clearEvicted()` Clears all evicted entries.
`E` `dequeue()` Dequeues last element from windows.
`Collection<E>` `dequeue(int cnt)` Dequeues up to `cnt` elements from window.
`protected abstract Collection<E>` `dequeue0(int cnt)` Dequeues up to cnt elements from window.
`Collection<E>` `dequeueAll()` Dequeues all elements from window.
`boolean` `enqueue(E... evts)` Adds events to window.
`boolean` `enqueue(E evt)` Adds single event to window.
`protected abstract boolean` `enqueue0(E evt)` Adds event to window.
`boolean` `enqueueAll(Collection<E> evts)` Adds all events to window.
`String` `getClassName()` Gets window class name.
`int` `getEvictionQueueSize()` Gets estimate for window eviction queue size.
`IgnitePredicate<Object>` `getFilter()` Gets optional event filter.
`String` `getName()` Gets window name.
`int` `getSize()` Gets current window size.
`<K,V> StreamerIndex<E,K,V>` `index()` Gets default index, if default index is not configured then `IllegalArgumentException` will be thrown.
`<K,V> StreamerIndex<E,K,V>` `index(String name)` Gets index by name, if not index with such name was configured then `IllegalArgumentException` will be thrown.
`Collection<StreamerIndex<E,?,?>>` `indexes()` Gets all indexes configured for this window.
`StreamerIndexProvider<E,?,?>[]` `indexProviders()` Get array of index providers.
`Iterator<E>` `iterator()`
`protected abstract GridStreamerWindowIterator<E>` `iterator0()` Returns an iterator over a set of elements of type T without check for iteration limit.
`String` `name()` Gets window name.
`E` `pollEvicted()` If window supports eviction, this method will return next evicted element.
`Collection<E>` `pollEvicted(int cnt)` If window supports eviction, this method will return up to `cnt` evicted elements.
`protected abstract Collection<E>` `pollEvicted0(int cnt)` If window supports eviction, this method will return up to cnt evicted elements.
`Collection<E>` `pollEvictedAll()` If window supports eviction, this method will return all available evicted elements.
`Collection<E>` `pollEvictedBatch()` If window supports batch eviction, this method will poll next evicted batch from window.
`protected abstract Collection<E>` `pollEvictedBatch0()` If window supports batch eviction, this method will poll next evicted batch from window.
`void` `reset()` Resets window.
`protected abstract void` `reset0()` Reset routine.
`void` `setFilter(IgnitePredicate<Object> filter)` Sets event filter.
`void` `setIndexes(StreamerIndexProvider<E,?,?>... idxs)` Set indexes.
`void` `setName(String name)` Sets window name.
`Collection<E>` `snapshot(boolean includeEvicted)` Create window snapshot.
`void` `start()` Starts grid component, called on grid start.
`void` `stop()` Stops grid component, called on grid shutdown.
`protected abstract void` `stop0()` Dispose window.
`protected void` `updateIndexes(E evt, boolean rmv)` Update indexes.

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

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

### Methods inherited from interface org.apache.ignite.streamer.StreamerWindow

`evictionQueueSize, size`

### Constructor Detail

#### StreamerWindowAdapter

    public StreamerWindowAdapter()

### Method Detail

#### getClassName

    public String getClassName()

Gets window class name.

Specified by:
  `getClassName` in interface `StreamerWindowMBean`
Returns:
  Window class name.

#### getSize

    public int getSize()

Gets current window size.

Specified by:
  `getSize` in interface `StreamerWindowMBean`
Returns:
  Current window size.

#### getEvictionQueueSize

    public int getEvictionQueueSize()

Gets estimate for window eviction queue size.

Specified by:
  `getEvictionQueueSize` in interface `StreamerWindowMBean`
Returns:
  Eviction queue size estimate.

#### name

    public String name()

Gets window name.

Specified by:
  `name` in interface `StreamerWindow<E>`
Returns:
  Window name.

#### getName

    public String getName()

Gets window name.

Specified by:
  `getName` in interface `StreamerWindowMBean`
Returns:
  Window name.

#### iterator

    public Iterator<E> iterator()

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

#### iterator0

    protected abstract GridStreamerWindowIterator<E> iterator0()

Returns an iterator over a set of elements of type T without check for iteration limit. That is, in case concurrent thread constantly adding new elements to the window we could iterate forever.

Returns:
  Iterator.

#### enqueue

    public boolean enqueue(E evt)

Adds single event to window.

Specified by:
  `enqueue` in interface `StreamerWindow<E>`
Parameters:
  `evt` - Event to add.
Returns:
  `True` if event was added.

#### enqueue

    public boolean enqueue(E... evts)

Adds events to window.

Specified by:
  `enqueue` in interface `StreamerWindow<E>`
Parameters:
  `evts` - Events to add.
Returns:
  ``

#### enqueueAll

    public boolean enqueueAll(Collection<E> evts)

Adds all events to window.

Specified by:
  `enqueueAll` in interface `StreamerWindow<E>`
Parameters:
  `evts` - Collection of events to add.
Returns:
  `True` if all events were added, `false` if at least 1 event was skipped.

#### enqueue0

    protected abstract boolean enqueue0(E evt)

Adds event to window.

Parameters:
  `evt` - Event.
Returns:
  `True` if event added.

#### dequeue

    public E dequeue()

Dequeues last element from windows. Will return `null` if window is empty.

Specified by:
  `dequeue` in interface `StreamerWindow<E>`
Returns:
  Dequeued element.

#### dequeueAll

    public Collection<E> dequeueAll()

Dequeues all elements from window.

Specified by:
  `dequeueAll` in interface `StreamerWindow<E>`
Returns:
  Collection of dequeued elements.

#### dequeue

    public Collection<E> dequeue(int cnt)

Dequeues up to `cnt` elements from window. If current window size is less than `cnt`, will dequeue all elements from window.

Specified by:
  `dequeue` in interface `StreamerWindow<E>`
Parameters:
  `cnt` - Count to dequeue.
Returns:
  Collection of dequeued elements.

#### dequeue0

    protected abstract Collection<E> dequeue0(int cnt)

Dequeues up to cnt elements from window. If current window size is less than cnt, will dequeue all elements from window.

Parameters:
  `cnt` - Count.
Returns:
  Dequeued elements.

#### pollEvicted

    public E pollEvicted()

If window supports eviction, this method will return next evicted element.

Specified by:
  `pollEvicted` in interface `StreamerWindow<E>`
Returns:
  Polls and returns next evicted event or `null` if eviction queue is empty or if window does not support eviction.

#### pollEvictedAll

    public Collection<E> pollEvictedAll()

If window supports eviction, this method will return all available evicted elements.

Specified by:
  `pollEvictedAll` in interface `StreamerWindow<E>`
Returns:
  Collection of evicted elements.

#### pollEvicted

    public Collection<E> pollEvicted(int cnt)

If window supports eviction, this method will return up to `cnt` evicted elements.

Specified by:
  `pollEvicted` in interface `StreamerWindow<E>`
Parameters:
  `cnt` - Number of elements to evict.
Returns:
  Collection of evicted elements.

#### pollEvicted0

    protected abstract Collection<E> pollEvicted0(int cnt)

If window supports eviction, this method will return up to cnt evicted elements.

Parameters:
  `cnt` - Count.
Returns:
  Evicted elements.

#### pollEvictedBatch

    public Collection<E> pollEvictedBatch()

If window supports batch eviction, this method will poll next evicted batch from window. If windows does not support batch eviction but supports eviction, will return collection of single last evicted element. If window does not support eviction, will return empty collection.

Specified by:
  `pollEvictedBatch` in interface `StreamerWindow<E>`
Returns:
  Next evicted batch.

#### pollEvictedBatch0

    protected abstract Collection<E> pollEvictedBatch0()

If window supports batch eviction, this method will poll next evicted batch from window. If windows does not support batch eviction but supports eviction, will return collection of single last evicted element. If window does not support eviction, will return empty collection.

Returns:
  Elements from evicted batch.

#### start

    public final void start()

Starts grid component, called on grid start.

Specified by:
  `start` in interface `LifecycleAware`

#### reset

    public final void reset()

Resets window. Usually will clear all events from window.

Specified by:
  `reset` in interface `StreamerWindow<E>`

#### checkConfiguration

    protected abstract void checkConfiguration()
                                        throws IgniteException

Check window configuration.

Throws:
  `IgniteException` - If failed.

#### reset0

    protected abstract void reset0()

Reset routine.

#### stop

    public void stop()

Stops grid component, called on grid shutdown.

Specified by:
  `stop` in interface `LifecycleAware`

#### stop0

    protected abstract void stop0()

Dispose window.

#### snapshot

    public Collection<E> snapshot(boolean includeEvicted)

Create window snapshot. Evicted entries are not included.

Specified by:
  `snapshot` in interface `StreamerWindow<E>`
Parameters:
  `includeEvicted` - Whether to include evicted entries or not.
Returns:
  Window snapshot.

#### setName

    public void setName(String name)

Sets window name.

Parameters:
  `name` - Window name.

#### getFilter

    @Nullable
    public IgnitePredicate<Object> getFilter()

Gets optional event filter.

Returns:
  Optional event filter.

#### setFilter

    public void setFilter(@Nullable
                 IgnitePredicate<Object> filter)

Sets event filter.

Parameters:
  `filter` - Event filter.

#### index

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

Gets default index, if default index is not configured then `IllegalArgumentException` will be thrown.

Specified by:
  `index` in interface `StreamerWindow<E>`
Type Parameters:
  `K` - Type of the index key.
  `V` - Type of the index value.
Returns:
  Index with default name.

#### index

    public <K,V> StreamerIndex<E,K,V> index(@Nullable
                                   String name)

Gets index by name, if not index with such name was configured then `IllegalArgumentException` will be thrown.

Specified by:
  `index` in interface `StreamerWindow<E>`
Type Parameters:
  `K` - Type of the index key.
  `V` - Type of the index value.
Parameters:
  `name` - Name of the index, if `null` then analogous to `StreamerWindow.index()`.
Returns:
  Index with a given name.

#### indexes

    public Collection<StreamerIndex<E,?,?>> indexes()

Gets all indexes configured for this window.

Specified by:
  `indexes` in interface `StreamerWindow<E>`
Returns:
  All indexes configured for this window or empty collection, if no indexes were configured.

#### indexProviders

    public StreamerIndexProvider<E,?,?>[] indexProviders()

Get array of index providers.

Returns:
  Index providers.

#### setIndexes

    public void setIndexes(StreamerIndexProvider<E,?,?>... idxs)
                    throws IllegalArgumentException

Set indexes.

Parameters:
  `idxs` - Indexes.
Throws:
  `IllegalArgumentException` - If some index names are not unique.

#### clearEvicted

    public void clearEvicted()

Clears all evicted entries.

Specified by:
  `clearEvicted` in interface `StreamerWindow<E>`

#### updateIndexes

    protected void updateIndexes(E evt,
                     boolean rmv)
                          throws IgniteException

Update indexes.

Parameters:
  `evt` - Event.
  `rmv` - Remove flag.
Throws:
  `IgniteException` - If index update failed.

2015 Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Fabric | : ver. 1.0.0-RC1
Release Date | : February 17 2015