QuickFIX: FIX::Acceptor Class Reference

Index Source Files Annotated Class List Alphabetical Class List Class Hierarchy Graphical Class Hierarchy

# FIX::Acceptor Class Reference

Base for classes which act as an acceptor for incoming connections. More...

`#include <Acceptor.h>`

Inheritance diagram for FIX::Acceptor:
[legend]
Collaboration diagram for FIX::Acceptor:
[legend]

List of all members.

## Public Member Functions
| Acceptor (Application &, MessageStoreFactory &, const SessionSettings &) throw ( ConfigError )
| Acceptor (Application &, MessageStoreFactory &, const SessionSettings &, LogFactory &) throw ( ConfigError )
virtual | ~Acceptor ()
Log * | getLog ()
void | start () throw ( ConfigError, RuntimeError )
| Start acceptor.
void | block () throw ( ConfigError, RuntimeError )
| Block on the acceptor.
bool | poll (double timeout=0.0) throw ( ConfigError, RuntimeError )
| Poll the acceptor.
void | stop (bool force=false)
| Stop acceptor.
bool | isLoggedOn ()
| Check to see if any sessions are currently logged on.
Session * | getSession (const std::string &msg, Responder &)
const std::set< SessionID > & | getSessions () const
Session * | getSession (const SessionID &sessionID) const
const Dictionary *const | getSessionSettings (const SessionID &sessionID) const
bool | has (const SessionID &id)
bool | isStopped ()
Application & | getApplication ()
MessageStoreFactory & | getMessageStoreFactory ()
## Private Types
typedef std::set< SessionID > | SessionIDs
typedef std::map< SessionID, Session * > | Sessions
## Private Member Functions
void | initialize () throw ( ConfigError )
virtual void | onConfigure (const SessionSettings &) throw ( ConfigError )
| Implemented to configure acceptor.
virtual void | onInitialize (const SessionSettings &) throw ( RuntimeError )
| Implemented to initialize acceptor.
virtual void | onStart ()=0
| Implemented to start listening for connections.
virtual bool | onPoll (double second)=0
| Implemented to connect and poll for events.
virtual void | onStop ()=0
| Implemented to stop a running acceptor.
## Static Private Member Functions
static THREAD_PROC | startThread (void *p)
## Private Attributes
thread_id | m_threadid
Sessions | m_sessions
SessionIDs | m_sessionIDs
Application & | m_application
MessageStoreFactory & | m_messageStoreFactory
SessionSettings | m_settings
LogFactory * | m_pLogFactory
Log * | m_pLog
NullLog | m_nullLog
bool | m_firstPoll
bool | m_stop

## Detailed Description

Base for classes which act as an acceptor for incoming connections.

Most users will not need to implement one of these. The default SocketAcceptor implementation will be used in most cases.

Definition at line 49 of file Acceptor.h.

## Member Typedef Documentation

typedef std::set< SessionID > FIX::Acceptor::SessionIDs`[private]`

Definition at line 109 of file Acceptor.h.

typedef std::map< SessionID, Session* > FIX::Acceptor::Sessions`[private]`

Reimplemented in FIX::SocketAcceptor, and FIX::ThreadedSocketAcceptor.

Definition at line 110 of file Acceptor.h.

## Constructor & Destructor Documentation

FIX::Acceptor::Acceptor | ( | Application & | application,
|  | MessageStoreFactory & | messageStoreFactory,
|  | const SessionSettings & | settings |
| ) |  |  | throw ( ConfigError )

Definition at line 37 of file Acceptor.cpp.

    00041   : m_threadid( 0 ),
    00042   m_application( application ),
    00043   m_messageStoreFactory( messageStoreFactory ),
    00044   m_settings( settings ),
    00045   m_pLogFactory( 0 ),
    00046   m_pLog( 0 ),
    00047   m_firstPoll( true ),
    00048   m_stop( true )
    00049 {
    00050   initialize();
    00051 }

FIX::Acceptor::Acceptor | ( | Application & | application,
|  | MessageStoreFactory & | messageStoreFactory,
|  | const SessionSettings & | settings,
|  | LogFactory & | logFactory |
| ) |  |  | throw ( ConfigError )

