This class defines the methods needed to store CDRs in the database, in one or more files or a combination of both.
The critical requirement is that all changes must be synchronized; it's all or nothing:
If anything goes wrong while processing an input stream, all modified files must be restored to their original status and all database transactions rolled-back.
In the moment where the database transactions are commited, all output files must reflect the committed status, they must not change afterwards.
When processing an input stream the application is expected to call the member functions in the following order:
beginStream()
Prepare the output for a new input stream.
The application should commit the database transactions after having called the function for all CDR storage instances.
push()
Call this member whenever the application has generated a CDR.
A concrete storage class may buffer the CDR or write to a temporary file.
prepareWrite()
Prepares to write the CDR to after all CDR of the input stream are processed.
writeCdrFiles()
Flushes all buffered CDR to the output file(s).
storeCdrs()
Saves all necessary information to the database and renames all output files to their final name.
endStream()
Call after database transactions from storeCdrs() have been commited.
All backup files are removed.
undoChanges()
Call whenever an error occurs during processing, but not after the transactions from storeCdrs() have been commited.
All modified files are restored to their original status and temporary output is deleted.
Definition at line 123 of file cdrstorage.h.
OSB_LIB::CdrStorage::CdrStorage | ( | ) |
Empty default constructor.
virtual OSB_LIB::CdrStorage::~CdrStorage | ( | ) | [virtual] |
Empty destructor.
OSB_LIB::CdrStorage::CdrStorage | ( | const CdrStorage & | ) | [protected] |
Empty copy constructor.
virtual OsbError OSB_LIB::CdrStorage::beginStream | ( | const OSB_DB::Session & | session, | |
const RecordStreamInfo & | input | |||
) | [pure virtual] |
Prepare to process a new batch of CDR records.
session | Database session to use. | |
input | Information about the input record stream being processed. |
StreamPending | (see StreamPending). |
Implemented in OSB_LIB::FileCdrStorage.
virtual OsbError OSB_LIB::CdrStorage::endStream | ( | ) | [pure virtual] |
Finalize the processing of an input stream.
The function is called after the database transactions from storeCdrs() have been committed.
Derived classes typically remove backup files in this member.
Implemented in OSB_LIB::FileCdrStorage.
CdrStorage& OSB_LIB::CdrStorage::operator= | ( | const CdrStorage & | ) | [protected] |
Empty assignment operator.
virtual OsbError OSB_LIB::CdrStorage::prepareWrite | ( | OSB_DB::Session & | session | ) | [pure virtual] |
Prepare to write the CDRs into files.
session | Database session that can be used to mark the CDR files as being changed. Derived classes must commit their transactions. |
Implemented in OSB_LIB::FileCdrStorage.
Add a CDR to the result set.
cdr | CDR to add. | |
error | Gets error information, it should not contain an error when calling this function. |
OsbException | if a fatal error occurred. |
Implemented in OSB_LIB::FileCdrStorage.
virtual OsbError OSB_LIB::CdrStorage::storeCdrs | ( | const OSB_DB::Session & | session, | |
CdrList & | errors | |||
) | [pure virtual] |
Maintain the database and rename files to final name.
session | Database session to use. | |
errors | List to store CDRs that can not be stored. |
Implemented in OSB_LIB::FileCdrStorage.
virtual bool OSB_LIB::CdrStorage::undoChanges | ( | OSB_DB::Session & | session | ) | [pure virtual] |
Undo all changes on the CDR files and database.
session | Database session to undo and commit the previous transactions (beginStream(), prepareWrite()). |
Before the function is called, all database transactions made in storeCdrs() have been rolled-back.
The undo operation must proceed as much as possible!
This means the function should not throw (unless there's a real emergency), instead appropriate errors should be written to OSB_LIB::Log.
Implemented in OSB_LIB::FileCdrStorage.
virtual OsbError OSB_LIB::CdrStorage::writeCdrFiles | ( | ) | [pure virtual] |
Write the CDRs to file(s).
Implemented in OSB_LIB::FileCdrStorage.