コード例 #1
0
        public void Restore()
        {
            var restoreEnumerator = persistentStorage.Restore().GetEnumerator();

            if (!restoreEnumerator.MoveNext())
            {
                persistedMessageId = lastMessageId = -1;
                data = new InfiniteArray <Message>(0, dataArrayOptions);
                RestoreSubscriptions();
                return;
            }

            data = new InfiniteArray <Message>(restoreEnumerator.Current.ID, dataArrayOptions);
            data.Add(restoreEnumerator.Current);

            while (restoreEnumerator.MoveNext())
            {
                data.Add(restoreEnumerator.Current);
            }

            currentData = new DataSnapshot()
            {
                StartMessageId = data.GetFirstItemIndex(),
                Data           = data.GetDataBlocks()
            };

            persistedMessageId = lastMessageId = currentData.Data[^ 1].Span[^ 1].ID;
コード例 #2
0
        public void Write(WriteManyRequest request)
        {
            lock (sync)
            {
                if (disposed)
                {
                    throw new TopicWriterException($"Cannot write to disposed {nameof(TopicWriter)}");
                }

                var writeResult = topic.Write(request.Messages.Span);
                idMap.Add(new IdPair(request.SequenceNumber, writeResult.LastInsertedIndex));
            }
        }
コード例 #3
0
        internal TopicWriteResult Write(ReadOnlySpan <ReadOnlyMemory <byte> > messages)
        {
            lock (dataSync)
            {
                var enqueuedTime = DateTime.UtcNow;
                var newMessages  = new Message[messages.Length];
                for (int i = 0; i < newMessages.Length; i++)
                {
                    newMessages[i] = new Message(lastMessageId + i + 1, enqueuedTime, messages[i]);
                }

                var ind = data.Add(newMessages);
                persistentStorage.Write(newMessages);
                lastMessageId += messages.Length;
                return(new TopicWriteResult(ind, enqueuedTime));
            }
        }