Definition at line 53 of file Acceptor.cpp.

    00058 : m_threadid( 0 ),
    00059   m_application( application ),
    00060   m_messageStoreFactory( messageStoreFactory ),
    00061   m_settings( settings ),
    00062   m_pLogFactory( &logFactory ),
    00063   m_pLog( logFactory.create() ),
    00064   m_firstPoll( true ),
    00065   m_stop( true )
    00066 {
    00067   initialize();
    00068 }

FIX::Acceptor::~Acceptor | ( |  | ) | `[virtual]`

Definition at line 97 of file Acceptor.cpp.

References FIX::LogFactory::destroy(), m_pLog, m_pLogFactory, m_sessions, QF_STACK_IGNORE_BEGIN, and QF_STACK_IGNORE_END.

    00098 { QF_STACK_IGNORE_BEGIN
    00099
    00100   Sessions::iterator i;
    00101   for ( i = m_sessions.begin(); i != m_sessions.end(); ++i )
    00102     delete i->second;
    00103
    00104   if( m_pLogFactory && m_pLog )
    00105     m_pLogFactory->destroy( m_pLog );
    00106
    00107   QF_STACK_IGNORE_END
    00108 }

## Member Function Documentation

void FIX::Acceptor::block | ( |  | ) | throw ( ConfigError, RuntimeError )

Block on the acceptor.

Definition at line 189 of file Acceptor.cpp.

References m_settings, m_stop, onConfigure(), onInitialize(), QF_STACK_POP, QF_STACK_PUSH, start(), and startThread().

    00190 { QF_STACK_PUSH( Acceptor::start )
    00191
    00192   m_stop = false;
    00193   onConfigure( m_settings );
    00194   onInitialize( m_settings );
    00195
    00196   startThread(this);
    00197
    00198   QF_STACK_POP
    00199 }

Application& FIX::Acceptor::getApplication | ( |  | ) | `[inline]`

Definition at line 89 of file Acceptor.h.

References m_application.

    00089 { return m_application; }

Log* FIX::Acceptor::getLog | ( |  | ) | `[inline]`

Definition at line 59 of file Acceptor.h.

References m_nullLog, and m_pLog.

Referenced by FIX::SocketAcceptor::onConnect(), and FIX::SocketConnection::read().

    00060   {
    00061     if( m_pLog ) return m_pLog;
    00062     return &m_nullLog;
    00063   }

MessageStoreFactory& FIX::Acceptor::getMessageStoreFactory | ( |  | ) | `[inline]`

Definition at line 90 of file Acceptor.h.

References m_messageStoreFactory.

    00091   { return m_messageStoreFactory; }

Session * FIX::Acceptor::getSession | ( | const SessionID & | sessionID | ) | const

Definition at line 147 of file Acceptor.cpp.

References FIX::Initiator::getSession(), m_sessions, QF_STACK_POP, and QF_STACK_PUSH.

    00148 { QF_STACK_PUSH(Initiator::getSession)
    00149
    00150   Sessions::const_iterator i = m_sessions.find( sessionID );
    00151   if( i != m_sessions.end() )
    00152     return i->second;
    00153   else
    00154     return 0;
    00155
    00156   QF_STACK_POP
    00157 }

Session * FIX::Acceptor::getSession | ( | const std::string & | msg,
|  | Responder & | responder |
| ) |  |  |

Definition at line 111 of file Acceptor.cpp.

References FIX::FIELD::BeginString, FIX::FieldMap::getField(), FIX::Message::getHeader(), FIX::FIELD::MsgType, QF_STACK_POP, QF_STACK_PUSH, FIX::FIELD::SenderCompID, FIX::Message::setStringHeader(), and FIX::FIELD::TargetCompID.

