The Session is the primary FIX abstraction for message communication. It performs sequencing and error recovery and represents a communication channel to a counterparty. Sessions are independent of specific communication layer connections. A Session is defined as starting with message sequence number of 1 and ending when the session is reset. The Session could span many sequential connections (it cannot operate on multiple connections simultaneously).
Inheritance: IDisposable
 public SocketInitiatorThread(Transport.SocketInitiator initiator, Session session, IPEndPoint socketEndPoint)
 {
     initiator_ = initiator;
     session_ = session;
     socketEndPoint_ = socketEndPoint;
     parser_ = new Parser();
     socket_ = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
     session_ = session;
 }
 public SocketInitiatorThread(Transport.SocketInitiator initiator, Session session, IPEndPoint socketEndPoint, SocketSettings socketSettings)
 {
     isDisconnectRequested_ = false;
     initiator_ = initiator;
     session_ = session;
     socketEndPoint_ = socketEndPoint;
     parser_ = new Parser();
     session_ = session;
     socketSettings_ = socketSettings;
 }
 public SocketInitiatorThread(Transport.SocketInitiator initiator, Session session, IPEndPoint socketEndPoint, SocketSettings socketSettings)
 {
     isDisconnectRequested_ = false;
     initiator_ = initiator;
     session_ = session;
     socketEndPoint_ = socketEndPoint;
     parser_ = new Parser();
     socket_ = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
     socket_.NoDelay = socketSettings.SocketNodelay;
     session_ = session;
 }
Example #4
0
        public void HandleException(Session quickFixSession, System.Exception cause, TcpClient client)
        {
            bool disconnectNeeded = true;
            string reason = cause.Message;

            System.Exception realCause = cause;
            /** TODO
            if(cause is FIXMessageDecoder.DecodeError && cause.InnerException != null)
                realCause = cause.getCause();
            */
            if (realCause is System.Net.Sockets.SocketException)
            {
                string remoteEndPoint = string.Empty;
                try { remoteEndPoint = client.Client.RemoteEndPoint.ToString(); }
                catch { }
                if (quickFixSession != null && quickFixSession.IsEnabled)
                    reason = "Socket exception (" + remoteEndPoint + "): " + cause.Message;
                else
                    reason = "Socket (" + remoteEndPoint + "): " + cause.Message;
                disconnectNeeded = true;
            }
            /** TODO
            else if(realCause is FIXMessageDecoder.CriticalDecodeError)
            {
                reason = "Critical protocol codec error: " + cause;
                disconnectNeeded = true;
            }
            */
            else if(realCause is MessageParseError)
            {
                reason = "Protocol handler exception: " + cause;
                if (quickFixSession == null)
                    disconnectNeeded = true;
                else
                    disconnectNeeded = false;
            }
            else
            {
                reason = cause.ToString();
                disconnectNeeded = false;
            }

            this.Log("SocketReader Error: " + reason);

            if (disconnectNeeded)
            {
                if (null != quickFixSession && quickFixSession.HasResponder)
                    quickFixSession.Disconnect(reason);
                else
                    DisconnectClient(client);
            }
        }
 public SocketInitiatorThread(Transport.SocketInitiator initiator, Session session, IPEndPoint socketEndPoint, SocketSettings socketSettings)
 {
     isDisconnectRequested_ = false;
     initiator_ = initiator;
     session_ = session;
     socketEndPoint_ = socketEndPoint;
     parser_ = new Parser();
     if (socketEndPoint.AddressFamily == AddressFamily.InterNetwork)
         socket_ = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
     else
     {
         socket_ = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp);
         socket_.SetSocketOption(SocketOptionLevel.IPv6, (SocketOptionName)23, 10);
     }
     socket_.NoDelay = socketSettings.SocketNodelay;
     session_ = session;
 }
Example #6
0
        private void HandleExceptionInternal(Session quickFixSession, System.Exception cause)
        {
            bool disconnectNeeded = true;
            string reason = cause.Message;

            System.Exception realCause = cause;

            // Unwrap socket exceptions from IOException in order for code below to work
            if (realCause is IOException && realCause.InnerException is SocketException)
                realCause = realCause.InnerException;

            /** TODO
            if(cause is FIXMessageDecoder.DecodeError && cause.InnerException != null)
                realCause = cause.getCause();
            */
            if (realCause is System.Net.Sockets.SocketException)
            {
                if (quickFixSession != null && quickFixSession.IsEnabled)
                    reason = "Socket exception (" + tcpClient_.Client.RemoteEndPoint + "): " + cause.Message;
                else
                    reason = "Socket (" + tcpClient_.Client.RemoteEndPoint + "): " + cause.Message;
                disconnectNeeded = true;
            }
            /** TODO
            else if(realCause is FIXMessageDecoder.CriticalDecodeError)
            {
                reason = "Critical protocol codec error: " + cause;
                disconnectNeeded = true;
            }
            */
            else if (realCause is MessageParseError)
            {
                reason = "Protocol handler exception: " + cause;
                if (quickFixSession == null)
                    disconnectNeeded = true;
                else
                    disconnectNeeded = false;
            }
            else
            {
                reason = cause.ToString();
                disconnectNeeded = false;
            }

            this.Log("SocketReader Error: " + reason);

            if (disconnectNeeded)
            {
                if (null != quickFixSession && quickFixSession.HasResponder)
                    quickFixSession.Disconnect(reason);
                else
                    DisconnectClient();
            }
        }
Example #7
0
 public void HandleException(Session quickFixSession, System.Exception cause, TcpClient client)
 {
     HandleExceptionInternal(quickFixSession, cause);
 }
Example #8
0
 protected bool HandleNewSession(string msg)
 {
     if (qfSession_.HasResponder)
     {
         qfSession_.Log.OnIncoming(msg);
         qfSession_.Log.OnEvent("Multiple logons/connections for this session are not allowed (" + tcpClient_.Client.RemoteEndPoint + ")");
         qfSession_ = null;
         DisconnectClient();
         return false;
     }
     qfSession_.Log.OnEvent(qfSession_.SessionID + " Socket Reader " + GetHashCode() + " accepting session " + qfSession_.SessionID + " from " + tcpClient_.Client.RemoteEndPoint);
     /// FIXME do this here? qfSession_.HeartBtInt = QuickFix.Fields.Converters.IntConverter.Convert(message.GetField(Fields.Tags.HeartBtInt)); /// FIXME
     qfSession_.Log.OnEvent(qfSession_.SessionID + " Acceptor heartbeat set to " + qfSession_.HeartBtInt + " seconds");
     qfSession_.SetResponder(responder_);
     return true;
 }
Example #9
0
        protected void OnMessageFoundInternal(string msg)
        {
            ///Message fixMessage;

            try
            {
                if (null == qfSession_)
                {
                    qfSession_ = Session.LookupSession(Message.GetReverseSessionID(msg));
                    if (null == qfSession_)
                    {
                        this.Log("ERROR: Disconnecting; received message for unknown session: " + msg);
                        DisconnectClient();
                        return;
                    }
                    else
                    {
                        if (!HandleNewSession(msg))
                            return;
                    }
                }

                try
                {
                    qfSession_.Next(msg);
                }
                catch (System.Exception e)
                {
                    this.Log("Error on Session '" + qfSession_.SessionID + "': " + e.ToString());
                }
            }
            catch (InvalidMessage e)
            {
                HandleBadMessage(msg, e);
            }
            catch (MessageParseError e)
            {
                HandleBadMessage(msg, e);
            }
        }
