internal void CallOnReturn(ulong identity) { ReturnParameter returnParameter = default(ReturnParameter); returnParameter.Set(identity); onReturn(returnParameter); onReturn = null; }
/// <summary> /// 获取数据 /// </summary> /// <param name="getMessage"></param> internal void Get(QueueTaskThread.GetMessage getMessage) { ReturnType returnType = ReturnType.MessageQueueNotFoundReader; try { if (isDisposed == 0) { if (getMessage.Identity == Identity) { if (onGetMessage == null || !onGetMessage.Callback(new ReturnParameter(ReturnType.Success))) { onGetMessage = getMessage.OnReturn; isGetMessageStream = getMessage.IsReturnStream; ulong endIdentity = Math.Min(Identity + Config.SendClientCount, writeIdentity); sendIdentity = Identity; sendMessageIndex = messageIndex; getMessage = null; ReturnParameter returnParameter = default(ReturnParameter); while (sendIdentity != endIdentity) { returnParameter.Set(messages[sendMessageIndex].Data, isGetMessageStream); if (onGetMessage.Callback(returnParameter)) { nextSendIndex(); } else { onGetMessage = null; return; } } return; } else { returnType = ReturnType.MessageQueueGetMessageExists; } } else { returnType = ReturnType.MessageQueueReaderIdentityError; } } } finally { if (getMessage != null) { getMessage.OnReturn.Callback(new ReturnParameter(returnType)); } } }
/// <summary> /// 设置已完成消息标识 /// </summary> internal void SaveIdentity() { ulong identity = (ulong)Interlocked.Exchange(ref currentSetIdentity, 0L); if (identity > Identity && identity <= sendIdentity) { saveState(identity); if (isDisposed == 0) { int endMessageIndex = messageIndex + (int)(uint)(identity - Identity); if (endMessageIndex >= messages.Length) { endMessageIndex -= messages.Length; } do { messages[messageIndex].OnMessage(); if (++messageIndex == messages.Length) { for (messageIndex = 0; messageIndex != endMessageIndex; messages[messageIndex++].OnMessage()) { ; } break; } }while (messageIndex != endMessageIndex); Identity = identity; memoryEndIdentity = identity + Config.MemoryCacheNodeCount; if (writeIdentity < memoryEndIdentity && writeIdentity < writerAppendIdentity) { byte isReader = 0, isLoadFile = 0; try { if (dataFileStream != null) { if (dataFileIdentity == writeIdentity) { isLoadFile = 1; if (loadFile()) { isReader = 1; } } else { dataFileStream.Dispose(); dataFileStream = null; } } if (isLoadFile == 0) { long fileIndex = 0; if (Writer.GetIndex(writeIdentity, ref dataFileIdentity, ref fileIndex)) { loadFile(fileIndex); if (loadFile()) { isReader = 1; } } } } finally { if (isReader == 0) { Dispose(); } } } if (isDisposed == 0 && onGetMessage != null) { ReturnParameter returnParameter = default(ReturnParameter); ulong endIdentity = Math.Min(Identity + Config.SendClientCount, writeIdentity); while (sendIdentity != endIdentity) { returnParameter.Set(messages[sendMessageIndex].Data, isGetMessageStream); if (onGetMessage.Callback(returnParameter)) { nextSendIndex(); } else { onGetMessage = null; return; } } } } } }