Public Member Functions | Private Types | Private Member Functions | Private Attributes
FIX::SessionFactory Class Reference

Responsible for creating Session objects. More...

#include <SessionFactory.h>

Collaboration diagram for FIX::SessionFactory:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 SessionFactory (Application &application, MessageStoreFactory &messageStoreFactory, LogFactory *pLogFactory)
 ~SessionFactory ()
Sessioncreate (const SessionID &sessionID, const Dictionary &settings) throw ( ConfigError )
void destroy (Session *pSession)

Private Types

typedef std::map< std::string,
ptr::shared_ptr
< DataDictionary > > 
Dictionaries

Private Member Functions

ptr::shared_ptr< DataDictionarycreateDataDictionary (const SessionID &sessionID, const Dictionary &settings, const std::string &settingsKey) throw (ConfigError)
void processFixtDataDictionaries (const SessionID &sessionID, const Dictionary &settings, DataDictionaryProvider &provider) throw (ConfigError)
void processFixDataDictionary (const SessionID &sessionID, const Dictionary &settings, DataDictionaryProvider &provider) throw (ConfigError)
std::string toApplVerID (const std::string &value)

Private Attributes

Applicationm_application
MessageStoreFactorym_messageStoreFactory
LogFactorym_pLogFactory
Dictionaries m_dictionaries

Detailed Description

Responsible for creating Session objects.

This factory will use QuickFIX SessionID, Dictionary settings, MessageStoreFactory, and optional LogFactory to create all the required sessions for an Application.

Definition at line 46 of file SessionFactory.h.


Member Typedef Documentation

typedef std::map< std::string, ptr::shared_ptr<DataDictionary> > FIX::SessionFactory::Dictionaries [private]

Definition at line 63 of file SessionFactory.h.


Constructor & Destructor Documentation

FIX::SessionFactory::SessionFactory ( Application application,
MessageStoreFactory messageStoreFactory,
LogFactory pLogFactory 
) [inline]

Definition at line 49 of file SessionFactory.h.

: m_application( application ),
  m_messageStoreFactory( messageStoreFactory ),
  m_pLogFactory( pLogFactory ) {}

Definition at line 37 of file SessionFactory.cpp.

{
}

Member Function Documentation

Session * FIX::SessionFactory::create ( const SessionID sessionID,
const Dictionary settings 
) throw ( ConfigError )

Definition at line 41 of file SessionFactory.cpp.

References FIX::CHECK_COMPID, FIX::CHECK_LATENCY, FIX::CONNECTION_TYPE, FIX::UtcTimeOnlyConvertor::convert(), FIX::DEFAULT_APPLVERID, FIX::END_DAY, FIX::END_TIME, FIX::DateTime::getHour(), FIX::DateTime::getMinute(), FIX::DateTime::getSecond(), FIX::HEARTBTINT, FIX::FIELD::HeartBtInt, FIX::TimeRange::isInRange(), FIX::LOGON_DAY, FIX::LOGON_TIME, FIX::LOGON_TIMEOUT, FIX::LOGOUT_DAY, FIX::LOGOUT_TIME, FIX::LOGOUT_TIMEOUT, FIX::MAX_LATENCY, FIX::MILLISECONDS_IN_TIMESTAMP, FIX::PERSIST_MESSAGES, FIX::REFRESH_ON_LOGON, FIX::RESET_ON_DISCONNECT, FIX::RESET_ON_LOGON, FIX::RESET_ON_LOGOUT, FIX::SEND_REDUNDANT_RESENDREQUESTS, FIX::SESSION_QUALIFIER, FIX::START_DAY, FIX::START_TIME, FIX::Message::toApplVerID(), FIX::USE_DATA_DICTIONARY, FIX::USE_LOCAL_TIME, and FIX::VALIDATE_LENGTH_AND_CHECKSUM.

Referenced by FIX::Acceptor::initialize(), and FIX::Initiator::initialize().

