com.epam.fixengine.session
Class AbstractFIXSession

java.lang.Object
  extended by com.epam.fixengine.session.AbstractFIXSession
All Implemented Interfaces:
FIXSession, ExtendedFIXSession, com.epam.fixengine.session.SessionStateListenSupport
Direct Known Subclasses:
AcceptorFIXSession, InitiatorFIXSession

public abstract class AbstractFIXSession
extends Object
implements ExtendedFIXSession, com.epam.fixengine.session.SessionStateListenSupport

The abstract session implementation. Provides base functional for acceptor and initiator sessions.


Field Summary
protected  com.epam.fixengine.session.util.ConfigurationAdaptor configuration
           
protected  HandlerChain listener
           
protected  Log log
           
protected  FIXMessageFactory messageFactory
           
protected  Queue<FIXFieldListWithType> queue
           
protected  Object sessionLock
           
protected  SessionParameters sessionParameters
           
protected  FIXTransport transport
           
 
Constructor Summary
AbstractFIXSession(FIXMessageFactory messageFactory, SessionParameters sessionParameters, HandlerChain fixSessionListener)
          Creates the AbstractFIXSession .
 
Method Summary
 void addSessionStateListener(com.epam.fixengine.session.FIXSessionStateListener stateListener)
           
 void checkHasSessionSendOrReceivedTestRequest()
          The method checks if TR send or received.
 void clearQueue()
          Clears output message queue.
abstract  void connect()
          Connects to remote counterparty,
if initiator or accepts incoming connection if acceptor.
 void disconnect(String reason)
          Disconnect the session.
protected  void disconnectTestRequestIsLost()
          Disconnect the session if test request doesn't received.
 void dispose()
          Disposes current session, removes its reference from GlobalSessionManager
and frees all allocated resources.
 boolean equals(Object o)
           
 Object getAttribute(String key)
          Gets session attribute value.
 long getBytesRead()
          Gets read bytes.
 long getBytesSent()
          Gets send bytes.
 com.epam.fixengine.encryption.Encryption getEncryption()
           
 ErrorHandler getErrorHandler()
          Gets session error handler.
 long getEstablished()
          Gets established session timestamp.
 ExtendedFIXSessionListener getExtendedFIXSessionListener()
          Gets extended fix session listener.
 MessageStorage getIncomingMessageStorage()
          Gets incoming message storage.
 long getLastInMessageTimestamp()
          Gets last received message timestamp.
 long getLastOutMessageTimestamp()
          Gets time when the message is sent
 FIXMessageFactory getMessageFactory()
          Gets message factory.
protected  HandlerChain getMessageHandlers()
          Gets chain of message handlers.
 MessageValidator getMessageValidator()
          Returns message validator.
 long getNoOfInMessages()
          Gets number of received message.
 long getNoOfOutMessages()
          Gets number of sent message.
 MessageStorage getOutgoingMessageStorage()
          Gets outgoing message storage.
 RejectMessageListener getRejectMessageListener()
          Gets reject message listener.
 SessionSequenceManager getSequenceManager()
           
 SessionParameters getSessionParameters()
          The returned value is cloned.
 SessionParameters getSessionParametersInstance()
          Gets session parameter instance.
 SessionState getSessionState()
          Returns session state.
 StorageFactory getStorageFactory()
          Gets storage factory
 int hashCode()
           
protected  void initSession()
          Initializes the resources and sends a logon message.
protected  void initSessionInternal()
          Initialize session internal.
protected  boolean isResetTimeMissed(long lastResetTime)
           
protected  void loadSessionParametersFromFile()
          Load session parameters.
 void markShutdownAsGraceful()
          Marks the session shutdown as gracefully.
 void removeAttribute(String key)
          Removes session attribute.
 void removeSessionStateListener(com.epam.fixengine.session.FIXSessionStateListener stateListener)
           
 void resetSequenceNumbers()
          Allows user to reset sequences numbers by sending logon with 141=Y.
 void resetSequenceNumbers(boolean checkGapFillBefore)
          Allows user to reset sequences numbers by sending logon with 141=Y.
protected  void restoreSessionAfterReceivedTestRequest()
          Restore the session if test request is received.
 void restoreSessionParameters()
          Restore session parameters in file.
 void saveSessionParameters()
          Save session parameters to file.
 void sendAsIs(FIXFieldList message)
          Convinient method to send out FIX message based on the message type and message content.
 void sendMessage(FIXFieldList message)
          Convinient method to send out user built FIX message.
 void sendMessage(String type, FIXFieldList content)
          Convinient method to send out FIX message based on the message type and message content.
 void sendMessageOutOfTurn(String type, FIXFieldList message)
          Sends message out of turn.
