SegBufferReader Class Reference

SegBufferReader is a helper class that reads data that has previously been buffered, and writes the data to its output stream. More...

#include <SegBufferReader.h>

Inheritance diagram for SegBufferReader:

ClosableObject List of all members.

Public Member Functions

 SegBufferReader (SharedExecStreamBufAccessor &pOutAccessorInit, SegmentAccessor const &bufferSegmentAccessorInit, PageId firstPageIdInit)
 Creates a new SegBufferReader object.
void open (bool destroy)
 Initiates reads of the buffered data, beginning at the first page.
ExecStreamResult read ()
 Reads the buffered data.
virtual void closeImpl ()
 Must be implemented by derived class to release any resources.
bool isClosed () const
 
Returns:
whether the object has been closed

void close ()
 Closes this object, releasing any unallocated resources.

Static Public Member Functions

static SharedSegBufferReader newSegBufferReader (SharedExecStreamBufAccessor &pOutAccessor, SegmentAccessor const &bufferSegmentAccessor, PageId firstPageId)
 Creates a shared pointer to a new SegBufferReader object.

Protected Attributes

bool needsClose

Private Attributes

SharedExecStreamBufAccessor pOutAccessor
SegmentAccessor bufferSegmentAccessor
SharedSegInputStream pByteInputStream
PageId firstPageId
SegStreamPosition restartPos
uint cbLastRead

Detailed Description

SegBufferReader is a helper class that reads data that has previously been buffered, and writes the data to its output stream.

Author:
John V. Sichi
Version:
Id
//open/dev/fennel/exec/SegBufferReader.h#2

Definition at line 41 of file SegBufferReader.h.


Constructor & Destructor Documentation

SegBufferReader::SegBufferReader ( SharedExecStreamBufAccessor pOutAccessorInit,
SegmentAccessor const &  bufferSegmentAccessorInit,
PageId  firstPageIdInit 
) [explicit]

Creates a new SegBufferReader object.

Parameters:
pOutAccessorInit the output stream that will be written
bufferSegmentAccessorInit the segment accessor that will be used to read the buffered data
firstPageIdInit the pageId of the first buffer page

Definition at line 41 of file SegBufferReader.cpp.

Referenced by newSegBufferReader().

00045     : pOutAccessor(pOutAccessorInit),
00046         bufferSegmentAccessor(bufferSegmentAccessorInit),
00047         firstPageId(firstPageIdInit)
00048 {
00049 }


Member Function Documentation

SharedSegBufferReader SegBufferReader::newSegBufferReader ( SharedExecStreamBufAccessor pOutAccessor,
SegmentAccessor const &  bufferSegmentAccessor,
PageId  firstPageId 
) [static]

Creates a shared pointer to a new SegBufferReader object.

Parameters:
pOutAccessor the output stream that will be written
bufferSegmentAccessor the segment accessor that will be used to read the buffered data
firstPageId the pageId of the first buffer page

Definition at line 31 of file SegBufferReader.cpp.

References bufferSegmentAccessor, and SegBufferReader().

Referenced by SegBufferReaderExecStream::execute(), and SegBufferExecStream::openBufferForRead().

void SegBufferReader::open ( bool  destroy  ) 

Initiates reads of the buffered data, beginning at the first page.

Parameters:
destroy if true, destroy the buffered pages after they've been read

Definition at line 51 of file SegBufferReader.cpp.

References bufferSegmentAccessor, cbLastRead, firstPageId, SegInputStream::newSegInputStream(), pByteInputStream, and restartPos.

00052 {
00053     cbLastRead = 0;
00054     // If previously opened, restart from the beginning
00055     if (pByteInputStream) {
00056         pByteInputStream->endPrefetch();
00057         pByteInputStream->seekSegPos(restartPos);
00058     } else {
00059         pByteInputStream =
00060             SegInputStream::newSegInputStream(
00061                 bufferSegmentAccessor,
00062                 firstPageId);
00063         pByteInputStream->getSegPos(restartPos);
00064     }
00065     if (destroy) {
00066         pByteInputStream->setDeallocate(true);
00067     }
00068     pByteInputStream->startPrefetch();
00069 }

ExecStreamResult SegBufferReader::read (  ) 

Reads the buffered data.

