...
The reason to create sessions ahead is to better control the sessions' parameters (only defaults can be applied in case of unregistered acceptors).
...
Info |
---|
When a session is created ahead and is not used, it consumes memory and file descriptors but does not consume CPU resources. |
The following piece of code shows the creation of the session ahead (either at the service start or on the fly):
Code Block | ||
---|---|---|
| ||
//create ahead: ssn = FixEngine::singleton()->createSession( application, "Sender", "Target", FIX44 ) if( asAcceptor ) ssn->connect(); else //as initiator ssn->connect(hbi, host, port); |
The following piece of code shows the creation of the session on demand:
...
Code Block | ||
---|---|---|
| ||
//create by demand (one should allow unregistered acceptors in the engine config)
// implement SessionsManager interface
class MySessionsManager : public Engine::SessionsManager
//....
//register manager
MySessionsManager* g_mySM = new MySessionsManager();
Engine::FixEngine::InitParameters params;
params.sessionsManager_ = g_mySM;
FixEngine::init( params );
//make descision accept or deny incomiing unregistered session
bool MySessionsManager::onUnregisteredAcceptor( Engine::Session* apSn, const FIXMessage& /*logonMsg*/ )
{
if( passUserCheck( apSn ) {
apSn->registerApplication( application );
apSn->addRef(); //increase count of session users
return true; // accept
}
return false; //deny
} |
Info |
---|
Once the session is created it becomes registered and onUnregisteredAcceptor will not be called until full session destroy, so one should use ssn->connect() to activate this session. |
...
Info |
---|
Session storage will be loaded and SeqNums will be continued for unregistered acceptor even after full session destroy if session storage logs are accessible for the engine. |
Session disconnection
- NonGraceful disconnection (without a Logout message - just drop TCP link):
ssn->disconnectNonGracefully()
...
It is needed to take additional actions to check whether the session is finally disconnected. The session state should become Session::CORRECTLY_TERMINATED or Session::NON_GRACEFULLY_TERMINATED.
...
Info |
---|
When a session is configured to continue SeqNums on the next connect (see IntradayLogoutTolerance) it will be marked as Session::NON_GRACEFULLY_TERMINATED even if logout is received. |
The following piece of code shows the session disconnection with the session release:
...
Code Block | ||
---|---|---|
| ||
ssn->disconnect( logoutReason );
Session::State st = session->getState();
while( Session::CORRECTLY_TERMINATED != session->getState() &&
Session::NON_GRACEFULLY_TERMINATED != session->getState())
{
sleepns(10*1000*1000);
st = session->getState();
}
session->release(); |
Session reconnection
Acceptor
...