protected  void sendTestRequest()
          Send test request.
 void sendWithChanges(FIXFieldList content, ChangesType allowedChangesType)
          Convinient method to send out FIX message based on the message type and message content.
 void setAttribute(String key, Object object)
          Sets session attribute.
 void setErrorHandler(ErrorHandler handler)
          Sets error handler.
 void setFIXSessionListener(FIXSessionListener listener)
          Sets FIXSession listener to monitor session status and receive incoming messages.
 void setOutOfTurnMode(boolean mode)
          Sets OutOf turn mode.
 void setRejectMessageListener(RejectMessageListener listener)
          Sets reject message listener.
 void setSessionState(SessionState sessionState)
          Sets session state.
 void shutdown(boolean blocking)
          Shutdown the session.
protected  void startSession()
           
protected  void storeProcessedSeqNumber()
          Store the last processed seq number.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

log

protected final Log log

transport

protected FIXTransport transport

queue

protected Queue<FIXFieldListWithType> queue

listener

protected final HandlerChain listener

sessionParameters

protected final SessionParameters sessionParameters

messageFactory

protected final FIXMessageFactory messageFactory

sessionLock

protected final Object sessionLock

configuration

protected final com.epam.fixengine.session.util.ConfigurationAdaptor configuration
Constructor Detail

AbstractFIXSession

public AbstractFIXSession(FIXMessageFactory messageFactory,
                          SessionParameters sessionParameters,
                          HandlerChain fixSessionListener)
Creates the AbstractFIXSession .

Method Detail

getSequenceManager

public SessionSequenceManager getSequenceManager()

getExtendedFIXSessionListener

public ExtendedFIXSessionListener getExtendedFIXSessionListener()
Description copied from interface: ExtendedFIXSession
Gets extended fix session listener.

Specified by:
getExtendedFIXSessionListener in interface ExtendedFIXSession
See Also:
ExtendedFIXSession.getExtendedFIXSessionListener()

getStorageFactory

public StorageFactory getStorageFactory()
Gets storage factory


getRejectMessageListener

public RejectMessageListener getRejectMessageListener()
Description copied from interface: ExtendedFIXSession
Gets reject message listener.

Specified by:
getRejectMessageListener in interface ExtendedFIXSession
Returns:
reject message listener
See Also:
ExtendedFIXSession.getRejectMessageListener()

getErrorHandler

public ErrorHandler getErrorHandler()
Description copied from interface: ExtendedFIXSession
Gets session error handler.

Specified by:
getErrorHandler in interface ExtendedFIXSession
Returns:
error handler
See Also:
ExtendedFIXSession.getErrorHandler()

setErrorHandler

public void setErrorHandler(ErrorHandler handler)
Description copied from interface: FIXSession
Sets error handler.

Specified by:
setErrorHandler in interface FIXSession
Parameters:
handler - the error handler
See Also:
FIXSession.setErrorHandler(com.epam.fixengine.ErrorHandler)

setRejectMessageListener

public void setRejectMessageListener(RejectMessageListener listener)
Description copied from interface: FIXSession
Sets reject message listener.

Specified by:
setRejectMessageListener in interface FIXSession
Parameters:
listener - the reject message listener
See Also:
FIXSession.setRejectMessageListener(com.epam.fixengine.RejectMessageListener)

markShutdownAsGraceful

public void markShutdownAsGraceful()
Description copied from interface: ExtendedFIXSession
Marks the session shutdown as gracefully.

Specified by:
markShutdownAsGraceful in interface ExtendedFIXSession
See Also:
ExtendedFIXSession.markShutdownAsGraceful();

clearQueue

public void clearQueue()
Description copied from interface: ExtendedFIXSession
Clears output message queue.
Method also reject all messages from the queue.
To use this feature, the user should set the RejectMessageListener listener.

Specified by:
clearQueue in interface ExtendedFIXSession
See Also:
ExtendedFIXSession.clearQueue()

setOutOfTurnMode

public void setOutOfTurnMode(boolean mode)
Description copied from interface: ExtendedFIXSession
Sets OutOf turn mode.

Specified by:
setOutOfTurnMode in interface ExtendedFIXSession
Parameters:
mode - the mode

resetSequenceNumbers

public void resetSequenceNumbers()
                          throws IOException
