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,
DataDictionary * > 
Dictionaries
 

Private Member Functions

const 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, 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.

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

Definition at line 37 of file SessionFactory.cpp.

References m_dictionaries.

38 {
39  Dictionaries::iterator i = m_dictionaries.begin();
40  for ( ; i != m_dictionaries.end(); ++i )
41  delete i->second;
42 }
Dictionaries m_dictionaries

Member Function Documentation

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

Definition at line 44 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().

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

Definition at line 209 of file SessionFactory.cpp.

References FIX::DataDictionary::checkFieldsHaveValues(), FIX::DataDictionary::checkFieldsOutOfOrder(), FIX::DataDictionary::checkUserDefinedFields(), FIX::VALIDATE_FIELDS_HAVE_VALUES, FIX::VALIDATE_FIELDS_OUT_OF_ORDER, and FIX::VALIDATE_USER_DEFINED_FIELDS.

212 {
213  DataDictionary * pDD = 0;
214  std::string path = settings.getString( settingsKey );
215  Dictionaries::iterator i = m_dictionaries.find( path );
216  if ( i != m_dictionaries.end() )
217  {
218  pDD = i->second;
219  }
220  else
221  {
222  pDD = new DataDictionary( path );
223  m_dictionaries[ path ] = pDD;
224  }
225 
226  DataDictionary * pCopyOfDD = new DataDictionary(*pDD);
227 
228  if( settings.has( VALIDATE_FIELDS_OUT_OF_ORDER ) )
229  pCopyOfDD->checkFieldsOutOfOrder( settings.getBool( VALIDATE_FIELDS_OUT_OF_ORDER ) );
230  if( settings.has( VALIDATE_FIELDS_HAVE_VALUES ) )
231  pCopyOfDD->checkFieldsHaveValues( settings.getBool( VALIDATE_FIELDS_HAVE_VALUES ) );
232  if( settings.has( VALIDATE_USER_DEFINED_FIELDS ) )
233  pCopyOfDD->checkUserDefinedFields( settings.getBool( VALIDATE_USER_DEFINED_FIELDS ) );
234 
235  return pCopyOfDD;
236 }
const char VALIDATE_FIELDS_HAVE_VALUES[]
const char VALIDATE_FIELDS_OUT_OF_ORDER[]
const char VALIDATE_USER_DEFINED_FIELDS[]
Dictionaries m_dictionaries
void FIX::SessionFactory::destroy ( Session pSession)

Definition at line 204 of file SessionFactory.cpp.

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

Definition at line 269 of file SessionFactory.cpp.

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

272 {
273  const DataDictionary * pDataDictionary = createDataDictionary(sessionID, settings, DATA_DICTIONARY);
274  provider.addTransportDataDictionary(sessionID.getBeginString(), pDataDictionary);
275  provider.addApplicationDataDictionary(Message::toApplVerID(sessionID.getBeginString()), pDataDictionary);
276 }
static ApplVerID toApplVerID(const BeginString &value)
Definition: Message.h:257
const char DATA_DICTIONARY[]
const DataDictionary * createDataDictionary(const SessionID &sessionID, const Dictionary &settings, const std::string &settingsKey)
void FIX::SessionFactory::processFixtDataDictionaries ( const SessionID sessionID,
const Dictionary settings,
DataDictionaryProvider provider 
)
throw (ConfigError
)
private

Definition at line 238 of file SessionFactory.cpp.

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

241 {
242  const DataDictionary * pDataDictionary = createDataDictionary(sessionID, settings, TRANSPORT_DATA_DICTIONARY);
243  provider.addTransportDataDictionary(sessionID.getBeginString(), pDataDictionary);
244 
245  for(Dictionary::const_iterator data = settings.begin(); data != settings.end(); ++data)
246  {
247  const std::string& key = data->first;
248  const std::string frontKey = key.substr(0, strlen(APP_DATA_DICTIONARY));
249  if( frontKey == string_toUpper(APP_DATA_DICTIONARY) )
250  {
251  if( key == string_toUpper(APP_DATA_DICTIONARY) )
252  {
253  provider.addApplicationDataDictionary(Message::toApplVerID(settings.getString(DEFAULT_APPLVERID)),
254  createDataDictionary(sessionID, settings, APP_DATA_DICTIONARY));
255  }
256  else
257  {
258  std::string::size_type offset = key.find('.');
259  if( offset == std::string::npos )
260  throw ConfigError(std::string("Malformed ") + APP_DATA_DICTIONARY + ": " + key);
261  std::string beginStringQualifier = key.substr(offset+1);
262  provider.addApplicationDataDictionary(Message::toApplVerID(beginStringQualifier),
263  createDataDictionary(sessionID, settings, key));
264  }
265  }
266  }
267 }
const char DEFAULT_APPLVERID[]
static ApplVerID toApplVerID(const BeginString &value)
Definition: Message.h:257
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 DataDictionary * createDataDictionary(const SessionID &sessionID, const Dictionary &settings, const std::string &settingsKey)
const char APP_DATA_DICTIONARY[]
std::string FIX::SessionFactory::toApplVerID ( const std::string &  value)
private

Member Data Documentation

Application& FIX::SessionFactory::m_application
private

Definition at line 79 of file SessionFactory.h.

Dictionaries FIX::SessionFactory::m_dictionaries
private

Definition at line 82 of file SessionFactory.h.

Referenced by ~SessionFactory().

MessageStoreFactory& FIX::SessionFactory::m_messageStoreFactory
private

Definition at line 80 of file SessionFactory.h.

LogFactory* FIX::SessionFactory::m_pLogFactory
private

Definition at line 81 of file SessionFactory.h.


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

Generated on Sat Mar 29 2014 15:13:35 for QuickFIX by doxygen 1.8.5 written by Dimitri van Heesch, © 1997-2001