Пример #1
0
        // Placed object message payload into a segment from a buffer pool.  When this get's too big, older blocks will be purged
        private ArraySegment <byte> SerializeMessageIntoPooledSegment(GeneratedBatchContainer queueMessage)
        {
            byte[] serializedPayload = this.serializationManager.SerializeToByteArray(queueMessage.Payload);
            // get size of namespace, offset, partitionkey, properties, and payload
            int size = SegmentBuilder.CalculateAppendSize(serializedPayload);

            // get segment
            ArraySegment <byte> segment;

            if (currentBuffer == null || !currentBuffer.TryGetSegment(size, out segment))
            {
                // no block or block full, get new block and try again
                currentBuffer = bufferPool.Allocate();
                //call EvictionStrategy's OnBlockAllocated method
                this.evictionStrategy.OnBlockAllocated(currentBuffer);
                // if this fails with clean block, then requested size is too big
                if (!currentBuffer.TryGetSegment(size, out segment))
                {
                    string errmsg = $"Message size is to big. MessageSize: {size}";
                    throw new ArgumentOutOfRangeException(nameof(queueMessage), errmsg);
                }
            }

            // encode namespace, offset, partitionkey, properties and payload into segment
            int writeOffset = 0;

            SegmentBuilder.Append(segment, ref writeOffset, serializedPayload);

            return(segment);
        }
Пример #2
0
        private CachedMessage QueueMessageToCachedMessage(GeneratedBatchContainer queueMessage, DateTime dequeueTimeUtc)
        {
            StreamPosition streamPosition = GetStreamPosition(queueMessage);

            return(new CachedMessage()
            {
                StreamId = streamPosition.StreamId,
                SequenceNumber = queueMessage.RealToken.SequenceNumber,
                EnqueueTimeUtc = queueMessage.EnqueueTimeUtc,
                DequeueTimeUtc = dequeueTimeUtc,
                Segment = SerializeMessageIntoPooledSegment(queueMessage)
            });
        }
Пример #3
0
        private CachedMessage QueueMessageToCachedMessage(GeneratedBatchContainer queueMessage, DateTime dequeueTimeUtc)
        {
            StreamPosition streamPosition = GetStreamPosition(queueMessage);

            return(new CachedMessage()
            {
                StreamGuid = streamPosition.StreamIdentity.Guid,
                StreamNamespace = streamPosition.StreamIdentity.Namespace != null?string.Intern(streamPosition.StreamIdentity.Namespace) : null,
                                      SequenceNumber = queueMessage.RealToken.SequenceNumber,
                                      EnqueueTimeUtc = queueMessage.EnqueueTimeUtc,
                                      DequeueTimeUtc = dequeueTimeUtc,
                                      Segment = SerializeMessageIntoPooledSegment(queueMessage)
            });
        }
Пример #4
0
        private bool TryGenerateBatch(out GeneratedBatchContainer batch)
        {
            batch = null;
            if (sequenceId >= this.options.EventsInStream)
            {
                return(false);
            }
            sequenceId++;
            var evt = new GeneratedEvent
            {
                // If this is the last event generated, mark it as such, so test grains know to report results.
                EventType = (sequenceId != this.options.EventsInStream)
                        ? GeneratedEvent.GeneratedEventType.Fill
                        : GeneratedEvent.GeneratedEventType.Report
            };

            batch = new GeneratedBatchContainer(streamId, evt, new EventSequenceTokenV2(sequenceId));
            return(true);
        }
Пример #5
0
 private StreamPosition GetStreamPosition(GeneratedBatchContainer queueMessage)
 {
     return(new StreamPosition(queueMessage.StreamId, queueMessage.RealToken));
 }
Пример #6
0
 private StreamPosition GetStreamPosition(GeneratedBatchContainer queueMessage)
 {
     return(new StreamPosition(new StreamIdentity(queueMessage.StreamGuid, queueMessage.StreamNamespace), queueMessage.RealToken));
 }