#include <persist.hpp>
|
| FilePersister (unsigned rotnum=0) |
| Ctor. More...
|
|
virtual F8API | ~FilePersister () |
| Dtor. More...
|
|
virtual F8API bool | initialise (const f8String &dbDir, const f8String &dbFname, bool purge=false) |
|
virtual F8API bool | put (const unsigned seqnum, const f8String &what) |
|
virtual F8API bool | put (const unsigned sender_seqnum, const unsigned target_seqnum) |
|
virtual F8API bool | get (const unsigned seqnum, f8String &to) const |
|
virtual F8API unsigned | get (const unsigned from, const unsigned to, Session &session, bool(Session::*)(const Session::SequencePair &with, Session::RetransmissionContext &rctx)) const |
|
virtual F8API unsigned | get_last_seqnum (unsigned &to) const |
|
virtual F8API bool | get (unsigned &sender_seqnum, unsigned &target_seqnum) const |
|
virtual F8API unsigned | find_nearest_highest_seqnum (const unsigned requested, const unsigned last) const |
|
| Persister ()=default |
| Ctor. More...
|
|
virtual | ~Persister () |
| Dtor. More...
|
|
| Persister (const Persister &)=delete |
|
Persister & | operator= (const Persister &)=delete |
|
virtual bool | put (const f8String &key, const f8String &what) |
|
virtual bool | get (const f8String &key, f8String &to) const |
|
virtual bool | del (const f8String &key) |
|
virtual bool | purge () |
|
virtual void | stop () |
| Stop the persister thread. More...
|
|
Definition at line 391 of file persist.hpp.
FIX8::FilePersister::FilePersister |
( |
unsigned |
rotnum = 0 | ) |
|
|
inline |
FilePersister::~FilePersister |
( |
| ) |
|
|
virtual |
unsigned FilePersister::find_nearest_highest_seqnum |
( |
const unsigned |
requested, |
|
|
const unsigned |
last |
|
) |
| const |
|
virtual |
Find the nearest highest sequence number from the sequence to last provided.
- Parameters
-
requested | sequence number to start |
last | highest sequence |
- Returns
- the nearest sequence number or 0 if not found
Implements FIX8::Persister.
Definition at line 339 of file filepersist.cpp.
343 for (
unsigned startseqnum(requested); startseqnum <= last; ++startseqnum)
345 Index::const_iterator itr(
_index.find(startseqnum));
bool FilePersister::get |
( |
const unsigned |
seqnum, |
|
|
f8String & |
to |
|
) |
| const |
|
virtual |
Retrieve a persisted message.
- Parameters
-
seqnum | sequence number of message |
to | target message string |
- Returns
- true on success
Implements FIX8::Persister.
Definition at line 310 of file filepersist.cpp.
References FIX8_MAX_MSG_LENGTH, glout_error, and glout_warn.
314 Index::const_iterator itr(
_index.find(seqnum));
317 glout_warn <<
"Warning: index does not contain seqnum: " << seqnum <<
" in: " <<
_dbIname;
321 if (lseek(
_fod, itr->second._offset, SEEK_SET) < 0)
328 if (read (
_fod, buff, itr->second._size) != itr->second._size)
330 glout_error <<
"Error: could not read message record for seqnum " << seqnum <<
" from: " <<
_dbFname;
334 to.assign(buff, itr->second._size);
#define FIX8_MAX_MSG_LENGTH
Retrieve a range of persisted messages.
- Parameters
-
from | start at sequence number |
to | end sequence number |
session | session containing callback method |
callback | method to call with each retrieved message |
- Returns
- number of messages retrieved
Implements FIX8::Persister.
Definition at line 169 of file filepersist.cpp.
References FIX8::Session::RetransmissionContext::_no_more_records, FIX8_MAX_MSG_LENGTH, FIX8::Session::get_next_send_seq(), glout_debug, glout_error, and glout_info.
172 unsigned last_seq(0);
175 const unsigned finish(to == 0 ? last_seq : to);
178 if (!startSeqNum || from > finish)
181 rctx._no_more_records =
true;
186 Index::const_iterator itr(
_index.find(startSeqNum));
193 if (!itr->first || itr->first > finish)
195 if (lseek(
_fod, itr->second._offset, SEEK_SET) < 0)
201 if (read (
_fod, buff, itr->second._size) != itr->second._size)
203 glout_error <<
"Error: could not read message record for seqnum " << itr->first <<
" from: " <<
_dbFname;
209 if (!(session.*callback)(txresult, rctx))
211 glout_debug <<
"Retransmission callback signalled an error, not sending any more records from: " <<
_dbFname;
215 while(++itr !=
_index.end());
217 rctx._no_more_records =
true;
222 glout_error <<
"record not found (" << startSeqNum <<
')';
std::pair< const unsigned, const f8String > SequencePair
Provides context to your retrans handler.
unsigned get_next_send_seq() const
#define FIX8_MAX_MSG_LENGTH
virtual F8API unsigned find_nearest_highest_seqnum(const unsigned requested, const unsigned last) const
virtual F8API unsigned get_last_seqnum(unsigned &to) const
bool FilePersister::get |
( |
unsigned & |
sender_seqnum, |
|
|
unsigned & |
target_seqnum |
|
) |
| const |
|
virtual |
Retrieve a sequence control record.
- Parameters
-
sender_seqnum | sequence number of last sent message |
target_seqnum | sequence number of last received message |
- Returns
- true on success
Implements FIX8::Persister.
Definition at line 286 of file filepersist.cpp.
References glout_error, and glout_warn.
297 Index::const_iterator itr(
_index.find(0));
304 sender_seqnum = itr->second._offset;
305 target_seqnum = itr->second._size;
unsigned FilePersister::get_last_seqnum |
( |
unsigned & |
to | ) |
const |
|
virtual |
Retrieve sequence number of last peristed message.
- Parameters
-
- Returns
- sequence number of last peristed message on success
Implements FIX8::Persister.
Definition at line 163 of file filepersist.cpp.
165 return sequence =
_index.empty() ? 0 :
_index.rbegin()->first;
bool FilePersister::initialise |
( |
const f8String & |
dbDir, |
|
|
const f8String & |
dbFname, |
|
|
bool |
purge = false |
|
) |
| |
|
virtual |
Open existing database or create new database.
- Parameters
-
dbDir | database directory |
dbFname | database name |
purge | if true, empty database if found |
- Returns
- true on success
Definition at line 45 of file filepersist.cpp.
References FIX8::IPrec::_seq, FIX8::CheckAddTrailingSlash(), FIX8::exist(), glout_error, glout_info, glout_warn, FIX8::Logger::max_rotation, and O_BINARY.
65 vector<string> dblst, idxlst;
73 dblst.push_back(ostr.str());
75 idxlst.push_back(ostr.str());
78 for (
unsigned ii(
_rotnum); ii; --ii)
80 rename (dblst[ii - 1].c_str(), dblst[ii].c_str());
81 rename (idxlst[ii - 1].c_str(), idxlst[ii].c_str());
93 glout_error <<
"Error: creating database index: " <<
_dbIname <<
" (" << strerror(errno) <<
')';
108 glout_error <<
"Error: opening existing database: " <<
_dbFname <<
" (" << strerror(errno) <<
')';
113 glout_error <<
"Error: opening existing database index: " <<
_dbIname <<
" (" << strerror(errno) <<
')';
120 const ssize_t blrd(read(
_iod, static_cast<void *>(&iprec),
sizeof(
IPrec)));
123 glout_error <<
"Error: reading existing database index: " <<
_dbIname <<
" (" << strerror(errno) <<
')';
134 if (!
_index.insert({iprec._seq, iprec._prec}).second)
136 glout_warn <<
"Warning: inserting index record into database index: " <<
_dbIname <<
" (" << iprec <<
"). Ignoring.";
static const int max_rotation
F8API std::string & CheckAddTrailingSlash(std::string &source)
virtual F8API unsigned get_last_seqnum(unsigned &to) const
bool exist(const std::string &fname)
bool FilePersister::put |
( |
const unsigned |
seqnum, |
|
|
const f8String & |
what |
|
) |
| |
|
virtual |
Persist a message.
- Parameters
-
seqnum | sequence number of message |
what | message string |
- Returns
- true on success
Implements FIX8::Persister.
Definition at line 249 of file filepersist.cpp.
References FIX8::IPrec::_prec, and glout_error.
259 if (lseek(
_iod, 0, SEEK_END) < 0)
265 if ((offset = lseek(
_fod, 0, SEEK_END)) < 0)
270 IPrec iprec(seqnum, offset, static_cast<unsigned>(what.size()));
271 if (write (
_iod, static_cast<void *>(&iprec),
sizeof(
IPrec)) !=
sizeof(
IPrec))
273 glout_error <<
"Error: could not write index record for seqnum " << seqnum <<
" to: " <<
_dbIname;
276 if (write (
_fod, what.data(),
static_cast<unsigned>(what.size())) !=
static_cast<ssize_t
>(what.size()))
278 glout_error <<
"Error: could not write record for seqnum " << seqnum <<
" to: " <<
_dbFname;
282 return _index.insert({seqnum, iprec._prec}).second;
bool FilePersister::put |
( |
const unsigned |
sender_seqnum, |
|
|
const unsigned |
target_seqnum |
|
) |
| |
|
virtual |
Persist a sequence control record.
- Parameters
-
sender_seqnum | sequence number of last sent message |
target_seqnum | sequence number of last received message |
- Returns
- true on success
Implements FIX8::Persister.
Definition at line 229 of file filepersist.cpp.
References FIX8::IPrec::_prec, and glout_error.
233 IPrec iprec(0, sender_seqnum, target_seqnum);
234 Index::iterator itr(
_index.find(0));
236 _index.insert({0, iprec._prec});
238 itr->second = iprec._prec;
240 if (lseek(
_iod, 0, SEEK_SET) < 0)
245 return write (
_iod, static_cast<void *>(&iprec),
sizeof(
IPrec)) ==
sizeof(
IPrec);
int FIX8::FilePersister::_fod |
|
private |
Index FIX8::FilePersister::_index |
|
private |
int FIX8::FilePersister::_iod |
|
private |
unsigned FIX8::FilePersister::_rotnum |
|
private |
bool FIX8::FilePersister::_wasCreated |
|
private |
The documentation for this class was generated from the following files: