Esempio n. 1
0
 /// <summary>
 /// 队列数据 读文件
 /// </summary>
 /// <param name="writer">队列数据 写文件</param>
 /// <param name="config">队列数据 读取配置</param>
 internal FileReaderBase(FileWriter writer, ReaderConfig config)
 {
     saveStateHandle = saveState;
     Writer          = writer;
     Config          = config;
     config.Format();
 }
Esempio n. 2
0
        /// <summary>
        /// 查询数据
        /// </summary>
        /// <param name="parser">参数解析</param>
        internal override void QueryEnd(ref OperationParameter.NodeParser parser)
        {
            switch (parser.OperationType)
            {
            case OperationParameter.OperationType.MessageQueueEnqueue: enqueue(ref parser, ValueData.Data <valueType> .DataType); return;

            case OperationParameter.OperationType.MessageQueueGetDequeueIdentity:
                ReaderConfig config = getReaderConfig <ReaderConfig>(ref parser);
                if (config != null)
                {
                    if (reader == null || reader.IsDisposed)
                    {
                        Writer.OnStart(new QueueTaskThread.GetIdentity(this, config, ref parser));
                    }
                    else
                    {
                        parser.ReturnParameter.ReturnParameterSet(reader.Identity);
                    }
                }
                return;

            case OperationParameter.OperationType.MessageQueueDequeue:
                if (parser.ValueData.Type == ValueData.DataType.ULong)
                {
                    FileReader reader = this.reader;
                    if (reader != null && !reader.IsDisposed)
                    {
                        if (parser.OnReturn != null)
                        {
                            Writer.OnStart(new QueueTaskThread.GetMessage(reader, ref parser));
                        }
                    }
                    else
                    {
                        parser.ReturnParameter.ReturnType = ReturnType.MessageQueueNotFoundReader;
                    }
                }
                else
                {
                    parser.ReturnParameter.ReturnType = ReturnType.ValueDataLoadError;
                }
                return;

            case OperationParameter.OperationType.MessageQueueSetDequeueIdentity: setDequeueIdentity(ref parser, this.reader); return;
            }
            parser.ReturnParameter.ReturnType = ReturnType.OperationTypeError;
        }
Esempio n. 3
0
        /// <summary>
        /// 队列数据 读文件
        /// </summary>
        /// <param name="node">消息队列节点</param>
        /// <param name="config">队列数据 读取配置</param>
        /// <param name="readerIndex">读文件编号</param>
        internal FileReader(Node node, ReaderConfig config, int readerIndex) : base(node.Writer, config ?? defaultConfig)
        {
            Node             = node;
            this.readerIndex = readerIndex;
            int isReader = 0;

            writerAppendIdentity = Writer.NewRead();
            try
            {
                loadStateFile();
                long fileIndex = 0;
                if (loadIndex(ref fileIndex))
                {
                    messages = new MessageItem[(int)config.MemoryCacheNodeCount + FileWriter.MaxPacketCount + 1];
                    if (Identity == writerAppendIdentity)
                    {
                        isReader = 1;
                    }
                    else
                    {
                        loadFile(fileIndex);
                        if (loadFile())
                        {
                            isReader = 1;
                        }
                    }
                }
            }
            finally
            {
                if (isReader == 0)
                {
                    Dispose();
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// 获取下一个节点
        /// </summary>
        /// <param name="parser"></param>
        /// <returns></returns>
        internal override Cache.Node GetQueryNext(ref OperationParameter.NodeParser parser)
        {
            int readerIndex;

            switch (parser.OperationType)
            {
            case OperationParameter.OperationType.MessageQueueGetDequeueIdentity:
                if ((readerIndex = getReaderIndex(ref parser)) >= 0)
                {
                    ReaderConfig config = getReaderConfig <ReaderConfig>(ref parser);
                    if (config != null)
                    {
                        if (readerIndex < readers.Length)
                        {
                            FileReader reader = readers[readerIndex];
                            if (reader != null && !reader.IsDisposed)
                            {
                                parser.ReturnParameter.ReturnParameterSet(reader.Identity);
                                return(null);
                            }
                        }
                        Writer.OnStart(new QueueTaskThread.GetIdentity(this, config, ref parser, readerIndex));
                    }
                }
                return(null);

            case OperationParameter.OperationType.MessageQueueDequeue:
                if ((readerIndex = getReaderIndex(ref parser)) >= 0)
                {
                    if (parser.ValueData.Type == ValueData.DataType.ULong)
                    {
                        if (readerIndex < readers.Length)
                        {
                            FileReader reader = readers[readerIndex];
                            if (reader != null && !reader.IsDisposed)
                            {
                                if (parser.OnReturn != null)
                                {
                                    Writer.OnStart(new QueueTaskThread.GetMessage(reader, ref parser));
                                }
                                return(null);
                            }
                        }
                        parser.ReturnParameter.ReturnType = ReturnType.MessageQueueNotFoundReader;
                    }
                    else
                    {
                        parser.ReturnParameter.ReturnType = ReturnType.ValueDataLoadError;
                    }
                }
                return(null);

            case OperationParameter.OperationType.MessageQueueSetDequeueIdentity:
                if ((uint)(readerIndex = getReaderIndex(ref parser)) < readers.Length)
                {
                    setDequeueIdentity(ref parser, readers[readerIndex]);
                }
                return(null);
            }
            parser.ReturnParameter.ReturnType = ReturnType.OperationTypeError;
            return(null);
        }