Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
FIX::SessionFactory Class Reference

Responsible for creating Session objects. More...

#include <SessionFactory.h>

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

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

◆ Dictionaries

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

Definition at line 63 of file SessionFactory.h.

Constructor & Destructor Documentation

◆ SessionFactory()

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

Definition at line 49 of file SessionFactory.h.

References create(), destroy(), and ~SessionFactory().

52 : m_application( application ),
53  m_messageStoreFactory( messageStoreFactory ),
54  m_pLogFactory( pLogFactory ) {}
LogFactory * m_pLogFactory
MessageStoreFactory & m_messageStoreFactory
Application & m_application

◆ ~SessionFactory()

FIX::SessionFactory::~SessionFactory ( )

Definition at line 37 of file SessionFactory.cpp.

Referenced by SessionFactory().

38 {
39 }

Member Function Documentation

◆ create()

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::FIELD::HeartBtInt, FIX::HEARTBTINT, FIX::TimeRange::isInRange(), FIX::LOGON_DAY, FIX::LOGON_TIME, FIX::LOGON_TIMEOUT, FIX::LOGOUT_DAY, FIX::LOGOUT_TIME, FIX::LOGOUT_TIMEOUT, m_application, m_messageStoreFactory, m_pLogFactory, FIX::MAX_LATENCY, FIX::MILLISECONDS_IN_TIMESTAMP, FIX::PERSIST_MESSAGES, processFixDataDictionary(), processFixtDataDictionaries(), 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::TIMESTAMP_PRECISION, FIX::Message::toApplVerID(), FIX::USE_DATA_DICTIONARY, FIX::USE_LOCAL_TIME, and FIX::VALIDATE_LENGTH_AND_CHECKSUM.

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