{
  std::string connectionType = settings.getString( CONNECTION_TYPE );
  if ( connectionType != "acceptor" && connectionType != "initiator" )
    throw ConfigError( "Invalid ConnectionType" );

  if( connectionType == "acceptor" && settings.has(SESSION_QUALIFIER) )
    throw ConfigError( "SessionQualifier cannot be used with acceptor." );

  bool useDataDictionary = true;
  if ( settings.has( USE_DATA_DICTIONARY ) )
    useDataDictionary = settings.getBool( USE_DATA_DICTIONARY );

  std::string defaultApplVerID;
  if( sessionID.isFIXT() )
  {
    if( !settings.has(DEFAULT_APPLVERID) )
    {
      throw ConfigError("ApplVerID is required for FIXT transport");
    }
    defaultApplVerID = Message::toApplVerID( settings.getString(DEFAULT_APPLVERID) );
  }

  DataDictionaryProvider dataDictionaryProvider;
  if( useDataDictionary )
  {
    if( sessionID.isFIXT() )
    {
      processFixtDataDictionaries(sessionID, settings, dataDictionaryProvider);
    }
    else
    {
      processFixDataDictionary(sessionID, settings, dataDictionaryProvider);
    }
  }

  bool useLocalTime = false;
  if( settings.has(USE_LOCAL_TIME) )
    useLocalTime = settings.getBool( USE_LOCAL_TIME );

  int startDay = -1;
  int endDay = -1;
  try
  {
    startDay = settings.getDay( START_DAY );
    endDay = settings.getDay( END_DAY );
  }
  catch( ConfigError & ) {}
  catch( FieldConvertError & e ) { throw ConfigError( e.what() ); }

  UtcTimeOnly startTime;
  UtcTimeOnly endTime;
  try
  {
    startTime = UtcTimeOnlyConvertor::convert
                ( settings.getString( START_TIME ) );
    endTime = UtcTimeOnlyConvertor::convert
              ( settings.getString( END_TIME ) );
  }
  catch ( FieldConvertError & e ) { throw ConfigError( e.what() ); }

  TimeRange utcSessionTime
    ( startTime, endTime, startDay, endDay );
  TimeRange localSessionTime
    ( LocalTimeOnly(startTime.getHour(), startTime.getMinute(), startTime.getSecond()),
      LocalTimeOnly(endTime.getHour(), endTime.getMinute(), endTime.getSecond()),
      startDay, endDay );
  TimeRange sessionTimeRange = useLocalTime ? localSessionTime : utcSessionTime;

  if( startDay >= 0 && endDay < 0 )
    throw ConfigError( "StartDay used without EndDay" );
  if( endDay >= 0 && startDay < 0 )
    throw ConfigError( "EndDay used without StartDay" );

  HeartBtInt heartBtInt( 0 );
  if ( connectionType == "initiator" )
  {
    heartBtInt = HeartBtInt( settings.getInt( HEARTBTINT ) );
    if ( heartBtInt <= 0 ) throw ConfigError( "Heartbeat must be greater than zero" );
  }

  std::auto_ptr<Session> pSession;
  pSession.reset( new Session( m_application, m_messageStoreFactory,
    sessionID, dataDictionaryProvider, sessionTimeRange,
    heartBtInt, m_pLogFactory ) );

  pSession->setSenderDefaultApplVerID(defaultApplVerID);

  int logonDay = startDay;
  int logoutDay = endDay;
  try
  {
    logonDay = settings.getDay( LOGON_DAY );
    logoutDay = settings.getDay( LOGOUT_DAY );
  }
  catch( ConfigError & ) {}
  catch( FieldConvertError & e ) { throw ConfigError( e.what() ); }

  UtcTimeOnly logonTime( startTime );
  UtcTimeOnly logoutTime( endTime );
  try
  {
    logonTime = UtcTimeOnlyConvertor::convert
                ( settings.getString( LOGON_TIME ) );
  }
  catch( ConfigError & ) {}
  catch( FieldConvertError & e ) { throw ConfigError( e.what() ); }
  try
  {
    logoutTime = UtcTimeOnlyConvertor::convert
              ( settings.getString( LOGOUT_TIME ) );
  }
  catch( ConfigError & ) {}
  catch( FieldConvertError & e ) { throw ConfigError( e.what() ); }

  TimeRange utcLogonTime
    ( logonTime, logoutTime, logonDay, logoutDay );
  TimeRange localLogonTime
    ( LocalTimeOnly(logonTime.getHour(), logonTime.getMinute(), logonTime.getSecond()),
      LocalTimeOnly(logoutTime.getHour(), logoutTime.getMinute(), logoutTime.getSecond()),
      logonDay, logoutDay );
  TimeRange logonTimeRange = useLocalTime ? localLogonTime : utcLogonTime;

  if( !sessionTimeRange.isInRange(logonTime, logonDay) )
    throw ConfigError( "LogonTime must be between StartTime and EndTime" );
  if( !sessionTimeRange.isInRange(logoutTime, logoutDay) )
    throw ConfigError( "LogoutTime must be between StartTime and EndTime" );
  pSession->setLogonTime( logonTimeRange );

  if ( settings.has( SEND_REDUNDANT_RESENDREQUESTS ) )
    pSession->setSendRedundantResendRequests( settings.getBool( SEND_REDUNDANT_RESENDREQUESTS ) );
  if ( settings.has( CHECK_COMPID ) )
    pSession->setCheckCompId( settings.getBool( CHECK_COMPID ) );
  if ( settings.has( CHECK_LATENCY ) )
    pSession->setCheckLatency( settings.getBool( CHECK_LATENCY ) );
  if ( settings.has( MAX_LATENCY ) )
    pSession->setMaxLatency( settings.getInt( MAX_LATENCY ) );
  if ( settings.has( LOGON_TIMEOUT ) )
    pSession->setLogonTimeout( settings.getInt( LOGON_TIMEOUT ) );
  if ( settings.has( LOGOUT_TIMEOUT ) )
    pSession->setLogoutTimeout( settings.getInt( LOGOUT_TIMEOUT ) );
  if ( settings.has( RESET_ON_LOGON ) )
    pSession->setResetOnLogon( settings.getBool( RESET_ON_LOGON ) );
  if ( settings.has( RESET_ON_LOGOUT ) )
    pSession->setResetOnLogout( settings.getBool( RESET_ON_LOGOUT ) );
  if ( settings.has( RESET_ON_DISCONNECT ) )
    pSession->setResetOnDisconnect( settings.getBool( RESET_ON_DISCONNECT ) );
  if ( settings.has( REFRESH_ON_LOGON ) )
    pSession->setRefreshOnLogon( settings.getBool( REFRESH_ON_LOGON ) );
  if ( settings.has( MILLISECONDS_IN_TIMESTAMP ) )
    pSession->setMillisecondsInTimeStamp( settings.getBool( MILLISECONDS_IN_TIMESTAMP ) );
  if ( settings.has( PERSIST_MESSAGES ) )
    pSession->setPersistMessages( settings.getBool( PERSIST_MESSAGES ) );
  if ( settings.has( VALIDATE_LENGTH_AND_CHECKSUM ) )
    pSession->setValidateLengthAndChecksum( settings.getBool( VALIDATE_LENGTH_AND_CHECKSUM ) );
   
  return pSession.release();
}
ptr::shared_ptr< DataDictionary > FIX::SessionFactory::createDataDictionary ( const SessionID sessionID,
const Dictionary settings,
const std::string &  settingsKey 
) throw (ConfigError) [private]

