#include <SegBufferWriter.h>
Inheritance diagram for SegBufferWriter:
Public Member Functions | |
SegBufferWriter (SharedExecStreamBufAccessor &pInAccessorInit, SegmentAccessor const &bufferSegmentAccessorInit, bool destroyOnCloseInit) | |
Creates a new SegBufferWriter object. | |
ExecStreamResult | write () |
Reads data from the input stream and buffers it. | |
PageId | getFirstPageId () |
virtual void | closeImpl () |
Must be implemented by derived class to release any resources. | |
bool | isClosed () const |
| |
void | close () |
Closes this object, releasing any unallocated resources. | |
Static Public Member Functions | |
static SharedSegBufferWriter | newSegBufferWriter (SharedExecStreamBufAccessor &pInAccessor, SegmentAccessor const &bufferSegmentAccessor, bool destroyOnClose) |
Creates a shared pointer to a new SegBufferWriter object. | |
Protected Attributes | |
bool | needsClose |
Private Attributes | |
SharedExecStreamBufAccessor | pInAccessor |
SegmentAccessor | bufferSegmentAccessor |
SharedSegOutputStream | pByteOutputStream |
PageId | firstPageId |
bool | destroyOnClose |
True if the buffer pages written should be destroyed on close. |
Definition at line 41 of file SegBufferWriter.h.
SegBufferWriter::SegBufferWriter | ( | SharedExecStreamBufAccessor & | pInAccessorInit, | |
SegmentAccessor const & | bufferSegmentAccessorInit, | |||
bool | destroyOnCloseInit | |||
) | [explicit] |
Creates a new SegBufferWriter object.
pInAccessorInit | the input stream that will be read | |
bufferSegmentAccessorInit | the segment accessor that will be used to write the buffered data | |
destroyOnCloseInit | true if the data written needs to be destroyed when the object is destroyed; otherwise, it's the responsibility of the caller to destroy the buffer pages |
Definition at line 42 of file SegBufferWriter.cpp.
References firstPageId, and NULL_PAGE_ID.
Referenced by newSegBufferWriter().
00046 : pInAccessor(pInAccessorInit), 00047 bufferSegmentAccessor(bufferSegmentAccessorInit), 00048 destroyOnClose(destroyOnCloseInit) 00049 { 00050 firstPageId = NULL_PAGE_ID; 00051 }
SharedSegBufferWriter SegBufferWriter::newSegBufferWriter | ( | SharedExecStreamBufAccessor & | pInAccessor, | |
SegmentAccessor const & | bufferSegmentAccessor, | |||
bool | destroyOnClose | |||
) | [static] |
Creates a shared pointer to a new SegBufferWriter object.
pInAccessor | the input stream that will be read | |
bufferSegmentAccessor | the segment accessor that will be used to write the buffered data | |
destroyOnClose | true if the data written needs to be destroyed when the object is destroyed; otherwise, it's the responsibility of the caller to destroy the buffer pages |
Definition at line 32 of file SegBufferWriter.cpp.
References bufferSegmentAccessor, and SegBufferWriter().
Referenced by SegBufferWriterExecStream::execute(), and SegBufferExecStream::execute().
00036 { 00037 return SharedSegBufferWriter( 00038 new SegBufferWriter(pInAccessor, bufferSegmentAccessor, destroyOnClose), 00039 ClosableObjectDestructor()); 00040 }
ExecStreamResult SegBufferWriter::write | ( | ) |
Reads data from the input stream and buffers it.
Definition at line 53 of file SegBufferWriter.cpp.
References bufferSegmentAccessor, EXECBUF_EMPTY, EXECBUF_EOS, EXECBUF_NONEMPTY, EXECBUF_OVERFLOW, EXECBUF_UNDERFLOW, EXECRC_BUF_UNDERFLOW, EXECRC_EOS, firstPageId, SegOutputStream::newSegOutputStream(), pByteOutputStream, and pInAccessor.
00054 { 00055 if (!pByteOutputStream) { 00056 pByteOutputStream = 00057 SegOutputStream::newSegOutputStream(bufferSegmentAccessor); 00058 firstPageId = pByteOutputStream->getFirstPageId(); 00059 } 00060 00061 ExecStreamBufState inState = pInAccessor->getState(); 00062 switch (inState) { 00063 case EXECBUF_NONEMPTY: 00064 case EXECBUF_OVERFLOW: 00065 pByteOutputStream->consumeWritePointer( 00066 pInAccessor->getConsumptionAvailable()); 00067 pByteOutputStream->hardPageBreak(); 00068 pInAccessor->consumeData(pInAccessor->getConsumptionEnd()); 00069 if (pInAccessor->getState() == EXECBUF_EOS) { 00070 return EXECRC_BUF_UNDERFLOW; 00071 } 00072 // else fall through intentionally 00073 case EXECBUF_EMPTY: 00074 { 00075 uint cb; 00076 PBuffer pBuffer = pByteOutputStream->getWritePointer(1,&cb); 00077 pInAccessor->provideBufferForProduction( 00078 pBuffer, 00079 pBuffer + cb, 00080 false); 00081 } 00082 return EXECRC_BUF_UNDERFLOW; 00083 case EXECBUF_UNDERFLOW: 00084 return EXECRC_BUF_UNDERFLOW; 00085 case EXECBUF_EOS: 00086 pByteOutputStream.reset(); 00087 return EXECRC_EOS; 00088 default: 00089 permAssert(false); 00090 } 00091 }
PageId SegBufferWriter::getFirstPageId | ( | ) |
Definition at line 93 of file SegBufferWriter.cpp.
References firstPageId.
00094 { 00095 return firstPageId; 00096 }
void SegBufferWriter::closeImpl | ( | ) | [virtual] |
Must be implemented by derived class to release any resources.
Implements ClosableObject.
Definition at line 98 of file SegBufferWriter.cpp.
References bufferSegmentAccessor, destroyOnClose, firstPageId, SegInputStream::newSegInputStream(), and pByteOutputStream.
00099 { 00100 pByteOutputStream.reset(); 00101 if (destroyOnClose) { 00102 SharedSegInputStream pByteInputStream = 00103 SegInputStream::newSegInputStream( 00104 bufferSegmentAccessor, 00105 firstPageId); 00106 pByteInputStream->setDeallocate(true); 00107 pByteInputStream.reset(); 00108 } 00109 }
bool ClosableObject::isClosed | ( | ) | const [inline, inherited] |
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 }
Definition at line 45 of file SegBufferWriter.h.
Referenced by closeImpl(), newSegBufferWriter(), and write().
PageId SegBufferWriter::firstPageId [private] |
Definition at line 47 of file SegBufferWriter.h.
Referenced by closeImpl(), getFirstPageId(), SegBufferWriter(), and write().
bool SegBufferWriter::destroyOnClose [private] |
True if the buffer pages written should be destroyed on close.
Otherwise, it's the responsibility of the caller to destroy the buffer pages.
Definition at line 54 of file SegBufferWriter.h.
Referenced by closeImpl().
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().