public void Buffer_must_work_with_strategy_if_bugger_size_of_one(OverflowStrategy strategy) { var publisher = this.CreatePublisherProbe <int>(); var subscriber = this.CreateManualSubscriberProbe <int>(); Source.FromPublisher(publisher) .Buffer(1, strategy) .To(Sink.FromSubscriber(subscriber)) .Run(Materializer); var sub = subscriber.ExpectSubscription(); // Fill up buffer Enumerable.Range(1, 200).ForEach(i => publisher.SendNext(i)); // The request below is in race otherwise with the onNext(200) above subscriber.ExpectNoMsg(TimeSpan.FromMilliseconds(500)); sub.Request(1); subscriber.ExpectNext(200); publisher.SendNext(-1); sub.Request(1); subscriber.ExpectNext(-1); sub.Cancel(); }
public ObservableSourceStage(IObservable <T> observable, int maxBufferCapacity, OverflowStrategy overflowStrategy) { _observable = observable; _maxBufferCapacity = maxBufferCapacity; _overflowStrategy = overflowStrategy; Shape = new SourceShape <T>(Outlet); }
/// <summary> /// TBD /// </summary> /// <param name="bufferSize">TBD</param> /// <param name="overflowStrategy">TBD</param> /// <param name="attributes">TBD</param> /// <param name="shape">TBD</param> public ActorRefSource(int bufferSize, OverflowStrategy overflowStrategy, Attributes attributes, SourceShape <TOut> shape) : base(shape) { _bufferSize = bufferSize; _overflowStrategy = overflowStrategy; Attributes = attributes; Label = $"ActorRefSource({bufferSize}, {overflowStrategy})"; }
/// <summary> /// Splits a reporting period into units-of-time by a specified granularity. /// </summary> /// <param name="reportingPeriod">The reporting period to split.</param> /// <param name="granularity">The granularity to use when splitting.</param> /// <param name="overflowStrategy"> /// OPTIONAL strategy to use when <paramref name="granularity"/> is less granular than /// the <paramref name="reportingPeriod"/> and, when splitting, the resulting units-of-time /// cannot be aligned with the start and end of the reporting period. /// For example, splitting March 2015 - February 2017 by year results in 2015,2016,2017, /// however only 2016 is fully contained within the reporting period. /// The reporting period is missing January 2015 - February 2015 and March 2017 to December 2017. /// DEFAULT is to throw when this happens. /// </param> /// <returns> /// Returns the units-of-time that split the specified reporting period by the specified granularity. /// The units-of-time will always be in the specified granularity, regardless of the granularity /// of the reporting period (e.g. splitting a fiscal month reporting period using yearly granularity /// will return <see cref="FiscalYear"/> objects). /// </returns> /// <exception cref="ArgumentNullException"><paramref name="reportingPeriod"/> is null.</exception> /// <exception cref="ArgumentException"><paramref name="reportingPeriod"/> has an <see cref="UnitOfTimeGranularity.Unbounded"/> component.</exception> /// <exception cref="ArgumentException"><paramref name="granularity"/> is <see cref="UnitOfTimeGranularity.Invalid"/>.</exception> /// <exception cref="ArgumentException"><paramref name="granularity"/> is <see cref="UnitOfTimeGranularity.Unbounded"/>.</exception> /// <exception cref="ArgumentException"><paramref name="overflowStrategy"/> is not <see cref="OverflowStrategy.ThrowOnOverflow"/>.</exception> /// <exception cref="InvalidOperationException">There was some overflow when splitting.</exception> public static IReadOnlyList <UnitOfTime> Split( this ReportingPeriod reportingPeriod, UnitOfTimeGranularity granularity, OverflowStrategy overflowStrategy = OverflowStrategy.ThrowOnOverflow) { if (reportingPeriod == null) { throw new ArgumentNullException(nameof(reportingPeriod)); } if (reportingPeriod.HasComponentWithUnboundedGranularity()) { throw new ArgumentException(Invariant($"{nameof(reportingPeriod)} has an {nameof(UnitOfTimeGranularity.Unbounded)} component.")); } if (granularity == UnitOfTimeGranularity.Invalid) { throw new ArgumentOutOfRangeException(Invariant($"'{nameof(granularity)}' == '{UnitOfTimeGranularity.Invalid}'"), (Exception)null); } if (granularity == UnitOfTimeGranularity.Unbounded) { throw new ArgumentOutOfRangeException(Invariant($"'{nameof(granularity)}' == '{UnitOfTimeGranularity.Unbounded}'"), (Exception)null); } if ((overflowStrategy != OverflowStrategy.ThrowOnOverflow) && (overflowStrategy != OverflowStrategy.DiscardOverflow)) { throw new ArgumentOutOfRangeException(Invariant($"'{nameof(overflowStrategy)}' is not one of {{{OverflowStrategy.ThrowOnOverflow}, {OverflowStrategy.DiscardOverflow}}}."), (Exception)null); } var reportingPeriodGranularity = reportingPeriod.GetUnitOfTimeGranularity(); IReadOnlyList <UnitOfTime> result; if (reportingPeriodGranularity == granularity) { result = reportingPeriod.GetUnitsWithin(); } else if (reportingPeriodGranularity.IsLessGranularThan(granularity)) { result = reportingPeriod.MakeMoreGranular(granularity).GetUnitsWithin(); } else { var lessGranularReportingPeriod = reportingPeriod.MakeLessGranular( granularity, throwOnMisalignment: overflowStrategy == OverflowStrategy.ThrowOnOverflow); result = lessGranularReportingPeriod.GetUnitsWithin(); if (overflowStrategy == OverflowStrategy.DiscardOverflow) { result = result.Where(reportingPeriod.Contains).ToList(); } } return(result); }
/// <summary> /// Creates a new instance of event source class. /// </summary> /// <param name="conversion">Function used to convert given event handler to delegate compatible with underlying .NET event.</param> /// <param name="addHandler">Action which attaches given event handler to the underlying .NET event.</param> /// <param name="removeHandler">Action which detaches given event handler to the underlying .NET event.</param> /// <param name="maxBuffer">Maximum size of the buffer, used in situation when amount of emitted events is higher than current processing capabilities of the downstream.</param> /// <param name="overflowStrategy">Overflow strategy used, when buffer (size specified by <paramref name="maxBuffer"/>) has been overflown.</param> public EventSourceStage(Action <TDelegate> addHandler, Action <TDelegate> removeHandler, Func <Action <TEventArgs>, TDelegate> conversion, int maxBuffer, OverflowStrategy overflowStrategy) { _conversion = conversion ?? throw new ArgumentNullException(nameof(conversion)); _addHandler = addHandler ?? throw new ArgumentNullException(nameof(addHandler)); _removeHandler = removeHandler ?? throw new ArgumentNullException(nameof(removeHandler)); _maxBuffer = maxBuffer; _overflowStrategy = overflowStrategy; Shape = new SourceShape <TEventArgs>(Out); }
public ConnectionSourceSettings(int bufferCapacity, OverflowStrategy overflowStrategy) { if (overflowStrategy == OverflowStrategy.Backpressure) { throw new ArgumentException($"OverflowStrategy.Backpressure cannot be used with current version of SignalR connection source", nameof(overflowStrategy)); } BufferCapacity = bufferCapacity; OverflowStrategy = overflowStrategy; }
public static Props Props(int bufferSize, OverflowStrategy overflowStrategy, ActorMaterializerSettings settings) { if (overflowStrategy == OverflowStrategy.Backpressure) { throw new NotSupportedException("Backpressure overflow strategy not supported"); } var maxFixedBufferSize = settings.MaxFixedBufferSize; return(Actor.Props.Create(() => new ActorRefSourceActor <T>(bufferSize, overflowStrategy, maxFixedBufferSize))); }
/// <summary> /// Splits a reporting period into units-of-time by a specified granularity. /// </summary> /// <param name="reportingPeriod">The reporting period to split.</param> /// <param name="granularity">The granularity to use when splitting.</param> /// <param name="overflowStrategy"> /// The strategy to use when <paramref name="granularity"/> is less granular than /// the <paramref name="reportingPeriod"/> and, when splitting, the resulting units-of-time /// cannot be aligned with the start and end of the reporting period. For example, /// splitting Mar2015-Feb2017 by year results in 2015,2016,2017, however only 2016 is /// fully contained within the reporting period. The reporting period is missing Jan2015-Feb2015 /// and March2017-Dec2017. /// </param> /// <returns> /// Returns the units-of-time that split the specified reporting period by the specified granularity. /// The units-of-time will always be in the specified granularity, regardless of the granularity /// of the reporting period (e.g. splitting a fiscal month reporting period using yearly granularity /// will return <see cref="FiscalYear"/> objects). /// </returns> /// <exception cref="ArgumentNullException"><paramref name="reportingPeriod"/> is null.</exception> /// <exception cref="ArgumentException"><paramref name="reportingPeriod"/> has an <see cref="UnitOfTimeGranularity.Unbounded"/> component.</exception> /// <exception cref="ArgumentException"><paramref name="granularity"/> is <see cref="UnitOfTimeGranularity.Invalid"/>.</exception> /// <exception cref="ArgumentException"><paramref name="granularity"/> is <see cref="UnitOfTimeGranularity.Unbounded"/>.</exception> /// <exception cref="ArgumentException"><paramref name="overflowStrategy"/> is not <see cref="OverflowStrategy.ThrowOnOverflow"/>.</exception> /// <exception cref="InvalidOperationException">There was some overflow when splitting.</exception> public static IList <UnitOfTime> Split( this IReportingPeriod <UnitOfTime> reportingPeriod, UnitOfTimeGranularity granularity, OverflowStrategy overflowStrategy = OverflowStrategy.ThrowOnOverflow) { if (reportingPeriod == null) { throw new ArgumentNullException(nameof(reportingPeriod)); } if (reportingPeriod.HasComponentWithUnboundedGranularity()) { throw new ArgumentException(Invariant($"{nameof(reportingPeriod)} has an {nameof(UnitOfTimeGranularity.Unbounded)} component.")); } if (granularity == UnitOfTimeGranularity.Invalid) { throw new ArgumentException(Invariant($"{nameof(granularity)} is {nameof(UnitOfTimeGranularity.Invalid)}")); } if (granularity == UnitOfTimeGranularity.Unbounded) { throw new ArgumentException(Invariant($"{nameof(granularity)} is {nameof(UnitOfTimeGranularity.Unbounded)}")); } if (overflowStrategy != OverflowStrategy.ThrowOnOverflow) { throw new ArgumentException(Invariant($"{nameof(overflowStrategy)} is not {nameof(OverflowStrategy.ThrowOnOverflow)}")); } var reportingPeriodGranularity = reportingPeriod.GetUnitOfTimeGranularity(); IList <UnitOfTime> result; if (reportingPeriodGranularity == granularity) { result = reportingPeriod.GetUnitsWithin(); } else if (reportingPeriodGranularity.IsLessGranularThan(granularity)) { result = reportingPeriod.MakeMoreGranular(granularity).GetUnitsWithin(); } else { result = reportingPeriod.MakeLessGranular(granularity).GetUnitsWithin(); } return(result); }
private Action <ISignalREvent> SetupOverflowStrategy(OverflowStrategy overflowStrategy) { switch (overflowStrategy) { case OverflowStrategy.DropHead: return(message => { buffer.RemoveFirst(); Enqueue(message); }); case OverflowStrategy.DropTail: return(message => { buffer.RemoveLast(); Enqueue(message); }); case OverflowStrategy.DropNew: return(message => { // do nothing }); case OverflowStrategy.DropBuffer: return(message => { buffer.Clear(); Enqueue(message); }); case OverflowStrategy.Fail: return(message => { FailStage(new BufferOverflowException($"{stage.outlet} buffer has been overflown")); }); case OverflowStrategy.Backpressure: return(message => { throw new NotSupportedException("OverflowStrategy.Backpressure is not supported"); }); default: throw new NotSupportedException($"Unknown option: {overflowStrategy}"); } }
public void SetDefaults() { // Load parameters from the global defaults where unset or invalid. Needs to be done outside constructor since // constructor might not run if initialized with an object initializer. if (MaxFrames <= 0) { MaxFrames = Megacool.Instance.MaxFrames; } if (PeakLocation <= 0d || PeakLocation > 1d) { //if set <0d, this ignores valid numbers passed in through the panel because the default null value is 0.0 //a valid zero value can be set from the config panel and using RecordingConfig by using initializer to //create the config PeakLocation = (double)Megacool.Instance.PeakLocation; } if (FrameRate <= 0) { FrameRate = (int)Megacool.Instance.FrameRate; } if (PlaybackFrameRate <= 0) { PlaybackFrameRate = (int)Megacool.Instance.PlaybackFrameRate; } if (LastFrameDelay <= 0) { LastFrameDelay = Megacool.Instance.LastFrameDelay; } if (!OverflowStrategy.Equals(MegacoolOverflowStrategy.LATEST) && !OverflowStrategy.Equals(MegacoolOverflowStrategy.HIGHLIGHT) && !OverflowStrategy.Equals(MegacoolOverflowStrategy.TIMELAPSE)) { OverflowStrategy = MegacoolOverflowStrategy.LATEST; } }
/// <summary> /// TBD /// </summary> /// <param name="maxBuffer">TBD</param> /// <param name="overflowStrategy">TBD</param> public QueueSource(int maxBuffer, OverflowStrategy overflowStrategy) { _maxBuffer = maxBuffer; _overflowStrategy = overflowStrategy; Shape = new SourceShape <TOut>(Out); }
public ActorRefSourceActor(int bufferSize, OverflowStrategy overflowStrategy, int maxFixedBufferSize) { BufferSize = bufferSize; OverflowStrategy = overflowStrategy; Buffer = bufferSize != 0 ? Implementation.Buffer.Create <T>(bufferSize, maxFixedBufferSize) : null; }
public ConnectionSourceSettings WithOverflowStrategy(OverflowStrategy overflowStrategy) => Copy(overflowStrategy: overflowStrategy);
public void Buffer_must_work_with_strategy_if_bugger_size_of_one(OverflowStrategy strategy) { var publisher = TestPublisher.CreateProbe<int>(this); var subscriber = TestSubscriber.CreateManualProbe<int>(this); Source.FromPublisher(publisher) .Buffer(1, strategy) .To(Sink.FromSubscriber(subscriber)) .Run(Materializer); var sub = subscriber.ExpectSubscription(); // Fill up buffer Enumerable.Range(1, 200).ForEach(i => publisher.SendNext(i)); // The request below is in race otherwise with the onNext(200) above subscriber.ExpectNoMsg(TimeSpan.FromMilliseconds(500)); sub.Request(1); subscriber.ExpectNext(200); publisher.SendNext(-1); sub.Request(1); subscriber.ExpectNext(-1); sub.Cancel(); }
public Buffer(int size, OverflowStrategy overflowStrategy, Attributes attributes = null) : base(attributes ?? DefaultAttributes.Buffer) { _size = size; _overflowStrategy = overflowStrategy; }
public QueueSource(int maxBuffer, OverflowStrategy overflowStrategy) { _maxBuffer = maxBuffer; _overflowStrategy = overflowStrategy; Shape = new SourceShape <TOut>(new Outlet <TOut>("queueSource.out")); }