Esempio n. 1
0
        public override IAppendable Normalize(char[] src, IAppendable dest)
        {
            ReorderingBuffer buffer = new ReorderingBuffer(Impl, dest, src.Length);

            Normalize(src, buffer);
            buffer.Flush();
            return(dest);
        }
Esempio n. 2
0
 public CaptureController(IActorContext context,
                          IActorRef contractor,
                          IActorRef captureControllerActor,
                          IRawPacketBatchParserActorFactory rawPacketBatchParserActorFactory)
 {
     this._context                          = context;
     this._contractor                       = contractor;
     this._captureControllerActor           = captureControllerActor;
     this._rawPacketBatchParserActorFactory = rawPacketBatchParserActorFactory;
     this._reorderingBuffer                 = new ReorderingBuffer();
 }
Esempio n. 3
0
        public override IAppendable Normalize(StringBuilder src, IAppendable dest)
        {
            if (dest is StringBuilderCharSequence && ((StringBuilderCharSequence)dest).Value == src)
            {
                throw new ArgumentException($"'{nameof(src)}' cannot be the same instance as '{nameof(dest)}'");
            }
            ReorderingBuffer buffer = new ReorderingBuffer(Impl, dest, src.Length);

            Normalize(src, buffer);
            buffer.Flush();
            return(dest);
        }
Esempio n. 4
0
 protected override void Normalize(char[] src, ReorderingBuffer buffer)
 {
     Impl.MakeFCD(src, 0, src.Length, buffer);
 }
Esempio n. 5
0
 public override void NormalizeAndAppend(
     ICharSequence src, bool doNormalize, ReorderingBuffer buffer)
 {
     Impl.ComposeAndAppend(src, doNormalize, onlyContiguous, buffer);
 }
Esempio n. 6
0
 protected override void NormalizeAndAppend(
     char[] src, bool doNormalize, ReorderingBuffer buffer)
 {
     Impl.ComposeAndAppend(src, doNormalize, onlyContiguous, buffer);
 }
Esempio n. 7
0
 public override void Normalize(ICharSequence src, ReorderingBuffer buffer)
 {
     Impl.Compose(src, 0, src.Length, onlyContiguous, true, buffer);
 }
Esempio n. 8
0
 public override void NormalizeAndAppend(
     ICharSequence src, bool doNormalize, ReorderingBuffer buffer)
 {
     Impl.MakeFCDAndAppend(src, doNormalize, buffer);
 }
Esempio n. 9
0
 public abstract void NormalizeAndAppend(
     ICharSequence src, bool doNormalize, ReorderingBuffer buffer);
Esempio n. 10
0
 protected abstract void NormalizeAndAppend(
     char[] src, bool doNormalize, ReorderingBuffer buffer);
Esempio n. 11
0
 protected abstract void NormalizeAndAppend(
     StringBuilder src, bool doNormalize, ReorderingBuffer buffer);
Esempio n. 12
0
 public abstract void Normalize(ICharSequence src, ReorderingBuffer buffer);
Esempio n. 13
0
 protected abstract void Normalize(char[] src, ReorderingBuffer buffer);
Esempio n. 14
0
 protected abstract void Normalize(StringBuilder src, ReorderingBuffer buffer);
Esempio n. 15
0
 public override void Normalize(ICharSequence src, ReorderingBuffer buffer)
 {
     Impl.MakeFCD(src, 0, src.Length, buffer);
 }
Esempio n. 16
0
 protected override void Normalize(StringBuilder src, ReorderingBuffer buffer)
 {
     Impl.Decompose(src, 0, src.Length, buffer);
 }
Esempio n. 17
0
 protected override void NormalizeAndAppend(
     char[] src, bool doNormalize, ReorderingBuffer buffer)
 {
     Impl.MakeFCDAndAppend(src, doNormalize, buffer);
 }
Esempio n. 18
0
 protected override void NormalizeAndAppend(StringBuilder src, bool doNormalize, ReorderingBuffer buffer)
 {
     Impl.DecomposeAndAppend(src, doNormalize, buffer);
 }
Esempio n. 19
0
 public ReorderingBufferTests()
 {
     this._reorderingBufferSUT = new ReorderingBuffer();
 }
Esempio n. 20
0
 protected override void Normalize(char[] src, ReorderingBuffer buffer)
 {
     Impl.Compose(src, 0, src.Length, onlyContiguous, true, buffer);
 }