Example #10
0
        public Session Create(SessionID sessionID, QuickFix.Dictionary settings)
        {
            string connectionType = settings.GetString(SessionSettings.CONNECTION_TYPE);
            if (!"acceptor".Equals(connectionType) && !"initiator".Equals(connectionType))
                throw new ConfigError("Invalid ConnectionType");

            if ("acceptor".Equals(connectionType) && settings.Has(SessionSettings.SESSION_QUALIFIER))
                throw new ConfigError("SessionQualifier cannot be used with acceptor.");

            bool useDataDictionary = true;
            if (settings.Has(SessionSettings.USE_DATA_DICTIONARY))
                useDataDictionary = settings.GetBool(SessionSettings.USE_DATA_DICTIONARY);

            string defaultApplVerID = "";
            if (sessionID.IsFIXT)
            {
                throw new System.NotImplementedException("FIXME - SessionFactory cannot handle FIXT Sessions!");
                /*
                if (!settings.Has(SessionSettings.DEFAULT_APPLVERID))
                {
                    throw new ConfigError("ApplVerID is required for FIXT transport");
                }
                defaultApplVerID = Message.ToApplVerID(settings.GetString(SessionSettings.DEFAULT_APPLVERID));
                */
            }

            DataDictionaryProvider dd = new DataDictionaryProvider();
            if (useDataDictionary)
            {
                if (sessionID.IsFIXT)
                    throw new System.NotImplementedException("FIXME - SessionFactory cannot handle 'UseDataDictionary=Y' for 'FIXT' sessions!");
                else
                    ProcessFixDataDictionary(sessionID, settings, dd);
            }

            int heartBtInt = 0;
            if ( connectionType == "initiator" )
            {
                heartBtInt = System.Convert.ToInt32(settings.GetLong( SessionSettings.HEARTBTINT ));
                if ( heartBtInt <= 0 )
                    throw new ConfigError( "Heartbeat must be greater than zero" );
            }

            Session session = new Session(
                application_,
                messageStoreFactory_,
                sessionID,
                dd,
                new SessionSchedule(settings, sessionID),
                heartBtInt,
                logFactory_,
                new DefaultMessageFactory());
            session.SenderDefaultApplVerID = defaultApplVerID;

            /** FIXME - implement optional settings
            if (settings.Has(SessionSettings.SEND_REDUNDANT_RESENDREQUESTS))
                session.SetSendRedundantResendRequests(settings.GetBool(SessionSettings.SEND_REDUNDANT_RESENDREQUESTS));
            if (settings.Has(SessionSettings.CHECK_COMPID))
                session.SetCheckCompId(settings.GetBool(SessionSettings.CHECK_COMPID));
            if (settings.Has(SessionSettings.CHECK_LATENCY))
                session.SetCheckLatency(settings.GetBool(SessionSettings.CHECK_LATENCY));
            if (settings.Has(SessionSettings.MAX_LATENCY))
                session.SetMaxLatency(settings.GetLong(SessionSettings.MAX_LATENCY));
            if (settings.Has(SessionSettings.LOGON_TIMEOUT))
                session.SetLogonTimeout(settings.GetLong(SessionSettings.LOGON_TIMEOUT));
            if (settings.Has(SessionSettings.LOGOUT_TIMEOUT))
                session.SetLogoutTimeout(settings.GetLong(SessionSettings.LOGOUT_TIMEOUT));
            */

            // FIXME to get from config if available
            session.MaxLatency = 120;
            session.CheckLatency = true;

            if (settings.Has(SessionSettings.RESET_ON_LOGON))
                session.ResetOnLogon = settings.GetBool(SessionSettings.RESET_ON_LOGON);
            if (settings.Has(SessionSettings.RESET_ON_LOGOUT))
                session.ResetOnLogout = settings.GetBool(SessionSettings.RESET_ON_LOGOUT);
            if (settings.Has(SessionSettings.RESET_ON_DISCONNECT))
                session.ResetOnDisconnect = settings.GetBool(SessionSettings.RESET_ON_DISCONNECT);
            if (settings.Has(SessionSettings.REFRESH_ON_LOGON))
                session.RefreshOnLogon = settings.GetBool(SessionSettings.REFRESH_ON_LOGON);
            /** FIXME - implement optional settings
            if (settings.Has(SessionSettings.MILLISECONDS_IN_TIMESTAMP))
                session.SetMillisecondsInTimeStamp(settings.GetBool(SessionSettings.MILLISECONDS_IN_TIMESTAMP));
            if (settings.Has(SessionSettings.PERSIST_MESSAGES))
                session.SetPersistMessages(settings.GetBool(SessionSettings.PERSIST_MESSAGES));
            if (settings.Has(SessionSettings.VALIDATE_LENGTH_AND_CHECKSUM))
                session.SetValidateLengthAndChecksum(settings.GetBool(SessionSettings.VALIDATE_LENGTH_AND_CHECKSUM));
            */

            return session;
        }
