private void WaitForDelay(MatcherEntry entry) { while (!entry.CanBeProcessed(_persistenceConfiguration.PersisterDelay.GetValueOrDefault())) { Thread.Sleep(100); } }
public void EnqueueAck(PeerId peerId, MessageId messageId) { _ackMessageKeys.Add(new MessageKey(peerId, messageId)); var entry = MatcherEntry.Ack(peerId, messageId); _persistenceQueue.Add(entry); }
private void LoadBatch(List <MatcherEntry> batch, out MatcherEntry nextEntry) { var configuration = _persistenceConfiguration; while (batch.Count < configuration.PersisterBatchSize && _persistenceQueue.TryTake(out var entry)) { if (!entry.CanBeProcessed(configuration.PersisterDelay.GetValueOrDefault())) { // the dequeued entry cannot be processed now nextEntry = entry; return; } PairUpOrAddToBatch(batch, entry); } // all dequeued entries are int the batch nextEntry = null; }
private void PairUpOrAddToBatch(List <MatcherEntry> batch, MatcherEntry entry) { switch (entry.Type) { case MatcherEntryType.Message: var isPairUpSuccessfull = _ackMessageKeys.Remove(new MessageKey(entry.PeerId, entry.MessageId)); if (isPairUpSuccessfull) { InMemoryAckCount++; return; } break; case MatcherEntryType.Ack: var isAlreadyPairedUp = !_ackMessageKeys.Remove(new MessageKey(entry.PeerId, entry.MessageId)); if (isAlreadyPairedUp) { return; } break; } batch.Add(entry); }
public void EnqueueWaitHandle(EventWaitHandle waitHandle) { _persistenceQueue.Add(MatcherEntry.EventWaitHandle(waitHandle)); }
public void EnqueueMessage(PeerId peerId, MessageId messageId, MessageTypeId messageTypeId, byte[] bytes) { var entry = MatcherEntry.Message(peerId, messageId, messageTypeId, bytes); _persistenceQueue.Add(entry); }