com.bigdata.relation.accesspath
Class AbstractUnsynchronizedArrayBuffer<E>

java.lang.Object
  extended by com.bigdata.relation.accesspath.AbstractUnsynchronizedArrayBuffer<E>
All Implemented Interfaces:
IBuffer<E>
Direct Known Subclasses:
MapBindingSetsOverShardsBuffer, UnsynchronizedArrayBuffer, UnsynchronizedUnboundedChunkBuffer, UnsyncLocalOutputBuffer, UnsyncLocalOutputBuffer

public abstract class AbstractUnsynchronizedArrayBuffer<E>
extends Object
implements IBuffer<E>

An abstract implementation of an unsynchronized buffer backed by a fixed capacity array.

This implementation is NOT thread-safe.

Version:
$Id: AbstractUnsynchronizedArrayBuffer.java 6130 2012-03-15 10:31:25Z thompsonbry $
Author:
Bryan Thompson

Constructor Summary
AbstractUnsynchronizedArrayBuffer(int capacity, Class<? extends E> cls)
           
AbstractUnsynchronizedArrayBuffer(int capacity, Class<? extends E> cls, IElementFilter<E> filter)
           
 
Method Summary
protected  boolean accept(E e)
          Applies the optional filter to restrict elements allowed into the buffer.
 void add(E e)
          Not thread-safe.
 boolean add2(E e)
          Adds an element to the buffer.
 long flush()
          Flush the buffer and return the #of elements written on the backing IRelation since the counter was last IBuffer.reset() (the mutationCount).
protected abstract  void handleChunk(E[] chunk)
          Dispatch a chunk.
 boolean isEmpty()
          If size() reports zero(0).
protected  void overflow()
          Adds all references in the internal buffer to the target buffer, resets the #of elements in the internal buffer to ZERO (0), and clears the internal array - it will be reallocated again on demand.
 void reset()
          Reset the state of the buffer, including the counter whose value is reported by IBuffer.flush().
 int size()
          The exact #of elements currently in the buffer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractUnsynchronizedArrayBuffer

public AbstractUnsynchronizedArrayBuffer(int capacity,
                                         Class<? extends E> cls)
Parameters:
capacity - The capacity of the backing buffer.
cls - The component type for the backing array.

AbstractUnsynchronizedArrayBuffer

public AbstractUnsynchronizedArrayBuffer(int capacity,
                                         Class<? extends E> cls,
                                         IElementFilter<E> filter)
Parameters:
capacity - The capacity of the backing buffer.
cls - The component type for the backing array.
filter - Filter to keep elements out of the buffer (optional).
Method Detail

isEmpty

public final boolean isEmpty()
If size() reports zero(0).

Specified by:
isEmpty in interface IBuffer<E>

size

public final int size()
The exact #of elements currently in the buffer.

Specified by:
size in interface IBuffer<E>

accept

protected boolean accept(E e)
Applies the optional filter to restrict elements allowed into the buffer. When the optional filter was NOT specified all elements are allowed into the buffer.

Parameters:
e - A element.
Returns:
true if the element is allowed into the buffer.

add

public final void add(E e)
Not thread-safe.

Specified by:
add in interface IBuffer<E>
Parameters:
e - The element

add2

public boolean add2(E e)
Adds an element to the buffer. Not thread-safe.

Parameters:
e - An element.
Returns:
true iff adding the element caused the buffer to overflow()

overflow

protected void overflow()
Adds all references in the internal buffer to the target buffer, resets the #of elements in the internal buffer to ZERO (0), and clears the internal array - it will be reallocated again on demand.


handleChunk

protected abstract void handleChunk(E[] chunk)
Dispatch a chunk.

Parameters:
chunk - A chunk.

flush

public long flush()
Description copied from interface: IBuffer
Flush the buffer and return the #of elements written on the backing IRelation since the counter was last IBuffer.reset() (the mutationCount).

Note: If the buffer does not write on an IRelation then it SHOULD return ZERO(0).

Specified by:
flush in interface IBuffer<E>
Returns:
The #of elements written on the backing IRelation. See IMutableRelation

reset

public void reset()
Description copied from interface: IBuffer
Reset the state of the buffer, including the counter whose value is reported by IBuffer.flush(). Any data in the buffer will be discarded.

Specified by:
reset in interface IBuffer<E>


Copyright © 2006-2011 SYSTAP, LLC. All Rights Reserved.