Example #1
0
        /// <summary>
        /// 队列数据 读文件
        /// </summary>
        /// <param name="node">消息队列节点</param>
        /// <param name="config">队列数据 读取配置</param>
        /// <param name="readerIndex">读文件编号</param>
        internal QueueReader(QueueNode node, Config.QueueReader config, int readerIndex)
        {
            Writer      = node.Writer;
            Node        = node;
            this.config = config ?? defaultConfig;
            this.config.Format();
            this.readerIndex = readerIndex;
            int isReader = 0;

            ++Writer.ReadCount;
            writerAppendIdentity = Writer.StatePacketIndex.Identity;
            try
            {
                if (checkStateFile())
                {
                    stateFileStream = new FileStream(stateFileName, FileMode.Open, FileAccess.ReadWrite, FileShare.Read, 256, FileOptions.None);
                    stateFileStream.Seek(-stateBufferSize, SeekOrigin.End);
                    stateFileStream.Read(bigBuffer, 0, stateBufferSize);

                    fixed(byte *stateDataFixed = bigBuffer) Identity = *(ulong *)stateDataFixed;
                }
                else
                {
                    stateFileStream = new FileStream(stateFileName, FileMode.CreateNew, FileAccess.Write, FileShare.Read, 256, FileOptions.None);
                }
                long fileIndex = 0;
                if (Writer.GetIndex(Identity, ref dataFileIdentity, ref fileIndex))
                {
                    writeIdentity     = Identity;
                    memoryEndIdentity = Identity + config.MemoryCacheNodeCount;
                    messages          = new MessageItem[(int)config.MemoryCacheNodeCount + QueueWriter.MaxPacketCount + 1];
                    if (Identity == writerAppendIdentity || loadFile(fileIndex))
                    {
                        isReader = 1;
                    }
                }
            }
            finally
            {
                if (isReader == 0)
                {
                    Dispose();
                }
            }
        }
Example #2
0
 /// <summary>
 /// 初始化
 /// </summary>
 protected override void start()
 {
     AutoCSer.Threading.ThreadPool.Tiny.Start((Writer = new File.QueueWriter(this)).Start);
 }