Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

 If an exception is thrown from the callback, the reject message will be sent by the engine to the counterparty. 

 

...

Info

The Application::process method should be completed as quickly as possible because multiple sessions are served by each Reader thread of the new TCPDispatcher. Time-consuming tasks are not advised to be performed inside it, pass the message into the pool to be processed instead.


Code Block
languagecpp
bool TraderApp::process( Engine::FIXMessageProcessElem* work, const Engine::Session& sn )
{
    sn.commitIncomingMessage(work);                 // save incoming message to session logs (to cache in memory)
    work->elem->userData0 = (MyApp*)this;           // setup processing pool to call this app to process the message
    processor_->postMessageToWorker( work->elem );  // post the messaage to the pool
    work->pipelined = 1;                            // hint the engine that the message is still in use
    return true;
}

 Thread Safety

The caller of the Application::process() method is Session, It guaranties that only one thread at the same time calls the Application object callbacks from this session. So it guaranties thread safety if the Application is bound to one session.  The caller thread can be Worker, Reader (in HFT FA), Timer or user thread that manipulates Session. FIX Antenna HFT always uses direct sending from the user threads to the sockets if sockets are ready. Otherwise (if sockets are busy), it uses the old style single dispatcher to poll sockets until a socket gets ready (vacant).

...

The socket accept() call is on the same thread as the read() thread (unlike FIX Antenna C++).  After socket is accepted and the Logon message is read by the Reader, the processing of the Logon message is performed by the Worker thread, so if one Application object is bound to the multiple Sessions it can receive onLogonEvent() from the one session and process() from the another concurrently even if the one Reader thread is used.

...

Info

The constness of the session ref in the Application::* callbacks means one generally shouldn’t call synchronously non-const methods of the session from this callback even if stored non-const  session ref is obtained a different way.


Reader Thread

The number of readers is controlled by the property TCPDispatcher.NumberOfWorkers in the engine.properties configuration file passed to FixEngine::init directly or using InitParameters::propertiesFileName. Each Reader has its own pool of messages. Each Reader calls the onNewThreadCreated() method with the TCP_READER value in the threadAttrs.