FIX Session

Persistent session

Persistent session is a session with persistent storage.
Engine::Session* Engine::FixEngine::createSession(Engine::Application* apApp, const std::string& aSenderCompID, const std::string& aTargetCompID, 
    Engine::FIXVersion aVer = FIX42, Engine::SessionExtraParameters* pParam = NULL, const Engine::MessageStorageType storageType = persistent_storageType)

Session state is stored on disk and can be restored after failure. The following information is stored for session:

Transient session

Transient session is a session with transient storage.
Engine::Session* Engine::FixEngine::createSession(Engine::Application* apApp, const std::string& aSenderCompID, const std::string& aTargetCompID, 
    Engine::FIXVersion aVer = FIX42, Engine::SessionExtraParameters* pParam = NULL, const Engine::MessageStorageType storageType = transient_storageType)

Session state is stored in memory, which highly increases performance. This is the recommended way in case when session is not required to provide fail-over by itself.

Session state

From the time session is created and till it is destroyed session uses state that dictates its reaction to events. Session state can be obtained using Engine::Session::getState() method, which returns Session::State.

inline_dotgraph_2.dot

To convert the Engine::Session::State enum value to a string value, use the Engine::Session::state2string() method.

Sequence number handling

Session is always assigned two sequence numbers:

Both sides must maintains two values and control that they are in sync. There are two types of sequence numbers desync:

Both sequence numbers are started from 1 when session is created from scratch. After correct session termination sequence numbers are reset to 1. If connection is terminated non-gracefully then after restore sequence numbers continue. In fact a lot of service providers never reset sequence numbers during the day. The are also some, who reset sequence numbers once per week. There are several cases to handle such deviation from standard in FIX Antenna

Resetting sequence number

It is recommended that a new FIX session is established once within each 24 hour period. The new set of sequence numbers can be set by sending a Logon message with the ResetSeqNumFlag set. FIX Antenna supports this feature via ResetSeqNumAfter24hours configuration option. It is also possible to reset sequence number manually using void Engine::Session::resetSeqNum() method.

Late delivery vs rejecting

When session connection is lost, the initiator tries to reconnect, which may take some time (or even infinity), acceptor waits for reconnect. For both sides message delivery is impossible. FIX Antenna provides two different approaches to the message handling in this state:

The Engine::SessionExtraParameters::enableMessageRejecting_ parameter controlls if Message rejecting enabled or not (by default it is disabled). The configuration file's property MessageTimeToLive specifies how long session waits for connection restore (i.e. before reject the message). If connection is not restored during MessageTimeToLive interval - the session starts rejecting messages by calling Engine::Application::onMsgRejectEvent() for each rejected message.

Events

To monitor engine events (see the Engine::Event class), derive from the EventListener class and register an object of this class using the Engine::FixEngine::registerEventListener method.

It is vital to call the Engine::FixEngine::unregisterEventListener method before calling the Engine::FixEngine::destroy method.

To detect the exact type of the received event, use C++ RTTI or the Event::getType method.

For example:

class Listener : public Engine::EventListener {
    public:
        virtual void onNotification (const Engine::Notification &aNotification){
            clog << "Notification: " << *aNotification.what() << endl << endl;
        } 
   
        virtual void onWarning (const Engine::Warning &aWarning){
            clog << "Warning: " << *aWarning.what() << endl << endl;
        }
   
        virtual void onError (const Engine::Error &aError){
            clog << "Error: " << *aError.what() << endl << endl;
        }
};
   
Listener listener;
Engine::FixEngine::singleton()->registerEventListener(&listener);

// ... - business logic

// must be done before FixEngine::destroy()
Engine::FixEngine::singleton()->unregisterEventListener(&listener); 

Engine::FixEngine::destroy();

Generated on Fri Apr 17 12:26:09 2009 for B2BITS FIX Antenna C++ by  doxygen 1.5.6