com.teraspaces.qwfix
Class FIXEngine

java.lang.Object
  extended by com.teraspaces.qwfix.FIXEngine

public final class FIXEngine
extends Object


Field Summary
static int CACHE_CAPACITY_ALL
           
 
Method Summary
 void addEngineListener(FIXEngineListener listener)
          Adds the engine event listener.
static int getCacheCapacity()
           Gets the cache capacity.
static FIXEngineMessageCacheType getCacheType()
          Gets the cache type.
 FIXEngineMessageHandler getEngineMessageHandler(FIXSession session, String msgType)
          Gets the engine message handler for the specified MsgType and FIXSession.
 String getEngineName()
          Gets the engine name.
 FIXEnginePersistenceStateInfo getEnginePersistenceStateInfo()
          Gets the engine persistence state info.
 FIXEngineRole getEngineRole()
          Gets role of current engine.
 int getGlobalEngineID()
          Gets the index of the current engine in getGlobalEngines().
static List<FIXEngine> getGlobalEngines()
          Gets the global list of all FIX engines managed by current process.
static List<FIXSessionPersistence> getGlobalSessionPersistences()
           Get the global list of FIXSessionPersistence in the current process.
static List<FIXSession> getGlobalSessions()
          Gets the global session list.
static FIXMessage getMessage(long token)
           Gets the engine message.
 FIXEngineMessageHandlerStatus getMessageHandlerStatus()
          Gets the message handler status.
 FIXMessageLog getMessageLog()
          Gets the engine message log.
 FIXServiceStatus getServiceStatus()
          Gets the current service status.
 FIXSession getSession(String name, FIXSessionDirection direction)
          Gets a session specified by name and direction.
 List<FIXSessionPersistence> getSessionPersistences()
           Gets the list of FIXSessionPersistence managed by current engine.
 List<FIXSession> getSessions()
           Gets the complete list of sessions defined in the engine.
 FIXEngineSettings getSettings()
          Gets the settings.
static void initMessageCache(FIXEngineMessageCacheType cacheType, int cacheCapacity)
           Initializes the global FIXMessage cache with a specified capacity.
 void removeEngineListener(FIXEngineListener listener)
          Removes the specified engine event listener.
 void setEngineMessageDefaultHandler(FIXSession session, FIXEngineMessageHandler handler)
           Sets a default message handler for the specific session.
 void setEngineMessageHandler(FIXSession session, FIXEngineMessageHandler handler, String... msgTypes)
           Sets a message handler for the specific session.
static void unloadAll()
           Unloads all FIXEngine instances in the current process.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CACHE_CAPACITY_ALL

public static final int CACHE_CAPACITY_ALL
See Also:
Constant Field Values
Method Detail

initMessageCache

public static void initMessageCache(FIXEngineMessageCacheType cacheType,
                                    int cacheCapacity)

Initializes the global FIXMessage cache with a specified capacity.

The global message cache is not bounded with the FIXEngine. An process can only have one message cache while it can have more than one FIXEngines.

The cacheCapacity can be either the number of messages or number of "MegaBytes (MB)" of memory, depending on the value of cacheType.

Parameters:
cacheType - the type of cache.
cacheCapacity - the cache capacity. Use CACHE_CAPACITY_ALL for unlimited capacity.
See Also:
getCacheCapacity(), getCacheType()

getCacheCapacity

public static int getCacheCapacity()

Gets the cache capacity. The cacheCapacity can be either the number of messages or number of "MegaBytes (MB)" of memory, depending on the value of cacheType.

Returns:
the cache capacity
See Also:
initMessageCache(FIXEngineMessageCacheType, int), getCacheType()

getCacheType

public static FIXEngineMessageCacheType getCacheType()
Gets the cache type.

Returns:
the cache type
See Also:
initMessageCache(FIXEngineMessageCacheType, int), getCacheCapacity(), FIXEngineMessageCacheType

getSettings

public FIXEngineSettings getSettings()
Gets the settings. The settings is not available until the engine is initialized. The initialization of FIX engine is controlled by specific application framework. See FIXStandaloneApplicationListener.engineInitialized(FIXEngine) for more detail.