Example #11
0
 public void OnCreate(SessionID sessionID)
 {
     _session = Session.LookupSession(sessionID);
 }
Example #12
0
        public ChannelTcpConflated(TCPConflatedConfig conflatedConfig)
        {
            logger = LogManager.GetLogger("ChannelTcpConflated-" + conflatedConfig.ChannelID);

            MDSUtils.AddAppender("ChannelTcpConflated-" + conflatedConfig.ChannelID, logger.Logger);

            _bKeepRunning = true;

            machineGun = new MachineGunFixSplitter();
            machineGun.UnderFIXMessageFire += new FIXMachineGunEventHandler(machineGun_UnderFIXMessageFire);
            machineGun.Start();

            thQueueProc = new Thread(new ThreadStart(queueProc));
            thQueueProc.Start();

            thSplitProc = new Thread(new ThreadStart(splitterThreadWork));
            thSplitProc.Start();

            _channelUmdfConfig = conflatedConfig;

            //if (!listaChannelQueues.ContainsKey(conflatedConfig.ChannelID))
            //    listaChannelQueues.Add(conflatedConfig.ChannelID, new ListChannelQueues(qUdpPkt, replayLockObject));

            logger.Info("Start(): iniciando sessao FIX...");
            try
            {
                // Cria sessao FIX
                _session = new QuickFix.SessionID(
                    conflatedConfig.BeginString,
                    conflatedConfig.SenderCompID,
                    conflatedConfig.TargetCompID);

                // Cria dicionario da configuracao
                QuickFix.Dictionary mainDic = new QuickFix.Dictionary();
                mainDic.SetLong("SocketConnectPort", conflatedConfig.ProxyPort);
                mainDic.SetLong("HeartBtInt", conflatedConfig.HeartBtInt);
                mainDic.SetLong("ReconnectInterval", conflatedConfig.ReconnectInterval);
                mainDic.SetBool("ResetOnLogon", conflatedConfig.ResetOnLogon);
                mainDic.SetBool("ResetOnLogout", conflatedConfig.ResetOnLogout);
                mainDic.SetBool("ResetOnDisconnect", conflatedConfig.ResetOnDisconnect);
                mainDic.SetBool("PersistMessages", conflatedConfig.PersistMessages);
                mainDic.SetString("ConnectionType", conflatedConfig.ConnectionType);
                mainDic.SetString("SocketConnectHost", conflatedConfig.ProxyHost);
                mainDic.SetString("FileStorePath", conflatedConfig.FileStorePath);
                mainDic.SetString("FileLogPath", conflatedConfig.FileLogPath);
                mainDic.SetString("StartTime", conflatedConfig.StartTime);
                mainDic.SetString("EndTime", conflatedConfig.EndTime);

                QuickFix.Dictionary sessDic = new QuickFix.Dictionary();
                sessDic.SetString("BeginString", conflatedConfig.BeginString);
                sessDic.SetString("SenderCompID", conflatedConfig.SenderCompID);

                sessDic.SetString("TargetCompID", conflatedConfig.TargetCompID);
                sessDic.SetString("DataDictionary", conflatedConfig.DataDictionary);
                sessDic.SetBool("CheckLatency", false);
                sessDic.SetBool("UseDataDictionary", true);
                sessDic.SetLong("SocketReceiveBufferSize", conflatedConfig.SocketReceiveBufferSize);

                // Configure the session settings
                QuickFix.SessionSettings settings = new QuickFix.SessionSettings();

                settings.Set(mainDic);
                settings.Set(_session, sessDic);

                MemoryStoreFactory store   = new MemoryStoreFactory();
                FileLogFactory     log     = new FileLogFactory(settings);
                IMessageFactory    message = new DefaultMessageFactory();

                // Cria o socket
                _initiator = new QuickFix.Transport.SocketInitiator(this, store, settings, this, message);
                _initiator.Start();

                QuickFix.Session mySession = QuickFix.Session.LookupSession(_session);
                QuickFix.Session.LookupSession(_session).ValidateLengthAndChecksum = false;
            }
            catch (Exception ex)
            {
                logger.Error("Start():" + ex.Message, ex);
            }

            logger.Info("Start(): Sessao FIX iniciado!");
        }