43 {
44  std::string connectionType = settings.getString( CONNECTION_TYPE );
45  if ( connectionType != "acceptor" && connectionType != "initiator" )
46  throw ConfigError( "Invalid ConnectionType" );
47 
48  if( connectionType == "acceptor" && settings.has(SESSION_QUALIFIER) )
49  throw ConfigError( "SessionQualifier cannot be used with acceptor." );
50 
51  bool useDataDictionary = true;
52  if ( settings.has( USE_DATA_DICTIONARY ) )
53  useDataDictionary = settings.getBool( USE_DATA_DICTIONARY );
54 
55  std::string defaultApplVerID;
56  if( sessionID.isFIXT() )
57  {
58  if( !settings.has(DEFAULT_APPLVERID) )
59  {
60  throw ConfigError("ApplVerID is required for FIXT transport");
61  }
62  defaultApplVerID = Message::toApplVerID( settings.getString(DEFAULT_APPLVERID) );
63  }
64 
65  DataDictionaryProvider dataDictionaryProvider;
66  if( useDataDictionary )
67  {
68  if( sessionID.isFIXT() )
69  {
70  processFixtDataDictionaries(sessionID, settings, dataDictionaryProvider);
71  }
72  else
73  {
74  processFixDataDictionary(sessionID, settings, dataDictionaryProvider);
75  }
76  }
77 
78  bool useLocalTime = false;
79  if( settings.has(USE_LOCAL_TIME) )
80  useLocalTime = settings.getBool( USE_LOCAL_TIME );
81 
82  int startDay = -1;
83  int endDay = -1;
84  try
85  {
86  startDay = settings.getDay( START_DAY );
87  endDay = settings.getDay( END_DAY );
88  }
89  catch( ConfigError & ) {}
90  catch( FieldConvertError & e ) { throw ConfigError( e.what() ); }
91 
92  UtcTimeOnly startTime;
93  UtcTimeOnly endTime;
94  try
95  {
97  ( settings.getString( START_TIME ) );
99  ( settings.getString( END_TIME ) );
100  }
101  catch ( FieldConvertError & e ) { throw ConfigError( e.what() ); }
102 
103  TimeRange utcSessionTime
104  ( startTime, endTime, startDay, endDay );
105  TimeRange localSessionTime
106  ( LocalTimeOnly(startTime.getHour(), startTime.getMinute(), startTime.getSecond()),
107  LocalTimeOnly(endTime.getHour(), endTime.getMinute(), endTime.getSecond()),
108  startDay, endDay );
109  TimeRange sessionTimeRange = useLocalTime ? localSessionTime : utcSessionTime;
110 
111  if( startDay >= 0 && endDay < 0 )
112  throw ConfigError( "StartDay used without EndDay" );
113  if( endDay >= 0 && startDay < 0 )
114  throw ConfigError( "EndDay used without StartDay" );
115 
116  HeartBtInt heartBtInt( 0 );
117  if ( connectionType == "initiator" )
118  {
119  heartBtInt = HeartBtInt( settings.getInt( HEARTBTINT ) );
120  if ( heartBtInt <= 0 ) throw ConfigError( "Heartbeat must be greater than zero" );
121  }
122 
123  SmartPtr<Session> pSession;
124  pSession.reset( new Session( m_application, m_messageStoreFactory,
125  sessionID, dataDictionaryProvider, sessionTimeRange,
126  heartBtInt, m_pLogFactory ) );
127 
128  pSession->setSenderDefaultApplVerID(defaultApplVerID);
129 
130  int logonDay = startDay;
131  int logoutDay = endDay;
132  try
133  {
134  logonDay = settings.getDay( LOGON_DAY );
135  logoutDay = settings.getDay( LOGOUT_DAY );
136  }
137  catch( ConfigError & ) {}
138  catch( FieldConvertError & e ) { throw ConfigError( e.what() ); }
139 
140  UtcTimeOnly logonTime( startTime );
141  UtcTimeOnly logoutTime( endTime );
142  try
143  {
145  ( settings.getString( LOGON_TIME ) );
146  }
147  catch( ConfigError & ) {}
148  catch( FieldConvertError & e ) { throw ConfigError( e.what() ); }
149  try
150  {
151  logoutTime = UtcTimeOnlyConvertor::convert
152  ( settings.getString( LOGOUT_TIME ) );
153  }
154  catch( ConfigError & ) {}
155  catch( FieldConvertError & e ) { throw ConfigError( e.what() ); }
156 
157  TimeRange utcLogonTime
158  ( logonTime, logoutTime, logonDay, logoutDay );
159  TimeRange localLogonTime
160  ( LocalTimeOnly(logonTime.getHour(), logonTime.getMinute(), logonTime.getSecond()),
161  LocalTimeOnly(logoutTime.getHour(), logoutTime.getMinute(), logoutTime.getSecond()),
162  logonDay, logoutDay );
163  TimeRange logonTimeRange = useLocalTime ? localLogonTime : utcLogonTime;
164 
165  if( !sessionTimeRange.isInRange(logonTime, logonDay) )
166  throw ConfigError( "LogonTime must be between StartTime and EndTime" );
167  if( !sessionTimeRange.isInRange(logoutTime, logoutDay) )
168  throw ConfigError( "LogoutTime must be between StartTime and EndTime" );
169  pSession->setLogonTime( logonTimeRange );
170 
171  if ( settings.has( SEND_REDUNDANT_RESENDREQUESTS ) )
172  pSession->setSendRedundantResendRequests( settings.getBool( SEND_REDUNDANT_RESENDREQUESTS ) );
173  if ( settings.has( CHECK_COMPID ) )
174  pSession->setCheckCompId( settings.getBool( CHECK_COMPID ) );
175  if ( settings.has( CHECK_LATENCY ) )
176  pSession->setCheckLatency( settings.getBool( CHECK_LATENCY ) );
177  if ( settings.has( MAX_LATENCY ) )
178  pSession->setMaxLatency( settings.getInt( MAX_LATENCY ) );
179  if ( settings.has( LOGON_TIMEOUT ) )
180  pSession->setLogonTimeout( settings.getInt( LOGON_TIMEOUT ) );
181  if ( settings.has( LOGOUT_TIMEOUT ) )
182  pSession->setLogoutTimeout( settings.getInt( LOGOUT_TIMEOUT ) );
183  if ( settings.has( RESET_ON_LOGON ) )
184  pSession->setResetOnLogon( settings.getBool( RESET_ON_LOGON ) );
185  if ( settings.has( RESET_ON_LOGOUT ) )
186  pSession->setResetOnLogout( settings.getBool( RESET_ON_LOGOUT ) );
187  if ( settings.has( RESET_ON_DISCONNECT ) )
188  pSession->setResetOnDisconnect( settings.getBool( RESET_ON_DISCONNECT ) );
189  if ( settings.has( REFRESH_ON_LOGON ) )
190  pSession->setRefreshOnLogon( settings.getBool( REFRESH_ON_LOGON ) );
191  if ( settings.has( MILLISECONDS_IN_TIMESTAMP ) )
192  pSession->setTimestampPrecision(3);
193  if ( settings.has( TIMESTAMP_PRECISION ) )
194  pSession->setTimestampPrecision(settings.getInt( TIMESTAMP_PRECISION ) );
195  if ( settings.has( PERSIST_MESSAGES ) )
196  pSession->setPersistMessages( settings.getBool( PERSIST_MESSAGES ) );
197  if ( settings.has( VALIDATE_LENGTH_AND_CHECKSUM ) )
198  pSession->setValidateLengthAndChecksum( settings.getBool( VALIDATE_LENGTH_AND_CHECKSUM ) );
199 
200  return pSession.release();
201 }
const char TIMESTAMP_PRECISION[]
const char LOGON_TIMEOUT[]
static std::string convert(const UtcTimeOnly &value, int precision=0)
const char RESET_ON_LOGON[]
const char RESET_ON_DISCONNECT[]
const char LOGOUT_DAY[]
LogFactory * m_pLogFactory
const int HeartBtInt
const char RESET_ON_LOGOUT[]
const char CONNECTION_TYPE[]
const char LOGOUT_TIME[]
const char MAX_LATENCY[]
const char DEFAULT_APPLVERID[]
static ApplVerID toApplVerID(const BeginString &value)
Definition: Message.h:307
void processFixDataDictionary(const SessionID &sessionID, const Dictionary &settings, DataDictionaryProvider &provider)
const char SEND_REDUNDANT_RESENDREQUESTS[]
const char SESSION_QUALIFIER[]
const char LOGON_TIME[]
MessageStoreFactory & m_messageStoreFactory
const char END_TIME[]
void processFixtDataDictionaries(const SessionID &sessionID, const Dictionary &settings, DataDictionaryProvider &provider)
const char END_DAY[]
const char START_DAY[]
const char CHECK_COMPID[]
Application & m_application
const char VALIDATE_LENGTH_AND_CHECKSUM[]
const char LOGOUT_TIMEOUT[]
const char START_TIME[]
const char LOGON_DAY[]
const char MILLISECONDS_IN_TIMESTAMP[]
const char USE_DATA_DICTIONARY[]
const char USE_LOCAL_TIME[]
const char PERSIST_MESSAGES[]
const char HEARTBTINT[]
const char CHECK_LATENCY[]
const char REFRESH_ON_LOGON[]