Description copied from interface: FIXSession
Allows user to reset sequences numbers by sending logon with 141=Y.
Notice: Only supported for FIX versions 4.1 and above.
Notice: The logon message will be send only when session is in connected state.

Specified by:
resetSequenceNumbers in interface FIXSession
Throws:
IOException
See Also:
FIXSession.resetSequenceNumbers()

resetSequenceNumbers

public void resetSequenceNumbers(boolean checkGapFillBefore)
                          throws IOException
Description copied from interface: FIXSession
Allows user to reset sequences numbers by sending logon with 141=Y.
Notice: Only supported for FIX versions 4.1 and above.
Notice: The logon message will be send only when session is in connected state.

Specified by:
resetSequenceNumbers in interface FIXSession
Parameters:
checkGapFillBefore - - the flag indicates if needed to check the seq num.

If true the TR will be sent before introday logon otherwise only intraday logon will be sent.

Throws:
IOException
See Also:
FIXSession.resetSequenceNumbers(boolean)

setFIXSessionListener

public void setFIXSessionListener(FIXSessionListener listener)
Description copied from interface: FIXSession
Sets FIXSession listener to monitor session status and receive incoming messages.

Specified by:
setFIXSessionListener in interface FIXSession
Parameters:
listener - the user specified listener
See Also:
FIXSession.setFIXSessionListener(FIXSessionListener)

getOutgoingMessageStorage

public MessageStorage getOutgoingMessageStorage()
Description copied from interface: ExtendedFIXSession
Gets outgoing message storage.

Specified by:
getOutgoingMessageStorage in interface ExtendedFIXSession
Returns:
message storage
See Also:
ExtendedFIXSession.getOutgoingMessageStorage()

getIncomingMessageStorage

public MessageStorage getIncomingMessageStorage()
Description copied from interface: ExtendedFIXSession
Gets incoming message storage.

Specified by:
getIncomingMessageStorage in interface ExtendedFIXSession
Returns:
message storage
See Also:
ExtendedFIXSession.getIncomingMessageStorage()

saveSessionParameters

public void saveSessionParameters()
                           throws IOException
Description copied from interface: ExtendedFIXSession
Save session parameters to file.

Specified by:
saveSessionParameters in interface ExtendedFIXSession
Throws:
IOException - if I/O error occurred
See Also:
ExtendedFIXSession.saveSessionParameters()

restoreSessionParameters

public void restoreSessionParameters()
                              throws IOException
Description copied from interface: ExtendedFIXSession
Restore session parameters in file. Method reset all parameters to default.

Specified by:
restoreSessionParameters in interface ExtendedFIXSession
Throws:
IOException - if I/O error occurred
See Also:
ExtendedFIXSession.restoreSessionParameters()

connect

public abstract void connect()
                      throws IOException
Description copied from interface: FIXSession
Connects to remote counterparty,
if initiator or accepts incoming connection if acceptor.

Specified by:
connect in interface FIXSession
Throws:
IOException - I/O exception if error occurred

getSessionParametersInstance

public SessionParameters getSessionParametersInstance()
Description copied from interface: ExtendedFIXSession
Gets session parameter instance.

Specified by:
getSessionParametersInstance in interface ExtendedFIXSession
See Also:
ExtendedFIXSession.getSessionParametersInstance()

getMessageFactory

public FIXMessageFactory getMessageFactory()
Description copied from interface: ExtendedFIXSession
Gets message factory.

Specified by:
getMessageFactory in interface ExtendedFIXSession
Returns:
message factory
See Also:
ExtendedFIXSession.getMessageFactory()

getSessionParameters

public SessionParameters getSessionParameters()
The returned value is cloned.

Specified by:
getSessionParameters in interface FIXSession
Returns:
SessionParameters - session parameters
See Also:
FIXSession.getSessionParameters()

getSessionState

public SessionState getSessionState()
Description copied from interface: FIXSession
Returns session state.

Specified by:
getSessionState in interface FIXSession
Returns:
SessionState - session state
See Also:
FIXSession.getSessionState()

setSessionState

public void setSessionState(SessionState sessionState)
Description copied from interface: ExtendedFIXSession
Sets session state.

Specified by:
setSessionState in interface ExtendedFIXSession
Parameters:
sessionState - the new session state
See Also:
ExtendedFIXSession.setSessionState(com.epam.fixengine.SessionState)

getBytesRead

public long getBytesRead()
Description copied from interface: ExtendedFIXSession
Gets read bytes.

Specified by:
getBytesRead in interface ExtendedFIXSession
Returns:
number of read bytes
See Also:
ExtendedFIXSession.getBytesRead()