Esempio n. 21
0
        /// <summary>Initializes the <see cref="TransformManyBlock{TInput,TOutput}"/> with the specified function and <see cref="ExecutionDataflowBlockOptions"/>.</summary>
        /// <param name="transformSync">The synchronous function to invoke with each data element received.</param>
        /// <param name="transformAsync">The asynchronous function to invoke with each data element received.</param>
        /// <param name="dataflowBlockOptions">The options with which to configure this <see cref="TransformManyBlock{TInput,TOutput}"/>.</param>
        /// <exception cref="System.ArgumentNullException">The <paramref name="transformSync"/> and <paramref name="transformAsync"/> are both null (Nothing in Visual Basic).</exception>
        /// <exception cref="System.ArgumentNullException">The <paramref name="dataflowBlockOptions"/> is null (Nothing in Visual Basic).</exception>
        private TransformManyBlock(Func <TInput, IEnumerable <TOutput> > transformSync, Func <TInput, Task <IEnumerable <TOutput> > > transformAsync, ExecutionDataflowBlockOptions dataflowBlockOptions)
        {
            // Validate arguments.  It's ok for the filterFunction to be null, but not the other parameters.
            if (transformSync == null && transformAsync == null)
            {
                throw new ArgumentNullException("transform");
            }
            if (dataflowBlockOptions == null)
            {
                throw new ArgumentNullException(nameof(dataflowBlockOptions));
            }

            Contract.Requires(transformSync == null ^ transformAsync == null, "Exactly one of transformSync and transformAsync must be null.");
            Contract.EndContractBlock();

            // Ensure we have options that can't be changed by the caller
            dataflowBlockOptions = dataflowBlockOptions.DefaultOrClone();

            // Initialize onItemsRemoved delegate if necessary
            Action <ISourceBlock <TOutput>, int> onItemsRemoved = null;

            if (dataflowBlockOptions.BoundedCapacity > 0)
            {
                onItemsRemoved = (owningSource, count) => ((TransformManyBlock <TInput, TOutput>)owningSource)._target.ChangeBoundingCount(-count);
            }

            // Initialize source component
            _source = new SourceCore <TOutput>(this, dataflowBlockOptions,
                                               owningSource => ((TransformManyBlock <TInput, TOutput>)owningSource)._target.Complete(exception: null, dropPendingMessages: true),
                                               onItemsRemoved);

            // If parallelism is employed, we will need to support reordering messages that complete out-of-order.
            // However, a developer can override this with EnsureOrdered == false.
            if (dataflowBlockOptions.SupportsParallelExecution && dataflowBlockOptions.EnsureOrdered)
            {
                _reorderingBuffer = new ReorderingBuffer <IEnumerable <TOutput> >(
                    this, (source, messages) => ((TransformManyBlock <TInput, TOutput>)source)._source.AddMessages(messages));
            }

            // Create the underlying target and source
            if (transformSync != null) // sync
            {
                // If an enumerable function was provided, we can use synchronous completion, meaning
                // that the target will consider a message fully processed as soon as the
                // delegate returns.
                _target = new TargetCore <TInput>(this,
                                                  messageWithId => ProcessMessage(transformSync, messageWithId),
                                                  _reorderingBuffer, dataflowBlockOptions, TargetCoreOptions.None);
            }
            else // async
            {
                Debug.Assert(transformAsync != null, "Incorrect delegate type.");

                // If a task-based function was provided, we need to use asynchronous completion, meaning
                // that the target won't consider a message completed until the task
                // returned from that delegate has completed.
                _target = new TargetCore <TInput>(this,
                                                  messageWithId => ProcessMessageWithTask(transformAsync, messageWithId),
                                                  _reorderingBuffer, dataflowBlockOptions, TargetCoreOptions.UsesAsyncCompletion);
            }

            // Link up the target half with the source half.  In doing so,
            // ensure exceptions are propagated, and let the source know no more messages will arrive.
            // As the target has completed, and as the target synchronously pushes work
            // through the reordering buffer when async processing completes,
            // we know for certain that no more messages will need to be sent to the source.
            _target.Completion.ContinueWith((completed, state) =>
            {
                var sourceCore = (SourceCore <TOutput>)state;
                if (completed.IsFaulted)
                {
                    sourceCore.AddAndUnwrapAggregateException(completed.Exception);
                }
                sourceCore.Complete();
            }, _source, CancellationToken.None, Common.GetContinuationOptions(), TaskScheduler.Default);

            // It is possible that the source half may fault on its own, e.g. due to a task scheduler exception.
            // In those cases we need to fault the target half to drop its buffered messages and to release its
            // reservations. This should not create an infinite loop, because all our implementations are designed
            // to handle multiple completion requests and to carry over only one.
            _source.Completion.ContinueWith((completed, state) =>
            {
                var thisBlock = ((TransformManyBlock <TInput, TOutput>)state) as IDataflowBlock;
                Debug.Assert(completed.IsFaulted, "The source must be faulted in order to trigger a target completion.");
                thisBlock.Fault(completed.Exception);
            }, this, CancellationToken.None, Common.GetContinuationOptions() | TaskContinuationOptions.OnlyOnFaulted, TaskScheduler.Default);

            // Handle async cancellation requests by declining on the target
            Common.WireCancellationToComplete(
                dataflowBlockOptions.CancellationToken, Completion, state => ((TargetCore <TInput>)state).Complete(exception: null, dropPendingMessages: true), _target);
#if FEATURE_TRACING
            DataflowEtwProvider etwLog = DataflowEtwProvider.Log;
            if (etwLog.IsEnabled())
            {
                etwLog.DataflowBlockCreated(this, dataflowBlockOptions);
            }
#endif
        }