◆ createDataDictionary()

ptr::shared_ptr< DataDictionary > FIX::SessionFactory::createDataDictionary ( const SessionID sessionID,
const Dictionary settings,
const std::string &  settingsKey 
)
throw (ConfigError
)
private

Definition at line 208 of file SessionFactory.cpp.

References FIX::ALLOW_UNKNOWN_MSG_FIELDS, m_dictionaries, FIX::PRESERVE_MESSAGE_FIELDS_ORDER, FIX::VALIDATE_FIELDS_HAVE_VALUES, FIX::VALIDATE_FIELDS_OUT_OF_ORDER, and FIX::VALIDATE_USER_DEFINED_FIELDS.

Referenced by processFixDataDictionary(), and processFixtDataDictionaries().

211 {
212  ptr::shared_ptr<DataDictionary> pDD;
213  std::string path = settings.getString( settingsKey );
214  Dictionaries::iterator i = m_dictionaries.find( path );
215  if ( i != m_dictionaries.end() )
216  {
217  pDD = i->second;
218  }
219  else
220  {
221  bool preserveMsgFldsOrder = false;
222  if( settings.has( PRESERVE_MESSAGE_FIELDS_ORDER ) )
223  preserveMsgFldsOrder = settings.getBool( PRESERVE_MESSAGE_FIELDS_ORDER );
224  pDD = ptr::shared_ptr<DataDictionary>(new DataDictionary( path, preserveMsgFldsOrder ));
225  m_dictionaries[ path ] = pDD;
226  }
227 
228  ptr::shared_ptr<DataDictionary> pCopyOfDD = ptr::shared_ptr<DataDictionary>(new DataDictionary(*pDD));
229 
230  if( settings.has( VALIDATE_FIELDS_OUT_OF_ORDER ) )
231  pCopyOfDD->checkFieldsOutOfOrder( settings.getBool( VALIDATE_FIELDS_OUT_OF_ORDER ) );
232  if( settings.has( VALIDATE_FIELDS_HAVE_VALUES ) )
233  pCopyOfDD->checkFieldsHaveValues( settings.getBool( VALIDATE_FIELDS_HAVE_VALUES ) );
234  if( settings.has( VALIDATE_USER_DEFINED_FIELDS ) )
235  pCopyOfDD->checkUserDefinedFields( settings.getBool( VALIDATE_USER_DEFINED_FIELDS ) );
236  if( settings.has( ALLOW_UNKNOWN_MSG_FIELDS ) )
237  pCopyOfDD->allowUnknownMsgFields( settings.getBool( ALLOW_UNKNOWN_MSG_FIELDS ) );
238 
239  return pCopyOfDD;
240 }
const char PRESERVE_MESSAGE_FIELDS_ORDER[]
const char VALIDATE_FIELDS_HAVE_VALUES[]
const char VALIDATE_FIELDS_OUT_OF_ORDER[]
const char VALIDATE_USER_DEFINED_FIELDS[]
Dictionaries m_dictionaries
const char ALLOW_UNKNOWN_MSG_FIELDS[]

