org.apache.ignite.streamer

## Interface StreamerWindow<E>

All Superinterfaces:
  Iterable<E>

All Known Implementing Classes:
  StreamerBoundedSizeBatchWindow, StreamerBoundedSizeSortedWindow, StreamerBoundedSizeWindow, StreamerBoundedTimeBatchWindow, StreamerBoundedTimeWindow, StreamerUnboundedWindow, StreamerWindowAdapter

    public interface StreamerWindow<E>
    extends Iterable<E>

Streamer rolling window. Rolling windows allow new event to come in, as well as automatically evicting obsolete events on the other side. Windows allow to query into specific time-frame or specific sample size of the events. With windows, you can answer questions like "What are my top 10 best selling products over last 24 hours?", or "Who are my top 10 users out of last 1,000,000 users who logged in?"

Ignite comes with following rolling windows implementations out of the box:

- `StreamerUnboundedWindow`
- `StreamerBoundedSizeWindow`
- `StreamerBoundedSizeBatchWindow`
- `StreamerBoundedSizeSortedWindow`
- `StreamerBoundedTimeWindow`
- `StreamerBoundedTimeBatchWindow`

Streamer window is configured via `StreamerConfiguration.getWindows()` method.

### Method Summary

Methods
`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.
`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.
`boolean` `enqueueAll(Collection<E> evts)` Adds all events to window.
`int` `evictionQueueSize()` Gets number of entries available for eviction.
`<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.
`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.
`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.
`void` `reset()` Resets window.
`int` `size()` Gets number of events currently stored in window.
`Collection<E>` `snapshot(boolean includeIvicted)` Create window snapshot.

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

`iterator`

### Method Detail

#### name

    String name()

Gets window name.

Returns:
  Window name.

#### index

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

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

Type Parameters:
  `K` - Type of the index key.
  `V` - Type of the index value.
Returns:
  Index with default name.

#### index

    <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.

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 `index()`.
Returns:
  Index with a given name.

#### indexes

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

Gets all indexes configured for this window.

Returns:
  All indexes configured for this window or empty collection, if no indexes were configured.

#### reset

    void reset()

Resets window. Usually will clear all events from window.

#### size

    int size()

Gets number of events currently stored in window.

Returns:
  Current size of the window.

#### evictionQueueSize

    int evictionQueueSize()

Gets number of entries available for eviction.

Returns:
  Number of entries available for eviction.

#### enqueue

    boolean enqueue(E evt)
                    throws IgniteException

Adds single event to window.

Parameters:
  `evt` - Event to add.
Returns:
  `True` if event was added.
Throws:
  `IgniteException` - If index update failed.

#### enqueue

    boolean enqueue(E... evts)
                    throws IgniteException

Adds events to window.

Parameters:
  `evts` - Events to add.
Returns:
  ``
Throws:
  `IgniteException` - If index update failed.

#### enqueueAll

    boolean enqueueAll(Collection<E> evts)
                       throws IgniteException

Adds all events to window.

Parameters:
  `evts` - Collection of events to add.
Returns:
  `True` if all events were added, `false` if at least 1 event was skipped.
Throws:
  `IgniteException` - If index update failed.

#### dequeue

    @Nullable
    E dequeue()
              throws IgniteException

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

Returns:
  Dequeued element.
Throws:
  `IgniteException` - If index update failed.

#### dequeue

    Collection<E> dequeue(int cnt)
                          throws IgniteException

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

Parameters:
  `cnt` - Count to dequeue.
Returns:
  Collection of dequeued elements.
Throws:
  `IgniteException` - If index update failed.

#### dequeueAll

    Collection<E> dequeueAll()
                             throws IgniteException

Dequeues all elements from window.

Returns:
  Collection of dequeued elements.
Throws:
  `IgniteException` - If index update failed.

#### pollEvicted

    @Nullable
    E pollEvicted()
                  throws IgniteException

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

Returns:
  Polls and returns next evicted event or `null` if eviction queue is empty or if window does not support eviction.
Throws:
  `IgniteException` - If index update failed.

#### pollEvicted

    Collection<E> pollEvicted(int cnt)
                              throws IgniteException

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

Parameters:
  `cnt` - Number of elements to evict.
Returns:
  Collection of evicted elements.
Throws:
  `IgniteException` - If index update failed.

#### pollEvictedBatch

    Collection<E> pollEvictedBatch()
                                   throws IgniteException

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:
  Next evicted batch.
Throws:
  `IgniteException` - If index update failed.

#### pollEvictedAll

    Collection<E> pollEvictedAll()
                                 throws IgniteException

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

Returns:
  Collection of evicted elements.
Throws:
  `IgniteException` - If index update failed.

#### clearEvicted

    void clearEvicted()
                      throws IgniteException

Clears all evicted entries.

Throws:
  `IgniteException` - If index update failed.

#### snapshot

    Collection<E> snapshot(boolean includeIvicted)

Create window snapshot. Evicted entries are not included.

Parameters:
  `includeIvicted` - Whether to include evicted entries or not.
Returns:
  Window snapshot.

2015 Copyright © Apache Software Foundation

Follow @ApacheIgnite

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