BDE 4.14.0 Production release
|
Provide a protocol for managing log record handles.
This component defines the base-level protocol, ball::RecordBuffer
, for managing record handles (specifically instances of bsl::shared_ptr<ball::Record>
) in a double-ended buffer. In particular, the ball::RecordBuffer
protocol class provides abstract methods to push a record handle into either end (back or front) of the buffer (pushBack
and pushFront
), to obtain read-only access to the log record positioned at either end (back
and front
) and to remove the record positioned at either end (popBack
and popFront
). Note that the classes implementing this protocol are supposed to manage record handles and not the records themselves, specifically, they should not allocate the memory for records and should not explicitly destroy records (a record is destroyed automatically when the reference count associated with its handle becomes zero). The push methods (pushBack
and pushFront
) are not guaranteed to succeed. Concrete implementations implementations are permitted to remove records from the buffer in order to attempt to accommodate a push request (which implies that, after a successful call to a push method, length
is not guaranteed to be more than one, and an unsuccessful call to a push method is permitted to leave the buffer empty).
This section illustrates intended use of this component.
This example shows the definition of a simple concrete record buffer. The requisite steps are:
ball::RecordBuffer
.The concrete thread-safe my_RecordBuffer
class in this example implements the ball::RecordBuffer
protocol by delegating to an instance of bsl::vector<bsl::shared_ptr<ball::Record> >
:
Recursive mutex (rather than plain mutex) is chosen to provide thread safety. This allows the manipulation of the record buffer between the call to beginSequence
and endSequence
. If we had used plain mutex, calling any method on the record buffer between the calls to beginSequence
and endSequence
would result in a deadlock.
Note that we always implement a virtual destructor (non-inline) in the .cpp file (to indicate the unique location of the class's virtual table):
This example demonstrates working with the ball::RecordBuffer
protocol. We implement a function processRecord
that processes a specified record handle based on its severity.