Definition at line 206 of file SessionFactory.cpp.

References FIX::VALIDATE_FIELDS_HAVE_VALUES, FIX::VALIDATE_FIELDS_OUT_OF_ORDER, and FIX::VALIDATE_USER_DEFINED_FIELDS.

{
  ptr::shared_ptr<DataDictionary> pDD;
  std::string path = settings.getString( settingsKey );
  Dictionaries::iterator i = m_dictionaries.find( path );
  if ( i != m_dictionaries.end() )
  {
    pDD = i->second;
  }
  else
  {
    pDD = ptr::shared_ptr<DataDictionary>(new DataDictionary( path ));
    m_dictionaries[ path ] = pDD;
  }

  ptr::shared_ptr<DataDictionary> pCopyOfDD = ptr::shared_ptr<DataDictionary>(new DataDictionary(*pDD));

  if( settings.has( VALIDATE_FIELDS_OUT_OF_ORDER ) )
    pCopyOfDD->checkFieldsOutOfOrder( settings.getBool( VALIDATE_FIELDS_OUT_OF_ORDER ) );
  if( settings.has( VALIDATE_FIELDS_HAVE_VALUES ) )
    pCopyOfDD->checkFieldsHaveValues( settings.getBool( VALIDATE_FIELDS_HAVE_VALUES ) );
  if( settings.has( VALIDATE_USER_DEFINED_FIELDS ) )
    pCopyOfDD->checkUserDefinedFields( settings.getBool( VALIDATE_USER_DEFINED_FIELDS ) );

  return pCopyOfDD;
}
void FIX::SessionFactory::destroy ( Session pSession)