Example #13
0
 public void OnCreate(SessionID sessionID)
 {
     // This method is called whenever a new session is created.
     m_Session = Session.LookupSession(sessionID);
 }
Example #14
0
 public void ProcessToApp(Message msg, Session session)
 {
 }
Example #15
0
 public void ProcessToAdmin(Message msg, Session session)
 {
 }
Example #16
0
        public Session Create(SessionID sessionID, QuickFix.Dictionary settings)
        {
            string connectionType = settings.GetString(SessionSettings.CONNECTION_TYPE);
            if (!"acceptor".Equals(connectionType) && !"initiator".Equals(connectionType))
                throw new ConfigError("Invalid ConnectionType");

            if ("acceptor".Equals(connectionType) && settings.Has(SessionSettings.SESSION_QUALIFIER))
                throw new ConfigError("SessionQualifier cannot be used with acceptor.");

            bool useDataDictionary = true;
            if (settings.Has(SessionSettings.USE_DATA_DICTIONARY))
                useDataDictionary = settings.GetBool(SessionSettings.USE_DATA_DICTIONARY);

            QuickFix.Fields.ApplVerID defaultApplVerID = null;
            if (sessionID.IsFIXT)
            {
                if (!settings.Has(SessionSettings.DEFAULT_APPLVERID))
                {
                    throw new ConfigError("ApplVerID is required for FIXT transport");
                }
                defaultApplVerID = Message.GetApplVerID(settings.GetString(SessionSettings.DEFAULT_APPLVERID));

            }

            DataDictionaryProvider dd = new DataDictionaryProvider();
            if (useDataDictionary)
            {
                if (sessionID.IsFIXT)
                    ProcessFixTDataDictionaries(sessionID, settings, dd);
                else
                    ProcessFixDataDictionary(sessionID, settings, dd);
            }

            int heartBtInt = 0;
            if ( connectionType == "initiator" )
            {
                heartBtInt = System.Convert.ToInt32(settings.GetLong( SessionSettings.HEARTBTINT ));
                if ( heartBtInt <= 0 )
                    throw new ConfigError( "Heartbeat must be greater than zero" );
            }
            string senderDefaultApplVerId = "";
            if(defaultApplVerID != null)
                senderDefaultApplVerId = defaultApplVerID.Obj;

            Session session = new Session(
                application_,
                messageStoreFactory_,
                sessionID,
                dd,
                new SessionSchedule(settings),
                heartBtInt,
                logFactory_,
                messageFactory_,
                senderDefaultApplVerId);

            if (settings.Has(SessionSettings.SEND_REDUNDANT_RESENDREQUESTS))
                session.SendRedundantResendRequests = settings.GetBool(SessionSettings.SEND_REDUNDANT_RESENDREQUESTS);
            if (settings.Has(SessionSettings.RESEND_SESSION_LEVEL_REJECTS))
                session.ResendSessionLevelRejects = settings.GetBool(SessionSettings.RESEND_SESSION_LEVEL_REJECTS);
            /** FIXME - implement optional settings
            if (settings.Has(SessionSettings.CHECK_COMPID))
                session.SetCheckCompId(settings.GetBool(SessionSettings.CHECK_COMPID));
             */
            if (settings.Has(SessionSettings.CHECK_LATENCY))
                session.CheckLatency = settings.GetBool(SessionSettings.CHECK_LATENCY);
            if (settings.Has(SessionSettings.MAX_LATENCY))
                session.MaxLatency = settings.GetInt(SessionSettings.MAX_LATENCY);
            if (settings.Has(SessionSettings.LOGON_TIMEOUT))
                session.LogonTimeout = settings.GetInt(SessionSettings.LOGON_TIMEOUT);
            if (settings.Has(SessionSettings.LOGOUT_TIMEOUT))
                session.LogoutTimeout = settings.GetInt(SessionSettings.LOGOUT_TIMEOUT);
            if (settings.Has(SessionSettings.RESET_ON_LOGON))
                session.ResetOnLogon = settings.GetBool(SessionSettings.RESET_ON_LOGON);
            if (settings.Has(SessionSettings.RESET_ON_LOGOUT))
                session.ResetOnLogout = settings.GetBool(SessionSettings.RESET_ON_LOGOUT);
            if (settings.Has(SessionSettings.RESET_ON_DISCONNECT))
                session.ResetOnDisconnect = settings.GetBool(SessionSettings.RESET_ON_DISCONNECT);
            if (settings.Has(SessionSettings.REFRESH_ON_LOGON))
                session.RefreshOnLogon = settings.GetBool(SessionSettings.REFRESH_ON_LOGON);
            if (settings.Has(SessionSettings.PERSIST_MESSAGES))
                session.PersistMessages = settings.GetBool(SessionSettings.PERSIST_MESSAGES);
            if (settings.Has(SessionSettings.MILLISECONDS_IN_TIMESTAMP))
                session.MillisecondsInTimeStamp = settings.GetBool(SessionSettings.MILLISECONDS_IN_TIMESTAMP);
            if (settings.Has(SessionSettings.ENABLE_LAST_MSG_SEQ_NUM_PROCESSED))
                session.EnableLastMsgSeqNumProcessed = settings.GetBool(SessionSettings.ENABLE_LAST_MSG_SEQ_NUM_PROCESSED);
            if (settings.Has(SessionSettings.MAX_MESSAGES_IN_RESEND_REQUEST))
                session.MaxMessagesInResendRequest = settings.GetInt(SessionSettings.MAX_MESSAGES_IN_RESEND_REQUEST);
            if (settings.Has(SessionSettings.SEND_LOGOUT_BEFORE_TIMEOUT_DISCONNECT))
                session.SendLogoutBeforeTimeoutDisconnect = settings.GetBool(SessionSettings.SEND_LOGOUT_BEFORE_TIMEOUT_DISCONNECT);
            if (settings.Has(SessionSettings.IGNORE_POSSDUP_RESEND_REQUESTS))
                session.IgnorePossDupResendRequests = settings.GetBool(SessionSettings.IGNORE_POSSDUP_RESEND_REQUESTS);
            if (settings.Has(SessionSettings.VALIDATE_LENGTH_AND_CHECKSUM))
                session.ValidateLengthAndChecksum = settings.GetBool(SessionSettings.VALIDATE_LENGTH_AND_CHECKSUM);
            if (settings.Has(SessionSettings.RESETSEQUENCE_MESSAGE_REQUIRES_ORIGSENDINGTIME))
                session.RequiresOrigSendingTime = settings.GetBool(SessionSettings.RESETSEQUENCE_MESSAGE_REQUIRES_ORIGSENDINGTIME);

            return session;
        }
 public void AcceptSession(Session session)
 {
     acceptedSessions_[session.SessionID] = session;
 }