Esempio n. 22
0
        private void Initialize(
            Action <KeyValuePair <TInput, long> > processMessageAction,
            ExecutionDataflowBlockOptions dataflowBlockOptions,
            [NotNull] ref SourceCore <TOutput>?source,
            [NotNull] ref TargetCore <TInput>?target,
            ref ReorderingBuffer <IEnumerable <TOutput> >?reorderingBuffer,
            TargetCoreOptions targetCoreOptions)
        {
            if (dataflowBlockOptions == null)
            {
                throw new ArgumentNullException(nameof(dataflowBlockOptions));
            }

            // Ensure we have options that can't be changed by the caller
            dataflowBlockOptions = dataflowBlockOptions.DefaultOrClone();

            // Initialize onItemsRemoved delegate if necessary
            Action <ISourceBlock <TOutput>, int>?onItemsRemoved = null;

            if (dataflowBlockOptions.BoundedCapacity > 0)
            {
                onItemsRemoved = (owningSource, count) => ((TransformManyBlock <TInput, TOutput>)owningSource)._target.ChangeBoundingCount(-count);
            }

            // Initialize source component
            source = new SourceCore <TOutput>(this, dataflowBlockOptions,
                                              owningSource => ((TransformManyBlock <TInput, TOutput>)owningSource)._target.Complete(exception: null, dropPendingMessages: true),
                                              onItemsRemoved);

            // If parallelism is employed, we will need to support reordering messages that complete out-of-order.
            // However, a developer can override this with EnsureOrdered == false.
            if (dataflowBlockOptions.SupportsParallelExecution && dataflowBlockOptions.EnsureOrdered)
            {
                reorderingBuffer = new ReorderingBuffer <IEnumerable <TOutput> >(
                    this, (source, messages) => ((TransformManyBlock <TInput, TOutput>)source)._source.AddMessages(messages));
            }

            // Create the underlying target and source
            target = new TargetCore <TInput>(this, processMessageAction, _reorderingBuffer, dataflowBlockOptions, targetCoreOptions);

            // Link up the target half with the source half.  In doing so,
            // ensure exceptions are propagated, and let the source know no more messages will arrive.
            // As the target has completed, and as the target synchronously pushes work
            // through the reordering buffer when async processing completes,
            // we know for certain that no more messages will need to be sent to the source.
            target.Completion.ContinueWith((completed, state) =>
            {
                var sourceCore = (SourceCore <TOutput>)state !;
                if (completed.IsFaulted)
                {
                    sourceCore.AddAndUnwrapAggregateException(completed.Exception !);
                }
                sourceCore.Complete();
            }, source, CancellationToken.None, Common.GetContinuationOptions(), TaskScheduler.Default);

            // It is possible that the source half may fault on its own, e.g. due to a task scheduler exception.
            // In those cases we need to fault the target half to drop its buffered messages and to release its
            // reservations. This should not create an infinite loop, because all our implementations are designed
            // to handle multiple completion requests and to carry over only one.
            source.Completion.ContinueWith((completed, state) =>
            {
                var thisBlock = ((TransformManyBlock <TInput, TOutput>)state !) as IDataflowBlock;
                Debug.Assert(completed.IsFaulted, "The source must be faulted in order to trigger a target completion.");
                thisBlock.Fault(completed.Exception !);
            }, this, CancellationToken.None, Common.GetContinuationOptions() | TaskContinuationOptions.OnlyOnFaulted, TaskScheduler.Default);

            // Handle async cancellation requests by declining on the target
            Common.WireCancellationToComplete(
                dataflowBlockOptions.CancellationToken, Completion, state => ((TargetCore <TInput>)state !).Complete(exception: null, dropPendingMessages: true), target);
            DataflowEtwProvider etwLog = DataflowEtwProvider.Log;

            if (etwLog.IsEnabled())
            {
                etwLog.DataflowBlockCreated(this, dataflowBlockOptions);
            }
        }