Returns:
the execution stream result code indicating the state of the data written to the output stream; EXECRC_BUF_OVERFLOW if data was successfully written or EXECRC_EOS if all data has been written

Definition at line 71 of file SegBufferReader.cpp.

References cbLastRead, EXECBUF_EMPTY, EXECBUF_EOS, EXECBUF_NONEMPTY, EXECBUF_OVERFLOW, EXECBUF_UNDERFLOW, EXECRC_BUF_OVERFLOW, EXECRC_EOS, pByteInputStream, and pOutAccessor.

00072 {
00073     switch (pOutAccessor->getState()) {
00074     case EXECBUF_NONEMPTY:
00075     case EXECBUF_OVERFLOW:
00076         return EXECRC_BUF_OVERFLOW;
00077     case EXECBUF_UNDERFLOW:
00078     case EXECBUF_EMPTY:
00079         break;
00080     case EXECBUF_EOS:
00081         return EXECRC_EOS;
00082     default:
00083         permAssert(false);
00084     }
00085 
00086     pByteInputStream->consumeReadPointer(cbLastRead);
00087     PConstBuffer pBuffer = pByteInputStream->getReadPointer(1,&cbLastRead);
00088     if (!pBuffer) {
00089         pOutAccessor->markEOS();
00090         return EXECRC_EOS;
00091     }
00092     pOutAccessor->provideBufferForConsumption(
00093         pBuffer,
00094         pBuffer + cbLastRead);
00095     return EXECRC_BUF_OVERFLOW;
00096 }

void SegBufferReader::closeImpl (  )  [virtual]

Must be implemented by derived class to release any resources.

Implements ClosableObject.

Definition at line 98 of file SegBufferReader.cpp.

References pByteInputStream.

00099 {
00100     pByteInputStream.reset();
00101 }

bool ClosableObject::isClosed (  )  const [inline, inherited]

Returns:
whether the object has been closed

Definition at line 58 of file ClosableObject.h.

00059     {
00060         return !needsClose;
00061     }

void ClosableObject::close (  )  [inherited]

Closes this object, releasing any unallocated resources.

Reimplemented in CollectExecStream, CorrelationJoinExecStream, LcsClusterAppendExecStream, and LcsClusterReplaceExecStream.

Definition at line 39 of file ClosableObject.cpp.

References ClosableObject::closeImpl(), and ClosableObject::needsClose.

Referenced by CacheImpl< PageT, VictimPolicyT >::allocatePages(), LcsRowScanBaseExecStream::closeImpl(), ExecStreamGraphImpl::closeImpl(), FlatFileBuffer::open(), ClosableObjectDestructor::operator()(), and Segment::~Segment().

00040 {
00041     if (!needsClose) {
00042         return;
00043     }
00044     needsClose = false;
00045     closeImpl();
00046 }


Member Data Documentation

SharedExecStreamBufAccessor SegBufferReader::pOutAccessor [private]

Definition at line 44 of file SegBufferReader.h.

Referenced by read().

SegmentAccessor SegBufferReader::bufferSegmentAccessor [private]

Definition at line 45 of file SegBufferReader.h.

Referenced by newSegBufferReader(), and open().

SharedSegInputStream SegBufferReader::pByteInputStream [private]

Definition at line 46 of file SegBufferReader.h.

Referenced by closeImpl(), open(), and read().

PageId SegBufferReader::firstPageId [private]

Definition at line 47 of file SegBufferReader.h.

Referenced by open().

SegStreamPosition SegBufferReader::restartPos [private]

Definition at line 48 of file SegBufferReader.h.

Referenced by open().

uint SegBufferReader::cbLastRead [private]

Definition at line 49 of file SegBufferReader.h.

Referenced by open(), and read().

bool ClosableObject::needsClose [protected, inherited]

Definition at line 44 of file ClosableObject.h.

Referenced by SegStreamAllocation::beginWrite(), ExecStreamGraphImpl::clear(), ClosableObject::ClosableObject(), ClosableObject::close(), FlatFileBuffer::open(), ExecStreamGraphImpl::open(), ExecStream::open(), and ClosableObject::~ClosableObject().


The documentation for this class was generated from the following files:
Generated on Mon Jun 22 04:00:45 2009 for Fennel by  doxygen 1.5.1