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

java.lang.Object
  extended by com.bigdata.relation.accesspath.AbstractArrayBuffer<E>
All Implemented Interfaces:
IBuffer<E>
Direct Known Subclasses:
AbstractElementBuffer, AbstractSolutionBuffer

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

A thread-safe buffer backed by a fixed capacity array. Concrete implementations must empty the buffer in flush(int, Object[]).

Version:
$Id: AbstractArrayBuffer.java 2265 2009-10-26 12:51:06Z thompsonbry $
Author:
Bryan Thompson

Field Summary
protected  E[] buffer
           
protected  int capacity
          The capacity of the backing buffer.
protected  Class cls
          The component type of the backing byte, used when a new instance is allocated.
protected static boolean DEBUG
           
protected  IElementFilter<E> filter
          An optional filter for keeping elements out of the buffer.
protected static boolean INFO
           
protected static org.apache.log4j.Logger log
           
protected  int size
           
 
Constructor Summary
protected AbstractArrayBuffer(int capacity, Class cls, IElementFilter<E> filter)
           
 
Method Summary
protected  boolean accept(E e)
          Filters elements allowed into the buffer.
 void add(E e)
          Add 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  long flush(int n, E[] a)
          This method is automatically invoked if the buffer is flushed and it is non-empty.
 boolean isEmpty()
          If size() reports zero(0).
 void reset()
          Reset the state of the buffer, including the counter whose value is reported by IBuffer.flush().
 int size()
          The approximate #of elements in the buffer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static final org.apache.log4j.Logger log

INFO

protected static final boolean INFO

DEBUG

protected static final boolean DEBUG

capacity

protected final int capacity
The capacity of the backing buffer.


cls

protected final Class cls
The component type of the backing byte, used when a new instance is allocated.


filter

protected final IElementFilter<E> filter
An optional filter for keeping elements out of the buffer.


size

protected int size

buffer

protected E[] buffer
Constructor Detail

AbstractArrayBuffer

protected AbstractArrayBuffer(int capacity,
                              Class cls,
                              IElementFilter<E> filter)
Parameters:
capacity - The capacity of the backing buffer.
cls - Array instances of this component type will be allocated.
filter - An optional filter for keeping elements out of the buffer.
Method Detail

isEmpty

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

Specified by:
isEmpty in interface IBuffer<E>

size

public int size()
The approximate #of elements in the buffer.

Specified by:
size in interface IBuffer<E>

accept

protected boolean accept(E e)
Filters elements allowed into the buffer.

Parameters:
e - Some element.
Returns:
true iff the buffer accepts the element.

add

public void add(E e)
Description copied from interface: IBuffer
Add an element to the buffer.

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

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>

flush

protected abstract long flush(int n,
                              E[] a)
This method is automatically invoked if the buffer is flushed and it is non-empty. The implementation is required to dispose of the contents of the buffer. The caller is already synchronized on this so no further synchronization is necessary. It is assumed that the contents of the buffer have been safely disposed of when this method returns.

Parameters:
n - The #of elements in the array.
a - The array of elements.
Returns:
The #of elements that were modified in the backing relation when the buffer was flushed (unlike flush(), this is not a cumulative counter, but the #of modified elements in the relation for this operation only).


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