Memory-based session storage is typically used to maintain a high-performance FIX session when persisting of a sessions state and messages to the file system is not required. This sample demonstrates how to use pluggable session storage.
{
public:
MySessionStorage();
void clear() ONIXS_FIXENGINE_OVERRIDE;
void close(
bool keepSequenceNumbers,
bool doBackup) ONIXS_FIXENGINE_OVERRIDE;
SequenceNumber
inSeqNum() ONIXS_FIXENGINE_OVERRIDE;
void inSeqNum(SequenceNumber messageSequenceNumber) ONIXS_FIXENGINE_OVERRIDE;
void storeInbound(const Message & message, SequenceNumber messageSequenceNumber, const
RawMessagePointer& pointer,
bool logMessage) ONIXS_FIXENGINE_OVERRIDE;
void storeInbound(const FlatMessage & message, SequenceNumber messageSequenceNumber, const
RawMessagePointer & pointer,
bool logMessage) ONIXS_FIXENGINE_OVERRIDE;
typedef
std::vector<
char> RawMessage;
typedef
std::map<SequenceNumber, RawMessage> MessageSequenceNumber2RawMessage;
MessageSequenceNumber2RawMessage outgoingMessages_;
SequenceNumber
outSeqNum() ONIXS_FIXENGINE_OVERRIDE;
void outSeqNum(SequenceNumber messageSequenceNumber) ONIXS_FIXENGINE_OVERRIDE;
void flush() ONIXS_FIXENGINE_OVERRIDE {}
private:
bool isSessionTerminated_;
SequenceNumber inSeqNum_;
SequenceNumber outSeqNum_;
Timestamp sessionCreationTime_;
};
#include "MySessionStorage.h"
MySessionStorage::MySessionStorage()
: isSessionTerminated_(false),
inSeqNum_(0),
outSeqNum_(0)
{}
{
std::clog << "Clear the session storage." << std::endl;
inSeqNum_ = 0;
outSeqNum_ = 0;
outgoingMessages_.clear();
}
{
if(doBackup)
{
std::clog << "Back up the stored data." << std::endl;
}
if(!keepSequenceNumbers)
}
{
std::clog << "getOutbound(" << beginSequenceNumber << ", " << endSequenceNumber << ",..)" << std::endl;
for(SequenceNumber i = beginSequenceNumber; i <= endSequenceNumber; ++i)
{
MessageSequenceNumber2RawMessage::const_iterator it = outgoingMessages_.find(i);
if(it != outgoingMessages_.end())
listener->
onReplayedMessage(ISessionStorage::RawMessagePointer(&it->second[0], it->second.size()));
}
}
{
return inSeqNum_;
}
{
std::clog << "inSeqNum(" << messageSequenceNumber << ")" << std::endl;
inSeqNum_ = messageSequenceNumber;
}
{
inSeqNum_ = messageSequenceNumber;
if (logMessage)
{
std::clog << "storeInbound(" << messageSequenceNumber << ", " << std::string(
<< ')' << std::endl;
}
}
{
inSeqNum_ = messageSequenceNumber;
if(logMessage)
{
std::clog << "storeInbound(" << messageSequenceNumber << ", " << std::string(
<< ')' << std::endl;
}
}
{
outSeqNum_ = messageSequenceNumber;
if(logMessage)
{
std::clog << "storeOutbound(" << messageSequenceNumber << ", " << std::string(
<< ')' << std::endl;
outgoingMessages_.insert(make_pair(messageSequenceNumber, RawMessage(pointer.
buffer_,
}
}
{
outSeqNum_ = sequenceNumber;
if(logMessage)
{
std::clog << "storeOutbound(" << sequenceNumber << ", " << std::string(
<< ')' << std::endl;
outgoingMessages_.insert(make_pair(sequenceNumber, RawMessage(pointer.
buffer_,
}
}
{
std::clog << "setSessionTerminationFlag(" << terminated << ")" << std::endl;
isSessionTerminated_ = terminated;
}
{
return outSeqNum_;
}
{
std::clog << "outSeqNum(" << messageSequenceNumber << ")" << std::endl;
outSeqNum_ = messageSequenceNumber;
}
{
std::clog << "sessionCreationTime(" << timestamp.toString() << ")" << std::endl;
sessionCreationTime_ = timestamp;
}
{
return sessionCreationTime_;
}
#include "MySessionStorage.h"
#include "../../Common/Helpers.h"
#include "../../Common/Settings.h"
using namespace Settings;
namespace {
class MySessionListener : public ISessionListener
{
public:
void onInboundApplicationMsg(Message &, Session *) ONIXS_FIXENGINE_OVERRIDE {}
};
};
int main()
{
try {
EngineSettings settings;
settings.licenseStore(LicenseStore);
Engine::init(settings);
MySessionListener listener;
MySessionStorage storage;
Session session("MySessionStorage_Initiator", "MySessionStorage_Acceptor", FixProtocolVersion, true, &listener, SessionStorageType::Pluggable, &storage);
Message order(MsgType::Order_Single, FixProtocolVersion);
if(foundMessage.get())
std::clog << std::endl << "Message found: " << *foundMessage << std::endl;
else
std::clog << std::endl << "Message not found!" << std::endl;
}
catch(const std::exception & ex) {
processSampleException(ex.what());
}
Engine::shutdown();
return 0;
}