fix8  version 1.4.0
Open Source C++ FIX Framework
FIX8::MemoryPersister Class Reference

Memory based message persister. More...

#include <persist.hpp>

Inheritance diagram for FIX8::MemoryPersister:
FIX8::Persister

Public Member Functions

 MemoryPersister ()
 Ctor. More...
 
virtual ~MemoryPersister ()
 Dtor. More...
 
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
 
- Public Member Functions inherited from FIX8::Persister
 Persister ()=default
 Ctor. More...
 
virtual ~Persister ()
 Dtor. More...
 
 Persister (const Persister &)=delete
 
Persisteroperator= (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...
 

Private Types

using Store = std::map< unsigned, const f8String >
 

Private Attributes

Store _store
 

Additional Inherited Members

- Public Types inherited from FIX8::Persister
enum  { MaxMsgLen = FIX8_MAX_MSG_LENGTH }
 Maximum length of persisted FIX message. More...
 
- Protected Attributes inherited from FIX8::Persister
bool _opened = false
 

Detailed Description

Memory based message persister.

Definition at line 292 of file persist.hpp.

Member Typedef Documentation

using FIX8::MemoryPersister::Store = std::map<unsigned, const f8String>
private

Definition at line 294 of file persist.hpp.

Constructor & Destructor Documentation

FIX8::MemoryPersister::MemoryPersister ( )
inline

Ctor.

Definition at line 299 of file persist.hpp.

299 {}
virtual FIX8::MemoryPersister::~MemoryPersister ( )
inlinevirtual

Dtor.

Definition at line 301 of file persist.hpp.

301 {}

Member Function Documentation

unsigned MemoryPersister::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
requestedsequence number to start
lasthighest sequence
Returns
the nearest sequence number or 0 if not found

Implements FIX8::Persister.

Definition at line 401 of file persist.cpp.

402 {
403  if (last)
404  {
405  for (unsigned startseqnum(requested); startseqnum <= last; ++startseqnum)
406  {
407  Store::const_iterator itr(_store.find(startseqnum));
408  if (itr != _store.end())
409  return itr->first;
410  }
411  }
412 
413  return 0;
414 }
bool MemoryPersister::get ( const unsigned  seqnum,
f8String to 
) const
virtual

Retrieve a persisted message.

Parameters
seqnumsequence number of message
totarget message string
Returns
true on success

Implements FIX8::Persister.

Definition at line 389 of file persist.cpp.

390 {
391  if (!seqnum)
392  return false;
393  Store::const_iterator itr(_store.find(seqnum));
394  if (itr == _store.end())
395  return false;
396  to = itr->second;
397  return true;
398 }
unsigned MemoryPersister::get ( const unsigned  from,
const unsigned  to,
Session session,
bool(Session::*)(const Session::SequencePair &with, Session::RetransmissionContext &rctx)  callback 
) const
virtual

Retrieve a range of persisted messages.

Parameters
fromstart at sequence number
toend sequence number
sessionsession containing callback method
callbackmethod to call with each retrieved message
Returns
number of messages retrieved

Implements FIX8::Persister.

Definition at line 322 of file persist.cpp.

References FIX8::Session::RetransmissionContext::_no_more_records, FIX8::Session::get_next_send_seq(), glout_error, and glout_warn.

324 {
325  unsigned last_seq(0);
326  get_last_seqnum(last_seq);
327  unsigned recs_sent(0), startSeqNum(find_nearest_highest_seqnum (from, last_seq));
328  const unsigned finish(to == 0 ? last_seq : to);
329  Session::RetransmissionContext rctx(from, to, session.get_next_send_seq());
330 
331  if (!startSeqNum || from > finish)
332  {
333  glout_warn << "No records found";
334  rctx._no_more_records = true;
335  (session.*callback)(Session::SequencePair(0, ""), rctx);
336  return 0;
337  }
338 
339  Store::const_iterator itr(_store.find(startSeqNum));
340  if (itr != _store.end())
341  {
342  do
343  {
344  if (!itr->first || itr->first > finish)
345  break;
346  Session::SequencePair result(itr->first, itr->second);
347  ++recs_sent;
348  if (!(session.*callback)(result, rctx))
349  break;
350  }
351  while(++itr != _store.end());
352 
353  Session::SequencePair result(0, "");
354  rctx._no_more_records = true;
355  (session.*callback)(result, rctx);
356  }
357  else
358  glout_error << "record not found (" << startSeqNum << ')';
359 
360  return recs_sent;
361 }
virtual F8API unsigned find_nearest_highest_seqnum(const unsigned requested, const unsigned last) const
Definition: persist.cpp:401
virtual F8API unsigned get_last_seqnum(unsigned &to) const
Definition: persist.cpp:417
std::pair< const unsigned, const f8String > SequencePair
Definition: session.hpp:615
Provides context to your retrans handler.
Definition: session.hpp:598
#define glout_error
Definition: logger.hpp:606
unsigned get_next_send_seq() const
Definition: session.hpp:750
#define glout_warn
Definition: logger.hpp:604
bool MemoryPersister::get ( unsigned &  sender_seqnum,
unsigned &  target_seqnum 
) const
virtual

Retrieve a sequence control record.

Parameters
sender_seqnumsequence number of last sent message
target_seqnumsequence number of last received message
Returns
true on success

Implements FIX8::Persister.

Definition at line 377 of file persist.cpp.

378 {
379  Store::const_iterator itr(_store.find(0));
380  if (itr == _store.end())
381  return false;
382  const unsigned *loc(reinterpret_cast<const unsigned *>(&itr->second));
383  sender_seqnum = *loc++;
384  target_seqnum = *loc;
385  return true;
386 }
unsigned MemoryPersister::get_last_seqnum ( unsigned &  to) const
virtual

Retrieve sequence number of last peristed message.

Parameters
totarget sequence number
Returns
sequence number of last peristed message on success

Implements FIX8::Persister.

Definition at line 417 of file persist.cpp.

418 {
419  return to = (_store.empty() ? 0 : _store.rbegin()->first);
420 }
bool MemoryPersister::put ( const unsigned  seqnum,
const f8String what 
)
virtual

Persist a message.

Parameters
seqnumsequence number of message
whatmessage string
Returns
true on success

Implements FIX8::Persister.

Definition at line 371 of file persist.cpp.

372 {
373  return !seqnum ? false : _store.insert({seqnum, what}).second;
374 }
bool MemoryPersister::put ( const unsigned  sender_seqnum,
const unsigned  target_seqnum 
)
virtual

Persist a sequence control record.

Parameters
sender_seqnumsequence number of last sent message
target_seqnumsequence number of last received message
Returns
true on success

Implements FIX8::Persister.

Definition at line 364 of file persist.cpp.

365 {
366  const unsigned arr[2] { sender_seqnum, target_seqnum };
367  return _store.insert({0, f8String(reinterpret_cast<const char *>(arr), sizeof(arr))}).second;
368 }
std::string f8String
Definition: f8types.hpp:47

Member Data Documentation

Store FIX8::MemoryPersister::_store
private

Definition at line 295 of file persist.hpp.


The documentation for this class was generated from the following files: