Esempio n. 1
0
 /// <summary>
 ///   Performs the task needed to clean up resources used by the <see cref="EventDataBatch" />.
 /// </summary>
 ///
 public void Dispose()
 {
     lock (SyncGuard)
     {
         AssertNotLocked();
         InnerBatch.Dispose();
     }
 }
Esempio n. 2
0
 /// <summary>
 ///   Clears the batch, removing all events and resetting the
 ///   available size.
 /// </summary>
 ///
 internal void Clear()
 {
     lock (SyncGuard)
     {
         AssertNotLocked();
         InnerBatch.Clear();
     }
 }
        /// <summary>
        ///   Attempts to add an event to the batch, ensuring that the size
        ///   of the batch does not exceed its maximum.
        /// </summary>
        ///
        /// <param name="eventData">The event to attempt to add to the batch.</param>
        ///
        /// <returns><c>true</c> if the event was added; otherwise, <c>false</c>.</returns>
        ///
        public bool TryAdd(EventData eventData)
        {
            bool instrumented = EventDataInstrumentation.InstrumentEvent(eventData, FullyQualifiedNamespace, EventHubName);
            bool added        = InnerBatch.TryAdd(eventData);

            if (!added && instrumented)
            {
                EventDataInstrumentation.ResetEvent(eventData);
            }

            return(added);
        }
Esempio n. 4
0
        /// <summary>
        ///   Attempts to add an event to the batch, ensuring that the size
        ///   of the batch does not exceed its maximum.
        /// </summary>
        ///
        /// <param name="eventData">The event to attempt to add to the batch.</param>
        ///
        /// <returns><c>true</c> if the event was added; otherwise, <c>false</c>.</returns>
        ///
        /// <remarks>
        ///   When an event is accepted into the batch, its content and state are frozen; any
        ///   changes made to the event will not be reflected in the batch nor will any state
        ///   transitions be reflected to the original instance.
        /// </remarks>
        ///
        /// <exception cref="InvalidOperationException">
        ///   When a batch is published, it will be locked for the duration of that operation.  During this time,
        ///   no events may be added to the batch.  Calling <c>TryAdd</c> while the batch is being published will
        ///   result in an <see cref="InvalidOperationException" /> until publishing has completed.
        /// </exception>
        ///
        public bool TryAdd(EventData eventData)
        {
            lock (SyncGuard)
            {
                AssertNotLocked();

                eventData = eventData.Clone();
                EventDataInstrumentation.InstrumentEvent(eventData, FullyQualifiedNamespace, EventHubName);

                var added = InnerBatch.TryAdd(eventData);

                if ((added) && (EventDataInstrumentation.TryExtractDiagnosticId(eventData, out string diagnosticId)))
                {
                    EventDiagnosticIdentifiers.Add(diagnosticId);
                }

                return(added);
            }
        }
Esempio n. 5
0
        /// <summary>
        ///   Attempts to add an event to the batch, ensuring that the size
        ///   of the batch does not exceed its maximum.
        /// </summary>
        ///
        /// <param name="eventData">The event to attempt to add to the batch.</param>
        ///
        /// <returns><c>true</c> if the event was added; otherwise, <c>false</c>.</returns>
        ///
        public bool TryAdd(EventData eventData)
        {
            bool instrumented = EventDataInstrumentation.InstrumentEvent(eventData, FullyQualifiedNamespace, EventHubName);
            bool added        = InnerBatch.TryAdd(eventData);

            if (added)
            {
                if (EventDataInstrumentation.TryExtractDiagnosticId(eventData, out string diagnosticId))
                {
                    EventDiagnosticIdentifiers.Add(diagnosticId);
                }
            }
            else if (instrumented)
            {
                EventDataInstrumentation.ResetEvent(eventData);
            }

            return(added);
        }
        /// <summary>
        ///   Attempts to add an event to the batch, ensuring that the size
        ///   of the batch does not exceed its maximum.
        /// </summary>
        ///
        /// <param name="eventData">The event to attempt to add to the batch.</param>
        ///
        /// <returns><c>true</c> if the event was added; otherwise, <c>false</c>.</returns>
        ///
        /// <remarks>
        ///   When an event is accepted into the batch, its content and state are frozen; any
        ///   changes made to the event will not be reflected in the batch nor will any state
        ///   transitions be reflected to the original instance.
        /// </remarks>
        ///
        /// <exception cref="InvalidOperationException">
        ///   When a batch is published, it will be locked for the duration of that operation.  During this time,
        ///   no events may be added to the batch.  Calling <c>TryAdd</c> while the batch is being published will
        ///   result in an <see cref="InvalidOperationException" /> until publishing has completed.
        /// </exception>
        ///
        public bool TryAdd(EventData eventData)
        {
            lock (SyncGuard)
            {
                AssertNotLocked();

                var messageScopeCreated = false;
                var identifier          = default(string);

                try
                {
                    (messageScopeCreated, identifier) = EventDataInstrumentation.InstrumentEvent(eventData, FullyQualifiedNamespace, EventHubName);

                    var added = InnerBatch.TryAdd(eventData);

                    if ((added) && (identifier != null))
                    {
                        EventDiagnosticIdentifiers.Add(identifier);
                    }

                    return(added);
                }
                finally
                {
                    // If a new message scope was added when instrumenting the instance, the identifier was
                    // added during this call.  If so, remove it so that the source event is not modified; the
                    // instrumentation will have been captured by the batch's copy of the event, if it was accepted
                    // into the batch.

                    if ((messageScopeCreated) && (identifier != null))
                    {
                        EventDataInstrumentation.ResetEvent(eventData);
                    }
                }
            }
        }
        /// <summary>
        ///   Attempts to add an event to the batch, ensuring that the size
        ///   of the batch does not exceed its maximum.
        /// </summary>
        ///
        /// <param name="eventData">The event to attempt to add to the batch.</param>
        ///
        /// <returns><c>true</c> if the event was added; otherwise, <c>false</c>.</returns>
        ///
        public bool TryAdd(EventData eventData)
        {
            if (_locked)
            {
                throw new InvalidOperationException(Resources.EventBatchIsLocked);
            }

            bool instrumented = EventDataInstrumentation.InstrumentEvent(eventData, FullyQualifiedNamespace, EventHubName);
            bool added        = InnerBatch.TryAdd(eventData);

            if (added)
            {
                if (EventDataInstrumentation.TryExtractDiagnosticId(eventData, out string diagnosticId))
                {
                    EventDiagnosticIdentifiers.Add(diagnosticId);
                }
            }
            else if (instrumented)
            {
                EventDataInstrumentation.ResetEvent(eventData);
            }

            return(added);
        }
Esempio n. 8
0
 /// <summary>
 ///   Represents the batch as an enumerable set of specific representations of an event.
 /// </summary>
 ///
 /// <typeparam name="T">The specific event representation being requested.</typeparam>
 ///
 /// <returns>The set of events as an enumerable of the requested type.</returns>
 ///
 internal IReadOnlyCollection <T> AsReadOnlyCollection <T>() => InnerBatch.AsReadOnlyCollection <T>();
Esempio n. 9
0
 /// <summary>
 ///   Represents the batch as an enumerable set of specific representations of an event.
 /// </summary>
 ///
 /// <typeparam name="T">The specific event representation being requested.</typeparam>
 ///
 /// <returns>The set of events as an enumerable of the requested type.</returns>
 ///
 internal IEnumerable <T> AsEnumerable <T>() => InnerBatch.AsEnumerable <T>();
Esempio n. 10
0
 /// <summary>
 ///   Resets the batch to remove sequencing information and publisher metadata assigned
 ///    by <see cref="ApplyBatchSequencing" />.
 /// </summary>
 ///
 internal void ResetBatchSequencing() => InnerBatch.ResetBatchSequencing();
Esempio n. 11
0
 /// <summary>
 ///   Assigns message sequence numbers and publisher metadata to the batch in
 ///   order to prepare it to be sent when certain features, such as idempotent retries,
 ///   are active.
 /// </summary>
 ///
 /// <param name="lastSequenceNumber">The sequence number assigned to the event that was most recently published to the associated partition successfully.</param>
 /// <param name="producerGroupId">The identifier of the producer group for which publishing is being performed.</param>
 /// <param name="ownerLevel">TThe owner level for which publishing is being performed.</param>
 ///
 /// <returns>The last sequence number applied to the batch.</returns>
 ///
 internal int ApplyBatchSequencing(int lastSequenceNumber,
                                   long?producerGroupId,
                                   short?ownerLevel) => InnerBatch.ApplyBatchSequencing(lastSequenceNumber, producerGroupId, ownerLevel);
 /// <summary>
 ///   Performs the task needed to clean up resources used by the <see cref="EventDataBatch" />.
 /// </summary>
 ///
 public void Dispose() => InnerBatch.Dispose();