forwardAsync File-based Session Storage   Table of ContentScheduling Sessions for Automatic Connectionforward
Pluggable Session Storage

Pluggable session storage allows customizing completely the persistence of a session state and messages.

For example, it could be used to implement High-Availability (HA) Solutions, one can implement a Pluggable Session Storage which stores data to shareable storage and if one server, with the FIX Engine, fails and another reserve server stands up then the FIX Engine can restore session states from the same shareable storage.

Switching to Pluggable Session Storage

To create such a session, it is needed to implement the ISessionStorage Interface and use one of Session's constructors that accepts this interface as the parameter.

Example
C#
using System;
using System.Collections.Generic;
using FIXForge.NET.FIX;

class MySessionStorage : ISessionStorage
{
    public void Clear()
    {
    }

    public void Close(bool keepSequenceNumbersBetweenFixConnections, bool doBackup)
    {
        this.keepSequenceNumbers = keepSequenceNumbersBetweenFixConnections;
        this.doBackup = doBackup;
    }

    public String Id
    {
        get
        {
            return "MyStorage";
        }
    }

    public int InSeqNum
    {
        get
        {
            return inSeqNum;
        }
        set
        {
            inSeqNum = value;
        }
    }

    public DateTime SessionCreationTime
    {
        get
        {
            return sessionCreationTime;
        }
        set
        {
            sessionCreationTime = value;
        }
    }

    public Message FindOutboundMessage(int messageSequenceNumber)
    {
        if (outboundMessages.ContainsKey(messageSequenceNumber))
        {
            return outboundMessages[messageSequenceNumber];
        }
        else
        {
            return null;
        }
    }

    public void SetSessionTerminationStatus(bool terminated)
    {
    }

    public void StoreInboundMessage(Message message, bool keepMessage)
    {
        inSeqNum = message.SeqNum;

        lastInboundMessage = message;
    }

    public void StoreOutboundMessage(Message message, bool keepMessage)
    {
        outSeqNum = message.SeqNum;

        lastOutboundMessage = message;

        if (keepMessage && !outboundMessages.ContainsKey(message.SeqNum))
        {
            outboundMessages.Add(message.SeqNum, message);
        }
    }

    public int OutSeqNum
    {
        get
        {
            return outSeqNum;
        }
        set
        {
            outSeqNum = value;
        }
    }

    private Message lastInboundMessage;

    public Message LastInboundMessage
    {
        get { return lastInboundMessage; }
    }

    private Message lastOutboundMessage;

    public Message LastOutboundMessage
    {
        get { return lastOutboundMessage; }
    }

    private Dictionary<int, Message> outboundMessages = new Dictionary<int, Message>();

    private int inSeqNum;

    private int outSeqNum;

    private bool keepSequenceNumbers;

    private bool doBackup;

    private DateTime sessionCreationTime;

}

void Run()
{
    const string sender = "Me";
    const string target = "Counterpart";
    ProtocolVersion version = ProtocolVersion.FIX44;
    bool keepSequenceNumbersBetweenFixConnections = true;

    MySessionStorage storage = new MySessionStorage();

    Session session = new Session(sender, target, version, keepSequenceNumbersBetweenFixConnections, storage);
}