Example #1
0
        public void enqueueDelayedMessages(ICommunicationMessage msg)
        {
            msg.SetValue("LAST_SEQ_ID", m_last_seq_id);
            m_last_seq_id = msg.SeqID;

            _sendMessage(msg);
            //lock (m_DelayedMessages)
            //    m_DelayedMessages.Enqueue(msg);

            //m_SignalNewMessage.Set();
        }
Example #2
0
        private void _worker(object state)
        {
            try
            {
                m_ClearEvent.Reset();

                while (Interlocked.Read(ref m_Run) == 1)
                {
                    m_SignalNewMessage.WaitOne();
                    if (Interlocked.Read(ref m_Run) == 0)
                    {
                        return;
                    }

                    // 一次命令激活发送完队列中所有数据
                    while (Interlocked.Read(ref m_Run) == 1)
                    {
                        List <ICommunicationMessage> tobesent = new List <ICommunicationMessage>();
                        lock (m_Messages)
                        {
                            while (m_Messages.Count > 0)
                            {
                                tobesent.Add(m_Messages.Dequeue());
                            } // endif

                            Thread.Sleep(0);
                        }

                        foreach (ICommunicationMessage msg in tobesent)
                        {
                            msg.SetValue("LAST_SEQ_ID", m_last_seq_id);
                            m_last_seq_id = msg.SeqID;

                            //msg.RemoveKey("ClientID");
                            _sendMessage(msg);
                        }
                        tobesent.Clear();

                        List <ICommunicationMessage> alarms = new List <ICommunicationMessage>();
                        lock (m_DelayedMessages)
                        {
                            if (m_DelayedMessages.Count == 0)
                            {
                                break;
                            }

                            int i = 0;
                            while (m_DelayedMessages.Count > 0 && ++i <= 50)
                            {
                                ICommunicationMessage msg = m_DelayedMessages.Dequeue();

                                msg.SetValue("LAST_SEQ_ID", m_last_seq_id);
                                m_last_seq_id = msg.SeqID;

                                //msg.RemoveKey("ClientID");
                                alarms.Add(msg);
                            }
                        }

                        if (alarms.Count > 0)
                        {
                            _sendMessage(alarms);
                        }

                        Thread.Sleep(0);

                        lock (m_DelayedMessages)
                        {
                            if (m_DelayedMessages.Count == 0)
                            {
                                break;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                m_ClearEvent.Set();

                try
                {
                    SendLog(ex.Message);
                    InvokeConnectionBroken(this, m_ClientInfo.ToString());
                }
                catch { }
            }
            finally
            {
                m_ClearEvent.Set();
            }
        }