LookupSession() публичный статический Метод

Looks up a Session by its SessionID
public static LookupSession ( SessionID sessionID ) : Session
sessionID SessionID the SessionID of the Session
Результат Session
Пример #1
0
        protected void OnMessageFoundInternal(string msg)
        {
            // Message fixMessage;

            try
            {
                if (null == qfSession_)
                {
                    Message adjustedMsg = null;

                    if (socketSettings_.RjoAdapterTestMode)
                    {
                        this.Log("RjoAdapterTestMode: ignoring SenderSubID & SenderLocID in sender's logon message");
                        // need to ignore client's SubID when looking up session
                        Regex  rgx = new Regex($"{Message.SOH}50=[^{Message.SOH}]*");
                        string s   = rgx.Replace(msg, "");
                        rgx         = new Regex($"{Message.SOH}142=[^{Message.SOH}]*");
                        s           = rgx.Replace(s, "");
                        adjustedMsg = new Message(s, false);
                    }
                    else
                    {
                        adjustedMsg = new Message(msg);
                    }

                    qfSession_ = Session.LookupSession(Message.GetReverseSessionID(adjustedMsg));
                    if (null == qfSession_)
                    {
                        this.Log("ERROR: Disconnecting; received message for unknown session: " + adjustedMsg);
                        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);
            }
        }
Пример #2
0
        /// <summary>
        /// FIXME send Message, not string
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static bool SendToTarget(Message message, SessionID sessionID)
        {
            message.SetSessionID(sessionID);
            Session session = Session.LookupSession(sessionID);

            if (null == session)
            {
                throw new SessionNotFound(sessionID);
            }
            return(session.Send(message));
        }
Пример #3
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 (IsAssumedSession(qfSession_.SessionID))
                    {
                        this.Log("ERROR: Disconnecting; received message for unknown session: " + msg);
                        qfSession_ = null;
                        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);
            }
        }
Пример #4
0
        public void Stop(bool force)
        {
            if (IsStopped)
            {
                return;
            }

            List <Session> enabledSessions = new List <Session>();

            lock (sync_)
            {
                foreach (SessionID sessionID in connected_)
                {
                    Session session = Session.LookupSession(sessionID);
                    if (session.IsEnabled)
                    {
                        enabledSessions.Add(session);
                        session.Logout();
                    }
                }
            }

            if (!force)
            {
                for (int second = 0; (second < 10) && IsLoggedOn(); ++second)
                {
                    Thread.Sleep(1000);
                }
            }

            lock (sync_)
            {
                HashSet <SessionID> connectedSessionIDs = new HashSet <SessionID>(connected_);
                foreach (SessionID sessionID in connectedSessionIDs)
                {
                    SetDisconnected(Session.LookupSession(sessionID).SessionID);
                }
            }

            isStopped_ = true;
            OnStop();
            thread_.Join(5000);
            thread_ = null;

            foreach (Session session in enabledSessions)
            {
                session.Logon();
            }
        }
Пример #5
0
        protected void OnMessageFoundInternal(string msg)
        {
            ///Message fixMessage;

            try
            {
                if (null == qfSession_)
                {
                    qfSession_ = Session.LookupSession(Message.GetReverseSessionID(msg));

                    if (null == qfSession_)
                    {
                        // If more complete QFn session (inc SubID tags etc) does not exist then perform session lookup using Version, TargetCompID and SenderCompID only
                        qfSession_ = Session.LookupSession(Message.GetBasicReverseSessionID(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);
            }
        }
Пример #6
0
        public bool IsLoggedOn()
        {
            lock (sync_)
            {
                foreach (SessionID sessionID in connected_)
                {
                    if (Session.LookupSession(sessionID).IsLoggedOn)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Пример #7
0
 protected void Connect()
 {
     lock (sync_)
     {
         HashSet <SessionID> disconnectedSessions = new HashSet <SessionID>(disconnected_);
         foreach (SessionID sessionID in disconnectedSessions)
         {
             Session session = Session.LookupSession(sessionID);
             if (session.IsEnabled && session.IsSessionTime)
             {
                 DoConnect(sessionID, settings_.Get(sessionID));
             }
         }
     }
 }
Пример #8
0
 protected void Connect()
 {
     lock (sync_)
     {
         HashSet <SessionID> disconnectedSessions = new HashSet <SessionID>(disconnected_);
         foreach (SessionID sessionID in disconnectedSessions)
         {
             Session session = Session.LookupSession(sessionID);
             if (session.IsEnabled)
             {
                 if (session.IsNewSession)
                 {
                     session.Reset("New session");
                 }
                 if (session.IsSessionTime)
                 {
                     DoConnect(sessionID, _settings.Get(sessionID));
                 }
             }
         }
     }
 }
Пример #9
0
 protected void Connect()
 {
     lock (GdaxPrototyping.Common.Core.Threading.TThreadingHelpers.MainLockable)
     {
         HashSet <SessionID> disconnectedSessions = new HashSet <SessionID>(disconnected_);
         foreach (SessionID sessionID in disconnectedSessions)
         {
             Session session = Session.LookupSession(sessionID);
             if (session.IsEnabled)
             {
                 if (session.IsNewSession)
                 {
                     session.Reset("New session");
                 }
                 if (session.IsSessionTime)
                 {
                     DoConnect(sessionID, _settings.Get(sessionID));
                 }
             }
         }
     }
 }
Пример #10
0
        /// <summary>
        /// Logout existing session and close connection
        /// </summary>
        /// <param name="force">If true, terminate immediately.  </param>
        public void Stop(bool force)
        {
            if (_disposed)
            {
                throw new System.ObjectDisposedException(this.GetType().Name);
            }

            if (IsStopped)
            {
                return;
            }

            List <Session> enabledSessions = new List <Session>();

            lock (sync_)
            {
                foreach (SessionID sessionID in connected_)
                {
                    Session session = Session.LookupSession(sessionID);
                    if (session.IsEnabled)
                    {
                        enabledSessions.Add(session);
                        session.Logout();
                    }
                }
            }

            if (!force)
            {
                // TODO change this duration to always exceed LogoutTimeout setting
                for (int second = 0; (second < 10) && IsLoggedOn; ++second)
                {
                    Thread.Sleep(1000);
                }
            }

            lock (sync_)
            {
                HashSet <SessionID> connectedSessionIDs = new HashSet <SessionID>(connected_);
                foreach (SessionID sessionID in connectedSessionIDs)
                {
                    SetDisconnected(Session.LookupSession(sessionID).SessionID);
                }
            }

            isStopped_ = true;
            OnStop();

            // Give OnStop() time to finish its business
            thread_.Join(5000);
            thread_ = null;

            // dispose all sessions and clear all session sets
            lock (sync_)
            {
                foreach (Session s in sessions_.Values)
                {
                    s.Dispose();
                }

                sessions_.Clear();
                sessionIDs_.Clear();
                pending_.Clear();
                connected_.Clear();
                disconnected_.Clear();
            }
        }