net.sf.farrago.runtime
Class FennelAbstractTupleIter

java.lang.Object
  extended by org.eigenbase.runtime.AbstractTupleIter
      extended by net.sf.farrago.runtime.FennelAbstractTupleIter
All Implemented Interfaces:
TupleIter, ClosableAllocation
Direct Known Subclasses:
FennelPipeTupleIter, FennelTransformTupleIter, FennelTupleIter

public abstract class FennelAbstractTupleIter
extends AbstractTupleIter

FennelAbstractTupleIter implements the TupleIter interface by unmarshalling Fennel tuples from a buffer.

FennelAbstractTupleIter only deals with raw byte buffers; it is the responsibility of the contained FennelTupleReader object to unmarshal individual fields.

Neither does it actually populate the source buffer. This is the responsibility of the populateBuffer() method, which must be implemented by the subclass. The subclass may optionally override the requestData() method to tell the producer that it is safe to start producing more data.

Version:
$Id: //open/dev/farrago/src/net/sf/farrago/runtime/FennelAbstractTupleIter.java#8 $
Author:
John V. Sichi, Stephan Zuercher

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.eigenbase.runtime.TupleIter
TupleIter.NoDataReason, TupleIter.TimeoutException
 
Field Summary
protected  byte[] bufferAsArray
           
protected  ByteBuffer byteBuffer
           
private  boolean endOfData
           
private static FennelTupleAccessor tupleAligner
          Singleton helper for aligning tuple buffers correctly.
protected  FennelTupleReader tupleReader
           
 
Fields inherited from interface org.eigenbase.runtime.TupleIter
EMPTY_ITERATOR
 
Constructor Summary
FennelAbstractTupleIter(FennelTupleReader tupleReader)
          Creates a new FennelAbstractTupleIter object.
 
Method Summary
 Object fetchNext()
          Returns the next element in the iteration.
protected  String getStatus(String prefix)
          For subclasses that trace, returns a terse description of the status.
protected abstract  int populateBuffer()
          Populates the buffer with a new batch of data, and returns the size in bytes.
protected  void requestData()
          This method is called when the contents of the buffer have been consumed.
 void restart()
          Restarts this iterator, so that a subsequent call to TupleIter.fetchNext() returns the first element in the collection being iterated.
protected  void traceNext(Object val)
           
private  Object unmarshal()
           
 
Methods inherited from class org.eigenbase.runtime.AbstractTupleIter
setTimeout
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.eigenbase.util.ClosableAllocation
closeAllocation
 

Field Detail

tupleAligner

private static FennelTupleAccessor tupleAligner
Singleton helper for aligning tuple buffers correctly.


tupleReader

protected final FennelTupleReader tupleReader

byteBuffer

protected ByteBuffer byteBuffer

bufferAsArray

protected byte[] bufferAsArray

endOfData

private boolean endOfData
Constructor Detail

FennelAbstractTupleIter

public FennelAbstractTupleIter(FennelTupleReader tupleReader)
Creates a new FennelAbstractTupleIter object.

Parameters:
tupleReader - FennelTupleReader to use to interpret Fennel data
Method Detail

getStatus

protected String getStatus(String prefix)
For subclasses that trace, returns a terse description of the status.

Parameters:
prefix - prepended to the results

restart

public void restart()
Description copied from interface: TupleIter
Restarts this iterator, so that a subsequent call to TupleIter.fetchNext() returns the first element in the collection being iterated.

Specified by:
restart in interface TupleIter
Overrides:
restart in class AbstractTupleIter

fetchNext

public Object fetchNext()
Description copied from interface: TupleIter
Returns the next element in the iteration. If there is no next value, it returns a value from the TupleIter.NoDataReason enumeration indicating why no data was returned.

If this method returns TupleIter.NoDataReason.END_OF_DATA, no further data will be returned by this iterator unless TupleIter.restart() is called.

If this method returns TupleIter.NoDataReason.UNDERFLOW, no data is currently available, but may be come available in the future. It is possible for consecutive calls to return UNDERFLOW and then END_OF_DATA.

The object returned by this method may be re-used for each subsequent call to fetchNext(). In other words, callers must either make certain that the returned value is no longer needed or is copied before any subsequent calls to fetchNext().

Returns:
the next element in the iteration, or an instance of TupleIter.NoDataReason.

unmarshal

private Object unmarshal()

traceNext

protected void traceNext(Object val)

populateBuffer

protected abstract int populateBuffer()
Populates the buffer with a new batch of data, and returns the size in bytes. The buffer position is set to the start. The call may block until the buffer is filled or it may return an indication that there is no data currently available. A subclass can implement this to fill the buffer itself, or it can work by allowing an outside object to fill the buffer.

Returns:
The number of bytes now in the buffer. 0 means end of stream. Less than 0 means no data currently available.

requestData

protected void requestData()
This method is called when the contents of the buffer have been consumed. A subclass may use this method to tell the producer that it can start producing. The default implementation does nothing. The method should not block.