Returns:
the settings

unloadAll

public static void unloadAll()

Unloads all FIXEngine instances in the current process.

After this method is called, all QWFIX related resources should be freed and subject to garbage collection.


setEngineMessageHandler

public void setEngineMessageHandler(FIXSession session,
                                    FIXEngineMessageHandler handler,
                                    String... msgTypes)

Sets a message handler for the specific session.

The handler must be able to handle Reject message. A reject message against a message type in the list will be passed to the handler, too.

If a FIXSession does not specify a handler for a specific MsgType, the default handler (see setEngineMessageDefaultHandler(FIXSession, FIXEngineMessageHandler)) will be used. If the default handler is not specific either, the message is ignored. No error will be reported. It's application developers' responsibility to at least specify the default handler.

It's application developers' responsibility to implement their own FIXEngineMessageHandler, based on their own business logics. QWFIX system may provide some standard off-the-shelf handlers for some common business logics such as order handling and market data.

Parameters:
session - the FIX session.
handler - the message handler
msgTypes - the types of messages the handler is going to handle
See Also:
setEngineMessageDefaultHandler(FIXSession, FIXEngineMessageHandler)

setEngineMessageDefaultHandler

public void setEngineMessageDefaultHandler(FIXSession session,
                                           FIXEngineMessageHandler handler)

Sets a default message handler for the specific session.

This handler will handle message types not covered by setEngineMessageDefaultHandler(FIXSession, FIXEngineMessageHandler) , including "unexpected" message types.

The default handler will handle the message if not other handler for the MsgType of the specified FIX message is found. See setEngineMessageHandler(FIXSession, FIXEngineMessageHandler, String...) for more details.

Parameters:
session - the FIX session
handler - the handler

getEngineMessageHandler

public FIXEngineMessageHandler getEngineMessageHandler(FIXSession session,
                                                       String msgType)
Gets the engine message handler for the specified MsgType and FIXSession. The returned handler may be null, which indicates that the handler has not been specified for the session.

Parameters:
session - the session
msgType - the MsgType
Returns:
the engine message handler

getSession

public FIXSession getSession(String name,
                             FIXSessionDirection direction)
Gets a session specified by name and direction.

Parameters:
name - the name
direction - the direction
Returns:
the session defined in the engine; or null if the session is not found.

getSessions

public List<FIXSession> getSessions()

Gets the complete list of sessions defined in the engine. The returned list is read only.