getEstablished

public long getEstablished()
Description copied from interface: ExtendedFIXSession
Gets established session timestamp.

Specified by:
getEstablished in interface ExtendedFIXSession
Returns:
timestamp
See Also:
ExtendedFIXSession.getEstablished()

getBytesSent

public long getBytesSent()
Description copied from interface: ExtendedFIXSession
Gets send bytes.

Specified by:
getBytesSent in interface ExtendedFIXSession
Returns:
number of send bytes
See Also:
ExtendedFIXSession.getBytesSent()

getNoOfInMessages

public long getNoOfInMessages()
Description copied from interface: ExtendedFIXSession
Gets number of received message.

Specified by:
getNoOfInMessages in interface ExtendedFIXSession
Returns:
number of received message
See Also:
ExtendedFIXSession.getNoOfInMessages()

getNoOfOutMessages

public long getNoOfOutMessages()
Description copied from interface: ExtendedFIXSession
Gets number of sent message.

Specified by:
getNoOfOutMessages in interface ExtendedFIXSession
Returns:
number of sent message
See Also:
ExtendedFIXSession.getNoOfInMessages()

getLastInMessageTimestamp

public long getLastInMessageTimestamp()
Description copied from interface: ExtendedFIXSession
Gets last received message timestamp.

Specified by:
getLastInMessageTimestamp in interface ExtendedFIXSession
Returns:
timestamp
See Also:
ExtendedFIXSession.getLastInMessageTimestamp()

getLastOutMessageTimestamp

public long getLastOutMessageTimestamp()
Description copied from interface: ExtendedFIXSession
Gets time when the message is sent

Specified by:
getLastOutMessageTimestamp in interface ExtendedFIXSession
Returns:
time when the message is sent
See Also:
ExtendedFIXSession.getLastOutMessageTimestamp()

getMessageHandlers

protected HandlerChain getMessageHandlers()
Gets chain of message handlers.


initSession

protected void initSession()
                    throws IOException
Initializes the resources and sends a logon message.

Throws:
IOException - - if I/O error occurred.

isResetTimeMissed

protected boolean isResetTimeMissed(long lastResetTime)

initSessionInternal

protected void initSessionInternal()
                            throws IOException
Initialize session internal.

The method is created all session object: in/out storage and pumper/reader, etc.

Throws:
IOException

loadSessionParametersFromFile

protected void loadSessionParametersFromFile()
Load session parameters.

Method load only lastProcessedIncomingSequenceNumber from session properties file.

See Also:
.

startSession

protected void startSession()
                     throws IOException
Throws:
IOException

disconnect

public void disconnect(String reason)
Disconnect the session.
The method sends the logof message, if response is not received during the HBI, shutdown the session.

Specified by:
disconnect in interface FIXSession
Parameters:
reason - the reason, if parameter is not null, the logof message will be send with 58=reason.
See Also:
FIXSession.disconnect(String)

shutdown

public void shutdown(boolean blocking)
Shutdown the session. If the parameter blocking is true, the next call of method is blocking.

Specified by:
shutdown in interface ExtendedFIXSession
Parameters:
blocking - the blocking parameter

storeProcessedSeqNumber

protected void storeProcessedSeqNumber()
Store the last processed seq number.

The method work only when last processed and last incoming seq nums are not equals.


sendMessage

public void sendMessage(String type,
                        FIXFieldList content)
Description copied from interface: FIXSession
Convinient method to send out FIX message based on the message type and message content.
Depending on implementation and configuration may send message immediately or put it in the outgoing queue either persistent or stateless.
If the msgType is null, Engine sends the message as is;
If the msgType is "", Engine updates body length, sequence number, sending time and checksum fields;
Otherwise Engine wraps the content.

If session is disposed no more messages should be send by session.

Specified by:
sendMessage in interface FIXSession
Parameters:
type - the message type (Tag 35 content)
content - the message content
See Also:
FIXSession.sendMessage(String, com.epam.fix.message.FIXFieldList)

sendAsIs

public void sendAsIs(FIXFieldList message)
Description copied from interface: FIXSession
Convinient method to send out FIX message based on the message type and message content.
Depending on implementation and configuration may send message immediately or put it in the outgoing queue either persistent or stateless.
The Engine sends the message as is.

If session is disposed no more messages should be send by session.

Specified by:
sendAsIs in interface FIXSession
Parameters:
message - the message content

sendWithChanges