Referenced by FIX::SocketConnection::read().

    00112 { QF_STACK_PUSH( Acceptor::getSession )
    00113
    00114   Message message;
    00115   if ( !message.setStringHeader( msg ) )
    00116     return 0;
    00117
    00118   BeginString beginString;
    00119   SenderCompID clSenderCompID;
    00120   TargetCompID clTargetCompID;
    00121   MsgType msgType;
    00122   try
    00123   {
    00124     message.getHeader().getField( beginString );
    00125     message.getHeader().getField( clSenderCompID );
    00126     message.getHeader().getField( clTargetCompID );
    00127     message.getHeader().getField( msgType );
    00128     if ( msgType != "A" ) return 0;
    00129
    00130     SenderCompID senderCompID( clTargetCompID );
    00131     TargetCompID targetCompID( clSenderCompID );
    00132     SessionID sessionID( beginString, senderCompID, targetCompID );
    00133
    00134     Sessions::iterator i = m_sessions.find( sessionID );
    00135     if ( i != m_sessions.end() )
    00136     {
    00137       i->second->setResponder( &responder );
    00138       return i->second;
    00139     }
    00140   }
    00141   catch ( FieldNotFound& ) {}
    00142   return 0;
    00143
    00144   QF_STACK_POP
    00145 }

const std::set<SessionID>& FIX::Acceptor::getSessions | ( |  | ) | const`[inline]`

Definition at line 80 of file Acceptor.h.

References m_sessionIDs.

    00080 { return m_sessionIDs; }

const Dictionary *const FIX::Acceptor::getSessionSettings | ( | const SessionID & | sessionID | ) | const

Definition at line 159 of file Acceptor.cpp.

References FIX::SessionSettings::get(), FIX::Initiator::getSessionSettings(), m_settings, QF_STACK_POP, and QF_STACK_PUSH.

    00160 { QF_STACK_PUSH(Initiator::getSessionSettings)
    00161
    00162   try
    00163   {
    00164     return &m_settings.get( sessionID );
    00165   }
    00166   catch( ConfigError& )
    00167   {
    00168     return 0;
    00169   }
    00170
    00171   QF_STACK_POP
    00172 }

bool FIX::Acceptor::has | ( | const SessionID & | id | ) | `[inline]`

Definition at line 84 of file Acceptor.h.

References m_sessions.

    00085   { return m_sessions.find( id ) != m_sessions.end(); }

void FIX::Acceptor::initialize | ( |  | ) | throw ( ConfigError )`[private]`

Definition at line 70 of file Acceptor.cpp.

References FIX::CONNECTION_TYPE, FIX::SessionFactory::create(), FIX::SessionSettings::get(), FIX::SessionSettings::getSessions(), FIX::Dictionary::getString(), m_application, m_messageStoreFactory, m_pLogFactory, m_sessionIDs, m_sessions, m_settings, QF_STACK_POP, and QF_STACK_PUSH.

    00071 { QF_STACK_PUSH( Acceptor::initialize )
    00072
    00073   std::set < SessionID > sessions = m_settings.getSessions();
    00074   std::set < SessionID > ::iterator i;
    00075
    00076   if ( !sessions.size() )
    00077     throw ConfigError( "No sessions defined" );
    00078
    00079   SessionFactory factory( m_application, m_messageStoreFactory,
    00080                           m_pLogFactory );
    00081
    00082   for ( i = sessions.begin(); i != sessions.end(); ++i )
    00083   {
    00084     if ( m_settings.get( *i ).getString( CONNECTION_TYPE ) == "acceptor" )
    00085     {
    00086       m_sessionIDs.insert( *i );
    00087       m_sessions[ *i ] = factory.create( *i, m_settings.get( *i ) );
    00088     }
    00089   }
    00090
    00091   if ( !m_sessions.size() )
    00092     throw ConfigError( "No sessions defined for acceptor" );
    00093
    00094   QF_STACK_POP
    00095 }

bool FIX::Acceptor::isLoggedOn | ( |  | ) |

Check to see if any sessions are currently logged on.

Definition at line 257 of file Acceptor.cpp.

References m_sessions, QF_STACK_POP, and QF_STACK_PUSH.

Referenced by FIX::SocketAcceptor::onPoll(), FIX::SocketAcceptor::onStart(), FIX::ThreadedSocketAcceptor::onStop(), and stop().

    00258 { QF_STACK_PUSH(Acceptor::isLoggedOn)
    00259
    00260   Sessions sessions = m_sessions;
    00261   Sessions::iterator i = sessions.begin();
    00262   for ( ; i != sessions.end(); ++i )
    00263   {
    00264     if( i->second->isLoggedOn() )
    00265       return true;
    00266   }
    00267   return false;
    00268
    00269   QF_STACK_POP
    00270 }