Sessions defined in a FIXEngine can be accessed using "EngineSessionID" (see FIXSession.getEngineSessionID() as index. Note the EngineSessionID is only valid within the process life cycle. It is not guaranteed to be the same across different process life spans.

Returns:
the list of sessions
See Also:
FIXSession.getEngineSessionID(), getGlobalSessions()

getEngineName

public String getEngineName()
Gets the engine name.

Returns:
the engine name

getServiceStatus

public FIXServiceStatus getServiceStatus()
Gets the current service status.

Returns:
the current service status.

getEnginePersistenceStateInfo

public FIXEnginePersistenceStateInfo getEnginePersistenceStateInfo()
Gets the engine persistence state info.

Returns:
the engine persistence state info

getEngineRole

public FIXEngineRole getEngineRole()
Gets role of current engine.

Returns:
the role of current engine

getSessionPersistences

public List<FIXSessionPersistence> getSessionPersistences()

Gets the list of FIXSessionPersistence managed by current engine.

The FIXSessionPersistence.getEnginePersistenceID() returns the index of the persistence in this list.

The returned list is read only.

Returns:
the list of session persistence.
See Also:
getGlobalSessionPersistences()

getGlobalSessionPersistences

public static List<FIXSessionPersistence> getGlobalSessionPersistences()

Get the global list of FIXSessionPersistence in the current process.

This method get all session persistence managed by current process. If there's only one FIXEngine in process. The list should be the same as getSessionPersistences(); otherwise it will be a collection of all SessionPersistences of all engines.

The returned list is read only.

Returns:
the global list session persistence
See Also:
getSessionPersistences()

addEngineListener

public void addEngineListener(FIXEngineListener listener)
Adds the engine event listener. The method is thread safe.

Parameters:
listener - the listener

removeEngineListener

public void removeEngineListener(FIXEngineListener listener)
Removes the specified engine event listener. This method is thread safe. If the specified listener is not added, the method returns without error.

Parameters:
listener - the listener

getMessage

public static FIXMessage getMessage(long token)

Gets the engine message.

The FIX engine message cache is a global LRU (Least Recently Used) cache. This operation will affect the cache by moving the message to the head of the cache (unless the cache size is unlimited).

The message may return a null if message is not available. For example, a token may represent an incoming administrative message that was "skipped" during resend process from a "Resend Gap Fill".

Parameters:
token - the token
Returns:
the message; or null if the message is not available.

getMessageLog

public FIXMessageLog getMessageLog()
Gets the engine message log.

The MessageLog keeps all FIX application message communications throughout the current FIXEngine life cycle (controlled by FIXScheduler). Administrative messages are generally hidden from application and will not be included in this log. The only exception is the "Reject" messages against application messages. Those "Reject" messages will be included in the log.

The MessageLog is read only. Throughout the life cycle of the FIXEngine, the size of log will only increase as a result of new messages appended to the log.

The messages in the log are appended in the order of the time the message is "processed" by the system.

For incoming messages, the message is appended to the log at the time of after the message is processed by FIXSession (by passing the message to the (@link FIXEngineMessageHandler} associated with the corresponding FIXSession, not the time when the message was received by FIXSession.

For outgoing messages, the message is appended to the log immediately after the message was sent by calling FIXSession.sendMessage(com.teraspaces.qwfix.FIXMessage), not the time when the message is actually sent by the session to the peer.

In the remote monitoring tools or QWFIX hot standby backup servers, the MessageLog is automatically synchronized with that of the primary production server. Remote applications can use the remote copy of MessageLog to help replicating the state of the primary production server. (See QWFIX RTAnalyzer)

Returns:
the engine message log

getMessageHandlerStatus

public FIXEngineMessageHandlerStatus getMessageHandlerStatus()
Gets the message handler status.

The status may be Recovery.

Returns:
the message handler status

getGlobalEngineID

public int getGlobalEngineID()
Gets the index of the current engine in getGlobalEngines().

Usually application only need one instance of FIXEngine per process. In that case the GlobalEngineID will be 0 and the count of GlobalEngines will be 1.

One exception is the management tool. The management tool such as QWFIX RTAnalyzer may maintain more than one FIXEngine per process.

Returns:
the index of the current engine in getGlobalEngines()

getGlobalEngines

public static List<FIXEngine> getGlobalEngines()
Gets the global list of all FIX engines managed by current process. The returned collection is read-only.

Each FIXEngine has a property getGlobalEngineID() represents the index of the FIXEngine in this list.

Usually application only need one instance of FIXEngine per process. In that case the GlobalEngineID will be 0 and the count of GlobalEngines will be 1.

One exception is the management tool. The management tool such as QWFIX RTAnalyzer may maintain more than one FIXEngine per process.

If the process does manage more than one FIX engines. The GlobalEngines collection is only valid during run-time. If the system is shut down and restarted, the sequence of FIX engines in GlobalEngines may possibly change because the engines may be added by different threads. In that case the GlobalEngineID of each engine will change accordingly.

Returns:
the global engine list
See Also:
getGlobalSessions()

getGlobalSessions

public static List<FIXSession> getGlobalSessions()
Gets the global session list.

The system may manage more than one FIX engines in the same process. The GUI based management tool QWRTAnalyzer is a good example. The glbal session list contains all FIX sessions managed by the system.

FIXSession.getGlobalSessionID() is the index of the session in this list.

If the process does manage more than one FIX engines. The GlobalSessions collection is only valid during run-time. If the system is shut down and restarted, the sequence of FIX sessions in GlobalSessions may possibly change because the sessions may be added by different threads. In that case the GlobalSessionID of each session will change accordingly.

Returns:
the global session list
See Also:
getSessions(), FIXSession.getGlobalSessionID(), getGlobalEngines()