FIXStandaloneApplication
FIXStandaloneApplication is very easy to program.
In this chapter will will demonstrate step by step how to write a standalone
QWFIX application.
Initialization
At the begining of your program you may need to initialize the memory size of FIX
message cache.
Read
FIXEngine.initMessageCache() to learn how to initialize the message cache size.
Create a Standalone FIX Application
Only three steps and less than a dozen lines of code is needed to create a QWFIX
enabled application.
- Create a new instance of FIXStandaloneApplication.
- Register event listeners on the
FIXStandaloneApplication instance.
- Start the application process by calling FIXStandaloneApplication.run().
For more information, please read the code snpppet "Initialize
QWFIX Enabled Application".
FIXStandaloneApplication Events
The step 2 of the three steps above is very important. Application is required to
implement and register a minimum set of event handlers.
FIXStandaloneApplication
only triggers events after FIXStandaloneApplication.run()
is called (step 3).
FIXStandaloneApplicationListener interface defines the event handlers of
FIXStandaloneApplication.
Event listeners can be added or removed by calling FIXStandaloneApplication.addListener() or
FIXStandaloneApplication.removeListener() methods.
FIXSessionStatusListener interface defines the event handlers of
FIXSession.
Event listeners can be added or removed by calling FIXSession.addSessionStatusListener() or
FIXSession.removeSessionStatusListener() methods.
Below is a complete list of all possible events that may be triggered by FIXStandaloneApplication.
- FIXStandaloneApplicationListener.fatalErrorOccurs
fatalErrorOccurs event occurs when some fatal error occured during FIX
engine initialization process, such as Repository Server connection problem etc.
This event should always be hooked up. Appropriate action should be taken.
-
FIXStandaloneApplicationListener.engineInitialized
engineInitialized event is always the first event triggered on
FIXStandaloneApplication. Note the
FIXStandaloneApplication.getFIXEngine() is not
available until this event is triggered. engineInitialized event is triggered
by the scheduler associated with the engine settings instead of the FIXStandaloneApplication.run()
method. If the process is started within the scheduler interval, the
FIXEngineInitialized event will be triggered when FIXStandaloneApplication.run()
is called (event within the same thread); otherwise it will wait until the
scheduler is triggered (definitely from a separate thread).
If application needs to set session message handler on some sessions of the
engine, call FIXEngine.setEngineMessageHandler() in this event handler; otherwise FIX engine will throw a fatal error because a session will be found without a message handler.
- FIXStandaloneApplicationListener.engineRecovered
After the engine is initialized, the run-time will check if the engine is
recovered from a previous intra-day crash. If it is recovered from a previous
intra-day crash a recovery process will be performed.
The recovery process will "replay" previously FIX message communication in
exactly the same sequence. Each message will be passed to the corresponding FIXEngineMessageHandler associated with the session.
Application is responsible for implementing the message handlers to correctly
recover the business logic to the exact state right before the crash.
Once the recovery is finished, engineRecovered event will be triggered.
- FIXSessionStatusListener.sessionStarting and FIXSessionStatusListener.sessionStarted
The run-time won't start the FIX sessions until the recovery process is finished (reason for this is simple).
Once the recovery is finished, the system will check if current time is in the
interval of each session schedulers and start the sessions if necessary.
- FIXStandaloneApplicationListener.engineStarted
After the sessions are started one by one, engineStarted event will be triggered.
Note sessionStarting and
sessionStarted events
may still be triggered after the engine is started if the session scheduler
dictates a later start time.
- FIXSessionStatusListener.sessionResetting and FIXSessionStatusListener.sessionReseted
Those events will be triggered if the session supports 24 hour session reset.
- FIXSessionStatusListener.sessionStopping and FIXSessionStatusListener.sessionStopped
Those event will be triggered if the sessions are stopped by the scheduler.
- FIXStandaloneApplicationListener.engineStopped
The event will be triggered if the engine scheduler needs to shut the FIX engine.
The process will NOT be automatically terminated after this event is triggered.
Application needs to hook up to this event and take appropriate action.
FIXStandaloneApplicationListener.engineInitialized
should always be implemented in any application.
FIXStandaloneApplication Error Handling
If any irrecoverable fatal error occurs during initialization process, such as
Repository Server error (cannot load settings), settings error or fatal
application error (e.g. message handler is not set on a session),
FIXStandaloneApplicationListener.fatalErrorOccurs event will be triggered.