public void ProcessMessage()
        {
            while (_queue.Count > 0)
            {
                lock (_stream)
                {
                    //var binaryWriter = MyBinaryWriter.Allocate(_stream);
                    _stream.Position = 0;

                    NetworkMessageRecoder.RecodMessageItem item = (NetworkMessageRecoder.RecodMessageItem)_queue.Dequeue();
                    try
                    {
                        var serializeInfo = _messageTypeInfo.GetSerializeInfo(item.MessageType);
                        if (serializeInfo != null)
                        {
                            item.Write(serializeInfo, _stream, _fileAppender);
                        }
                    }
                    catch (Exception e)
                    {
                        _logger.ErrorFormat("NetworkMessageRecoder thread{0}", e);
                    }
                    finally
                    {
                        item.ReleaseReference();
                    }
                }
            }
        }
Exemple #2
0
        public NetworkMessageRecoder.RecodMessageItem GetItem(int stage, int seq, int channel)
        {
            if (!_stageSet.Contains(stage))
            {
                _stageSet.Add(stage);
            }
            // _logger.InfoFormat("GetItem :{0}, {1}, {2}", stage, seq, channel);
            lastGetSeq   = seq;
            lastGetStage = stage;
            Queue queue;

            if (_dictionary.TryGetValue(new ReplayMessageKey(channel, stage), out queue))
            {
                if (queue.Count > 0)
                {
                    NetworkMessageRecoder.RecodMessageItem item = (NetworkMessageRecoder.RecodMessageItem)queue.Peek();
                    if (item.ProcessSeq <= seq)
                    {
                        _logger.DebugFormat("GetItem Succ:{0}, {1}, {2} {3} {4}", stage, seq, channel, item,
                                            queue.Count);
                        return((NetworkMessageRecoder.RecodMessageItem)queue.Dequeue());
                    }
                }
            }

            return(null);
        }
Exemple #3
0
        public bool ReadFromFile()
        {
            if (!_stageSet.Contains(lastGetStage))
            {
                return(false);
            }
            if (lastGetStage == lastReadStage && lastReadSeq > lastGetSeq + 30)
            {
                return(false);
            }
            if (!_reader.HasRemain())
            {
                return(false);
            }


            NetworkMessageRecoder.RecodMessageItem item = NetworkMessageRecoder.RecodMessageItem.Allocate();


            if (item.ReadFrom(_reader, _messageTypeInfo))
            {
                lastReadSeq   = item.ProcessSeq;
                lastReadStage = item.Stage;
                Queue queue;
                var   key = new ReplayMessageKey(item.ChannelId, item.Stage);
                if (!_dictionary.TryGetValue(key, out queue))
                {
                    queue            = Queue.Synchronized(new Queue());
                    _dictionary[key] = queue;
                }

                queue.Enqueue(item);
                if (queue.Count > 50)
                {
                    return(false);
                }
                return(true);
            }


            return(false);
        }
 public void AddMessage(NetworkMessageRecoder.RecodMessageItem item)
 {
     _queue.Enqueue(item);
 }