org.apache.ignite.internal.util

## Class GridCircularBuffer<T>

- java.lang.Object
- - org.apache.ignite.internal.util.GridCircularBuffer<T>

    public class GridCircularBuffer<T>
    extends Object

This class implements a circular buffer for efficient data exchange.

### Constructor Summary

Constructors
Constructor and Description
`GridCircularBuffer(int size)`

### Method Summary

Methods
`T` `add(T t)`
`T` `add(T t, IgniteInClosureX<T> c)`
`void` `forEach(IgniteInClosure<T> c)` Executes given closure for every item in circular buffer.
`T2<T,Long>` `get(long idx)`
`Collection<T>` `items()`
`String` `toString()`

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

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

### Constructor Detail

#### GridCircularBuffer

    public GridCircularBuffer(int size)

Parameters:
  `size` - Size.

### Method Detail

#### items

    public Collection<T> items()

Returns:
  Items currently in buffer.

#### forEach

    public void forEach(IgniteInClosure<T> c)

Executes given closure for every item in circular buffer.

Parameters:
  `c` - Closure to execute.

#### get

    public T2<T,Long> get(long idx)

Parameters:
  `idx` - Index.
Returns:
  Item data and index.

#### add

    @Nullable
    public T add(T t)
          throws InterruptedException

Parameters:
  `t` - Item to add.
Returns:
  Evicted object or `null` if nothing evicted.
Throws:
  `InterruptedException` - If interrupted.

#### add

    @Nullable
    public T add(T t,
                 @Nullable
                 IgniteInClosureX<T> c)
          throws InterruptedException,
                 IgniteCheckedException

Parameters:
  `t` - Item to add.
  `c` - Closure to by applied on evicted object before eviction.
Returns:
  Evicted object or `null` if nothing evicted.
Throws:
  `InterruptedException` - If interrupted.
  `IgniteCheckedException` - If closure throws exception.

#### toString

    public String toString()

Overrides:
  `toString` in class `Object`

2015 Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Fabric | : ver. 1.2.0-incubating
Release Date | : June 16 2015