◆ destroy()

void FIX::SessionFactory::destroy ( Session pSession)

Definition at line 203 of file SessionFactory.cpp.

Referenced by SessionFactory().

204 {
205  delete pSession;
206 }

◆ processFixDataDictionary()

void FIX::SessionFactory::processFixDataDictionary ( const SessionID sessionID,
const Dictionary settings,
DataDictionaryProvider provider 
)
throw (ConfigError
)
private

Definition at line 273 of file SessionFactory.cpp.

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

Referenced by create().

276 {
277  ptr::shared_ptr<DataDictionary> pDataDictionary = createDataDictionary(sessionID, settings, DATA_DICTIONARY);
278  provider.addTransportDataDictionary(sessionID.getBeginString(), pDataDictionary);
279  provider.addApplicationDataDictionary(Message::toApplVerID(sessionID.getBeginString()), pDataDictionary);
280 }
ptr::shared_ptr< DataDictionary > createDataDictionary(const SessionID &sessionID, const Dictionary &settings, const std::string &settingsKey)
static ApplVerID toApplVerID(const BeginString &value)
Definition: Message.h:307
const char DATA_DICTIONARY[]

◆ processFixtDataDictionaries()

void FIX::SessionFactory::processFixtDataDictionaries ( const SessionID sessionID,
const Dictionary settings,
DataDictionaryProvider provider 
)
throw (ConfigError
)
private

Definition at line 242 of file SessionFactory.cpp.

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

Referenced by create().

245 {
246  ptr::shared_ptr<DataDictionary> pDataDictionary = createDataDictionary(sessionID, settings, TRANSPORT_DATA_DICTIONARY);
247  provider.addTransportDataDictionary(sessionID.getBeginString(), pDataDictionary);
248 
249  for(Dictionary::const_iterator data = settings.begin(); data != settings.end(); ++data)
250  {
251  const std::string& key = data->first;
252  const std::string frontKey = key.substr(0, strlen(APP_DATA_DICTIONARY));
253  if( frontKey == string_toUpper(APP_DATA_DICTIONARY) )
254  {
255  if( key == string_toUpper(APP_DATA_DICTIONARY) )
256  {
257  provider.addApplicationDataDictionary(Message::toApplVerID(settings.getString(DEFAULT_APPLVERID)),
258  createDataDictionary(sessionID, settings, APP_DATA_DICTIONARY));
259  }
260  else
261  {
262  std::string::size_type offset = key.find('.');
263  if( offset == std::string::npos )
264  throw ConfigError(std::string("Malformed ") + APP_DATA_DICTIONARY + ": " + key);
265  std::string beginStringQualifier = key.substr(offset+1);
266  provider.addApplicationDataDictionary(Message::toApplVerID(beginStringQualifier),
267  createDataDictionary(sessionID, settings, key));
268  }
269  }
270  }
271 }
ptr::shared_ptr< DataDictionary > createDataDictionary(const SessionID &sessionID, const Dictionary &settings, const std::string &settingsKey)
const char DEFAULT_APPLVERID[]
static ApplVerID toApplVerID(const BeginString &value)
Definition: Message.h:307
const char TRANSPORT_DATA_DICTIONARY[]
std::string string_toUpper(const std::string &value)
Definition: Utility.cpp:53
iterator const_iterator
Definition: Dictionary.h:45
const char APP_DATA_DICTIONARY[]

◆ toApplVerID()

std::string FIX::SessionFactory::toApplVerID ( const std::string &  value)
private

Member Data Documentation

◆ m_application

Application& FIX::SessionFactory::m_application
private

Definition at line 79 of file SessionFactory.h.

Referenced by create().

◆ m_dictionaries

Dictionaries FIX::SessionFactory::m_dictionaries
private

Definition at line 82 of file SessionFactory.h.

Referenced by createDataDictionary().

◆ m_messageStoreFactory

MessageStoreFactory& FIX::SessionFactory::m_messageStoreFactory
private

Definition at line 80 of file SessionFactory.h.

Referenced by create().

◆ m_pLogFactory

LogFactory* FIX::SessionFactory::m_pLogFactory
private

Definition at line 81 of file SessionFactory.h.

Referenced by create().


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

Generated on Sun Apr 15 2018 21:44:06 for QuickFIX by doxygen 1.8.13 written by Dimitri van Heesch, © 1997-2001