Definition at line 201 of file SessionFactory.cpp.

{
  delete pSession;
}
void FIX::SessionFactory::processFixDataDictionary ( const SessionID sessionID,
const Dictionary settings,
DataDictionaryProvider provider 
) throw (ConfigError) [private]

Definition at line 266 of file SessionFactory.cpp.

References FIX::DATA_DICTIONARY, and FIX::Message::toApplVerID().

{
  ptr::shared_ptr<DataDictionary> pDataDictionary = createDataDictionary(sessionID, settings, DATA_DICTIONARY);
  provider.addTransportDataDictionary(sessionID.getBeginString(), pDataDictionary);
  provider.addApplicationDataDictionary(Message::toApplVerID(sessionID.getBeginString()), pDataDictionary);
}
void FIX::SessionFactory::processFixtDataDictionaries ( const SessionID sessionID,
const Dictionary settings,
DataDictionaryProvider provider 
) throw (ConfigError) [private]

Definition at line 235 of file SessionFactory.cpp.

References FIX::APP_DATA_DICTIONARY, FIX::DEFAULT_APPLVERID, FIX::string_toUpper(), FIX::Message::toApplVerID(), and FIX::TRANSPORT_DATA_DICTIONARY.

{
  ptr::shared_ptr<DataDictionary> pDataDictionary = createDataDictionary(sessionID, settings, TRANSPORT_DATA_DICTIONARY);
  provider.addTransportDataDictionary(sessionID.getBeginString(), pDataDictionary);
  
  for(Dictionary::const_iterator data = settings.begin(); data != settings.end(); ++data)
  {
    const std::string& key = data->first;
    const std::string frontKey = key.substr(0, strlen(APP_DATA_DICTIONARY));
    if( frontKey == string_toUpper(APP_DATA_DICTIONARY) )
    {
      if( key == string_toUpper(APP_DATA_DICTIONARY) )
      {
        provider.addApplicationDataDictionary(Message::toApplVerID(settings.getString(DEFAULT_APPLVERID)),
            createDataDictionary(sessionID, settings, APP_DATA_DICTIONARY));
      }
      else
      {
        std::string::size_type offset = key.find('.');
        if( offset == std::string::npos )
          throw ConfigError(std::string("Malformed ") + APP_DATA_DICTIONARY + ": " + key);
        std::string beginStringQualifier = key.substr(offset+1);
        provider.addApplicationDataDictionary(Message::toApplVerID(beginStringQualifier), 
            createDataDictionary(sessionID, settings, key));
      }
    }
  }
}
std::string FIX::SessionFactory::toApplVerID ( const std::string &  value) [private]

Member Data Documentation

Definition at line 79 of file SessionFactory.h.

Definition at line 82 of file SessionFactory.h.

Definition at line 80 of file SessionFactory.h.

Definition at line 81 of file SessionFactory.h.


The documentation for this class was generated from the following files:

Generated on Mon Sep 15 2014 01:23:57 for QuickFIX by doxygen 1.7.6.1 written by Dimitri van Heesch, © 1997-2001