bool FIX::Acceptor::isStopped | ( |  | ) | `[inline]`

Definition at line 87 of file Acceptor.h.

References m_stop.

Referenced by FIX::SocketAcceptor::onPoll(), FIX::SocketAcceptor::onStart(), and stop().

    00087 { return m_stop; }

virtual void FIX::Acceptor::onConfigure | ( | const SessionSettings & |  | ) | throw ( ConfigError )`[inline, private, virtual]`

Implemented to configure acceptor.

Reimplemented in FIX::SocketAcceptor, and FIX::ThreadedSocketAcceptor.

Definition at line 97 of file Acceptor.h.

Referenced by block(), and start().

    00097 {};

virtual void FIX::Acceptor::onInitialize | ( | const SessionSettings & |  | ) | throw ( RuntimeError )`[inline, private, virtual]`

Implemented to initialize acceptor.

Reimplemented in FIX::SocketAcceptor, and FIX::ThreadedSocketAcceptor.

Definition at line 99 of file Acceptor.h.

Referenced by block(), and start().

    00099 {};

virtual bool FIX::Acceptor::onPoll | ( | double | second | ) | `[private, pure virtual]`

Implemented to connect and poll for events.

Implemented in FIX::SocketAcceptor, and FIX::ThreadedSocketAcceptor.

virtual void FIX::Acceptor::onStart | ( |  | ) | `[private, pure virtual]`

Implemented to start listening for connections.

Implemented in FIX::SocketAcceptor, and FIX::ThreadedSocketAcceptor.

virtual void FIX::Acceptor::onStop | ( |  | ) | `[private, pure virtual]`

Implemented to stop a running acceptor.

Implemented in FIX::SocketAcceptor, and FIX::ThreadedSocketAcceptor.

Referenced by stop().

bool FIX::Acceptor::poll | ( | double | timeout = `0.0` | ) | throw ( ConfigError, RuntimeError )

Poll the acceptor.

Definition at line 201 of file Acceptor.cpp.

References QF_STACK_POP, and QF_STACK_PUSH.

    00202 { QF_STACK_PUSH( Acceptor::poll )
    00203
    00204   if( m_firstPoll )
    00205   {
    00206     onConfigure( m_settings );
    00207     onInitialize( m_settings );
    00208     m_firstPoll = false;
    00209   }
    00210
    00211   return onPoll( timeout );
    00212
    00213   QF_STACK_POP
    00214 }

void FIX::Acceptor::start | ( |  | ) | throw ( ConfigError, RuntimeError )

Start acceptor.

Definition at line 174 of file Acceptor.cpp.

References m_settings, m_stop, m_threadid, onConfigure(), onInitialize(), QF_STACK_POP, QF_STACK_PUSH, FIX::HttpServer::startGlobal(), startThread(), and FIX::thread_spawn().

Referenced by block(), FIX::SocketAcceptor::onPoll(), FIX::SocketAcceptor::onStart(), FIX::ThreadedSocketAcceptor::onStop(), and FIX::HttpServer::start().

    00175 { QF_STACK_PUSH( Acceptor::start )
    00176
    00177   m_stop = false;
    00178   onConfigure( m_settings );
    00179   onInitialize( m_settings );
    00180
    00181   HttpServer::startGlobal( m_settings );
    00182
    00183   if( !thread_spawn( &startThread, this, m_threadid ) )
    00184     throw RuntimeError("Unable to spawn thread");
    00185
    00186   QF_STACK_POP
    00187 }

THREAD_PROC FIX::Acceptor::startThread | ( | void * | p | ) | `[static, private]`

Definition at line 272 of file Acceptor.cpp.

References QF_STACK_CATCH, QF_STACK_POP, QF_STACK_PUSH, and QF_STACK_TRY.

