Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes
FIX::Acceptor Class Reference

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

#include <Acceptor.h>

Inheritance diagram for FIX::Acceptor:
Inheritance graph
[legend]
Collaboration diagram for FIX::Acceptor:
Collaboration graph
[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 ()
LoggetLog ()
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.
SessiongetSession (const std::string &msg, Responder &)
const std::set< SessionID > & getSessions () const
SessiongetSession (const SessionID &sessionID) const
const Dictionary *const getSessionSettings (const SessionID &sessionID) const
bool has (const SessionID &id)
bool isStopped ()
ApplicationgetApplication ()
MessageStoreFactorygetMessageStoreFactory ()

Private Types

typedef std::set< SessionIDSessionIDs
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
Applicationm_application
MessageStoreFactorym_messageStoreFactory
SessionSettings m_settings
LogFactorym_pLogFactory
Logm_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::ThreadedSocketAcceptor, and FIX::SocketAcceptor.

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 36 of file Acceptor.cpp.

  : m_threadid( 0 ),
  m_application( application ),
  m_messageStoreFactory( messageStoreFactory ),
  m_settings( settings ),
  m_pLogFactory( 0 ),
  m_pLog( 0 ),
  m_firstPoll( true ),
  m_stop( true )
{
  initialize();
}
FIX::Acceptor::Acceptor ( Application application,
MessageStoreFactory messageStoreFactory,
const SessionSettings settings,
LogFactory logFactory 
) throw ( ConfigError )

Definition at line 52 of file Acceptor.cpp.

: m_threadid( 0 ),
  m_application( application ),
  m_messageStoreFactory( messageStoreFactory ),
  m_settings( settings ),
  m_pLogFactory( &logFactory ),
  m_pLog( logFactory.create() ),
  m_firstPoll( true ),
  m_stop( true )
{
  initialize();
}
FIX::Acceptor::~Acceptor ( ) [virtual]

Definition at line 93 of file Acceptor.cpp.

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

{
  Sessions::iterator i;
  for ( i = m_sessions.begin(); i != m_sessions.end(); ++i )
    delete i->second;

  if( m_pLogFactory && m_pLog )
    m_pLogFactory->destroy( m_pLog );
}

Member Function Documentation

Block on the acceptor.

Definition at line 170 of file Acceptor.cpp.

References m_settings, m_stop, onConfigure(), onInitialize(), and startThread().

Definition at line 89 of file Acceptor.h.

References m_application.

{ 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().

  { 
    if( m_pLog ) return m_pLog;
    return &m_nullLog;
  }

Definition at line 90 of file Acceptor.h.

References m_messageStoreFactory.

  { return m_messageStoreFactory; }
Session * FIX::Acceptor::getSession ( const std::string &  msg,
Responder responder 
)

Definition at line 104 of file Acceptor.cpp.

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

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

{
  Message message;
  if ( !message.setStringHeader( msg ) )
    return 0;

  BeginString beginString;
  SenderCompID clSenderCompID;
  TargetCompID clTargetCompID;
  MsgType msgType;
  try
  {
    message.getHeader().getField( beginString );
    message.getHeader().getField( clSenderCompID );
    message.getHeader().getField( clTargetCompID );
    message.getHeader().getField( msgType );
    if ( msgType != "A" ) return 0;

    SenderCompID senderCompID( clTargetCompID );
    TargetCompID targetCompID( clSenderCompID );
    SessionID sessionID( beginString, senderCompID, targetCompID );

    Sessions::iterator i = m_sessions.find( sessionID );
    if ( i != m_sessions.end() )
    {
      i->second->setResponder( &responder );
      return i->second;
    }
  }
  catch ( FieldNotFound& ) {}
  return 0;
}
Session * FIX::Acceptor::getSession ( const SessionID sessionID) const

Definition at line 137 of file Acceptor.cpp.

References m_sessions.

{
  Sessions::const_iterator i = m_sessions.find( sessionID );
  if( i != m_sessions.end() )
    return i->second;
  else
    return 0;
}
const std::set<SessionID>& FIX::Acceptor::getSessions ( ) const [inline]

Definition at line 80 of file Acceptor.h.

References m_sessionIDs.

{ return m_sessionIDs; }
const Dictionary *const FIX::Acceptor::getSessionSettings ( const SessionID sessionID) const

Definition at line 146 of file Acceptor.cpp.

References FIX::SessionSettings::get(), and m_settings.

{
  try
  {
    return &m_settings.get( sessionID );
  }
  catch( ConfigError& )
  {
    return 0;
  }
}
bool FIX::Acceptor::has ( const SessionID id) [inline]

Definition at line 84 of file Acceptor.h.

References m_sessions.

  { return m_sessions.find( id ) != m_sessions.end(); }
void FIX::Acceptor::initialize ( ) throw ( ConfigError ) [private]

Definition at line 69 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, and m_settings.

{
  std::set < SessionID > sessions = m_settings.getSessions();
  std::set < SessionID > ::iterator i;

  if ( !sessions.size() )
    throw ConfigError( "No sessions defined" );

  SessionFactory factory( m_application, m_messageStoreFactory,
                          m_pLogFactory );

  for ( i = sessions.begin(); i != sessions.end(); ++i )
  {
    if ( m_settings.get( *i ).getString( CONNECTION_TYPE ) == "acceptor" )
    {
      m_sessionIDs.insert( *i );
      m_sessions[ *i ] = factory.create( *i, m_settings.get( *i ) );
    }
  }

  if ( !m_sessions.size() )
    throw ConfigError( "No sessions defined for acceptor" );
}

Check to see if any sessions are currently logged on.

Definition at line 230 of file Acceptor.cpp.

References m_sessions.

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

{
  Sessions sessions = m_sessions;
  Sessions::iterator i = sessions.begin();
  for ( ; i != sessions.end(); ++i )
  {
    if( i->second->isLoggedOn() )
      return true;
  }
  return false;
}
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().

{ return m_stop; }
virtual void FIX::Acceptor::onConfigure ( const SessionSettings ) throw ( ConfigError ) [inline, private, virtual]

Implemented to configure acceptor.

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

Definition at line 97 of file Acceptor.h.

Referenced by block(), and start().

{};
virtual void FIX::Acceptor::onInitialize ( const SessionSettings ) throw ( RuntimeError ) [inline, private, virtual]

Implemented to initialize acceptor.

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

Definition at line 99 of file Acceptor.h.

Referenced by block(), and start().

{};
virtual bool FIX::Acceptor::onPoll ( double  second) [private, pure virtual]

Implemented to connect and poll for events.

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

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

Implemented to start listening for connections.

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

Referenced by startThread().

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

Implemented to stop a running acceptor.

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

Referenced by stop().

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

Poll the acceptor.

Definition at line 179 of file Acceptor.cpp.

{
  if( m_firstPoll )
  {
    m_stop = false;
    onConfigure( m_settings );
    onInitialize( m_settings );
    m_firstPoll = false;
  }

  return onPoll( timeout );
}
THREAD_PROC FIX::Acceptor::startThread ( void *  p) [static, private]

Definition at line 242 of file Acceptor.cpp.

References onStart().

Referenced by block(), and start().

{
  Acceptor * pAcceptor = static_cast < Acceptor* > ( p );
  pAcceptor->onStart();
  return 0;
}
void FIX::Acceptor::stop ( bool  force = false)

Stop acceptor.

Definition at line 192 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(), FIX::HttpServer::stopGlobal(), FIX::thread_join(), and FIX::Session::unregisterSession().

{
  if( isStopped() ) return;

  HttpServer::stopGlobal();

  std::vector<Session*> enabledSessions;

  Sessions sessions = m_sessions;
  Sessions::iterator i = sessions.begin();
  for ( ; i != sessions.end(); ++i )
  {
    Session* pSession = Session::lookupSession(i->first);
    if( pSession && pSession->isEnabled() )
    {
      enabledSessions.push_back( pSession );
      pSession->logout();
      Session::unregisterSession( pSession->getSessionID() );
    }
  }

  if( !force )
  {
    for ( int second = 1; second <= 10 && isLoggedOn(); ++second )
      process_sleep( 1 );
  }

  m_stop = true;
  onStop();
  if( m_threadid )
    thread_join( m_threadid );
  m_threadid = 0;

  std::vector<Session*>::iterator session = enabledSessions.begin();
  for( ; session != enabledSessions.end(); ++session )
    (*session)->logon();
}

Member Data Documentation

Definition at line 115 of file Acceptor.h.

Referenced by getApplication(), and initialize().

Definition at line 121 of file Acceptor.h.

Definition at line 116 of file Acceptor.h.

Referenced by getMessageStoreFactory(), and initialize().

Definition at line 120 of file Acceptor.h.

Referenced by getLog().

Definition at line 119 of file Acceptor.h.

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

Definition at line 118 of file Acceptor.h.

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

Definition at line 114 of file Acceptor.h.

Referenced by getSessions(), and initialize().

Definition at line 113 of file Acceptor.h.

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

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().

Definition at line 112 of file Acceptor.h.

Referenced by start(), and stop().


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

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