public void sendWithChanges(FIXFieldList content,
                            ChangesType allowedChangesType)
Description copied from interface: FIXSession
Convinient method to send out FIX message based on the message type and message content.
Depending on implementation and configuration may send message immediately or put it in the outgoing queue either persistent or stateless.
The Engine sends the message as is.

If session is disposed no more messages should be send by session.

Specified by:
sendWithChanges in interface FIXSession
Parameters:
content - the message content
allowedChangesType - the parameter takes the next values:
ChangesType.UPDATE_SMH_AND_SMT - update the header and footer;

sendMessage

public void sendMessage(FIXFieldList message)
Description copied from interface: FIXSession
Convinient method to send out user built FIX message. Depending on implementation and configuration may send message
immediately or put it in the outgoing queue either persistent or stateless.
The Engine updates the footer and header in the message .

If session is disposed no more messages should be send by session.

Specified by:
sendMessage in interface FIXSession
Parameters:
message - the message
See Also:
FIXSession.sendMessage(com.epam.fix.message.FIXFieldList)

sendMessageOutOfTurn

public void sendMessageOutOfTurn(String type,
                                 FIXFieldList message)
Description copied from interface: ExtendedFIXSession
Sends message out of turn.

Specified by:
sendMessageOutOfTurn in interface ExtendedFIXSession
Parameters:
type - the message type
message - the message
See Also:
FIXSession.sendMessage(String, com.epam.fix.message.FIXFieldList)

getMessageValidator

public MessageValidator getMessageValidator()
Description copied from interface: FIXSession
Returns message validator.

Specified by:
getMessageValidator in interface FIXSession
Returns:
message validator for current session
See Also:
FIXSession.getMessageValidator()

dispose

public void dispose()
Description copied from interface: FIXSession
Disposes current session, removes its reference from GlobalSessionManager
and frees all allocated resources. Normally should be called after disconnect().
However it is possible to call this method for active session without
previous disconnect() that will abnormally terminate fix session by closing fix connection
(without logon exchange). This is useful to terminate stuck sessions if standard FIX logoff procedure doesn't work.
Note: it's harmless to call this method for acceptor session, but it'll do nothing because acceptor sessions are disposed automatically after disconnect().

Specified by:
dispose in interface FIXSession
See Also:
FIXSession.dispose()

sendTestRequest

protected void sendTestRequest()
Send test request.


disconnectTestRequestIsLost

protected void disconnectTestRequestIsLost()
Disconnect the session if test request doesn't received.


checkHasSessionSendOrReceivedTestRequest

public void checkHasSessionSendOrReceivedTestRequest()
The method checks if TR send or received.

If session is not received any messages during HB interval the HB will be send and If no response received session will be disconnected;

This is helper method for session task.


restoreSessionAfterReceivedTestRequest

protected void restoreSessionAfterReceivedTestRequest()
Restore the session if test request is received.


setAttribute

public void setAttribute(String key,
                         Object object)
Description copied from interface: ExtendedFIXSession
Sets session attribute.

Specified by:
setAttribute in interface ExtendedFIXSession
Parameters:
key - the attribute key
object - the attribute value
See Also:
ExtendedFIXSession.setAttribute(String, Object)

getAttribute

public Object getAttribute(String key)
Description copied from interface: ExtendedFIXSession
Gets session attribute value.

Specified by:
getAttribute in interface ExtendedFIXSession
Parameters:
key - the attribute key
Returns:
attribute value
See Also:
ExtendedFIXSession.getAttribute(String)

removeAttribute

public void removeAttribute(String key)
Description copied from interface: ExtendedFIXSession
Removes session attribute.

Specified by:
removeAttribute in interface ExtendedFIXSession
Parameters:
key - the attribute key
See Also:
ExtendedFIXSession.removeAttribute(String)

addSessionStateListener

public void addSessionStateListener(com.epam.fixengine.session.FIXSessionStateListener stateListener)
Specified by:
addSessionStateListener in interface com.epam.fixengine.session.SessionStateListenSupport

removeSessionStateListener

public void removeSessionStateListener(com.epam.fixengine.session.FIXSessionStateListener stateListener)
Specified by:
removeSessionStateListener in interface com.epam.fixengine.session.SessionStateListenSupport

toString

public String toString()
Overrides:
toString in class Object

equals

public boolean equals(Object o)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

getEncryption

public com.epam.fixengine.encryption.Encryption getEncryption()
Specified by:
getEncryption in interface ExtendedFIXSession


Copyright © 2000-2011 EPAM Systems. All Rights Reserved.