Referenced by block(), and start().

    00273 { QF_STACK_TRY
    00274   QF_STACK_PUSH( Acceptor::startThread )
    00275
    00276   Acceptor * pAcceptor = static_cast < Acceptor* > ( p );
    00277   pAcceptor->onStart();
    00278   return 0;
    00279
    00280   QF_STACK_POP
    00281   QF_STACK_CATCH
    00282 }

void FIX::Acceptor::stop | ( | bool | force = `false` | ) |

Stop acceptor.

Definition at line 216 of file Acceptor.cpp.

References FIX::Session::getSessionID(), FIX::Session::isEnabled(), isLoggedOn(), isStopped(), FIX::Session::logout(), FIX::Session::lookupSession(), m_sessions, m_stop, m_threadid, onStop(), FIX::process_sleep(), QF_STACK_POP, QF_STACK_PUSH, FIX::HttpServer::stopGlobal(), FIX::thread_join(), and FIX::Session::unregisterSession().

    00217 { QF_STACK_PUSH( Acceptor::stop )
    00218
    00219   if( isStopped() ) return;
    00220
    00221   HttpServer::stopGlobal();
    00222
    00223   std::vector<Session*> enabledSessions;
    00224
    00225   Sessions sessions = m_sessions;
    00226   Sessions::iterator i = sessions.begin();
    00227   for ( ; i != sessions.end(); ++i )
    00228   {
    00229     Session* pSession = Session::lookupSession(i->first);
    00230     if( pSession->isEnabled() )
    00231     {
    00232       enabledSessions.push_back( pSession );
    00233       pSession->logout();
    00234       Session::unregisterSession( pSession->getSessionID() );
    00235     }
    00236   }
    00237
    00238   if( !force )
    00239   {
    00240     for ( int second = 1; second <= 10 && isLoggedOn(); ++second )
    00241       process_sleep( 1 );
    00242   }
    00243
    00244   m_stop = true;
    00245   onStop();
    00246   if( m_threadid )
    00247     thread_join( m_threadid );
    00248   m_threadid = 0;
    00249
    00250   std::vector<Session*>::iterator session = enabledSessions.begin();
    00251   for( ; session != enabledSessions.end(); ++session )
    00252     (*session)->logon();
    00253
    00254   QF_STACK_POP
    00255 }

## Member Data Documentation

Application& FIX::Acceptor::m_application`[private]`

Definition at line 115 of file Acceptor.h.

Referenced by getApplication(), and initialize().

bool FIX::Acceptor::m_firstPoll`[private]`

Definition at line 121 of file Acceptor.h.

MessageStoreFactory& FIX::Acceptor::m_messageStoreFactory`[private]`

Definition at line 116 of file Acceptor.h.

Referenced by getMessageStoreFactory(), and initialize().

NullLog FIX::Acceptor::m_nullLog`[private]`

Definition at line 120 of file Acceptor.h.

Referenced by getLog().

Log* FIX::Acceptor::m_pLog`[private]`

Definition at line 119 of file Acceptor.h.

Referenced by getLog(), and ~Acceptor().

LogFactory* FIX::Acceptor::m_pLogFactory`[private]`

Definition at line 118 of file Acceptor.h.

Referenced by initialize(), and ~Acceptor().

SessionIDs FIX::Acceptor::m_sessionIDs`[private]`

Definition at line 114 of file Acceptor.h.

Referenced by getSessions(), and initialize().

Sessions FIX::Acceptor::m_sessions`[private]`

Definition at line 113 of file Acceptor.h.

Referenced by getSession(), has(), initialize(), isLoggedOn(), stop(), and ~Acceptor().

SessionSettings FIX::Acceptor::m_settings`[private]`

Definition at line 117 of file Acceptor.h.

Referenced by block(), getSessionSettings(), initialize(), and start().

bool FIX::Acceptor::m_stop`[private]`

Definition at line 122 of file Acceptor.h.

Referenced by block(), isStopped(), start(), and stop().

thread_id FIX::Acceptor::m_threadid`[private]`

Definition at line 112 of file Acceptor.h.

Referenced by start(), and stop().

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

- /home/omiller/Development/autobuild/quickfix/src/C++/Acceptor.h
- /home/omiller/Development/autobuild/quickfix/src/C++/Acceptor.cpp