protected virtual bool ReceiveElement(T message) { if (IsActive) { if (TotalDemand > 0L) { OnNext(message); } else if (BufferSize == 0) { Log.Debug("Dropping element because there is no downstream demand: [{0}]", message); } else if (!Buffer.IsFull) { Buffer.Enqueue(message); } else { switch (OverflowStrategy) { case OverflowStrategy.DropHead: Log.Debug("Dropping the head element because buffer is full and overflowStrategy is: [DropHead]"); Buffer.DropHead(); Buffer.Enqueue(message); break; case OverflowStrategy.DropTail: Log.Debug("Dropping the tail element because buffer is full and overflowStrategy is: [DropTail]"); Buffer.DropTail(); Buffer.Enqueue(message); break; case OverflowStrategy.DropBuffer: Log.Debug("Dropping all the buffered elements because buffer is full and overflowStrategy is: [DropBuffer]"); Buffer.Clear(); Buffer.Enqueue(message); break; case OverflowStrategy.DropNew: // do not enqueue new element if the buffer is full Log.Debug("Dropping the new element because buffer is full and overflowStrategy is: [DropNew]"); break; case OverflowStrategy.Fail: Log.Error("Failing because buffer is full and overflowStrategy is: [Fail]"); OnErrorThenStop(new BufferOverflowException($"Buffer overflow, max capacity was ({BufferSize})")); break; case OverflowStrategy.Backpressure: // there is a precondition check in Source.actorRefSource factory method Log.Debug("Backpressuring because buffer is full and overflowStrategy is: [Backpressure]"); break; } } return(true); } return(false); }
private void BufferElement(Offer <TOut> offer) { if (!_buffer.IsFull) { EnqueueAndSuccess(offer); } else { switch (_stage._overflowStrategy) { case OverflowStrategy.DropHead: _buffer.DropHead(); EnqueueAndSuccess(offer); break; case OverflowStrategy.DropTail: _buffer.DropTail(); EnqueueAndSuccess(offer); break; case OverflowStrategy.DropBuffer: _buffer.Clear(); EnqueueAndSuccess(offer); break; case OverflowStrategy.DropNew: offer.CompletionSource.SetResult(QueueOfferResult.Dropped.Instance); break; case OverflowStrategy.Fail: var bufferOverflowException = new BufferOverflowException($"Buffer overflow (max capacity was: {_stage._maxBuffer})!"); offer.CompletionSource.SetResult(new QueueOfferResult.Failure(bufferOverflowException)); _completion.SetException(bufferOverflowException); FailStage(bufferOverflowException); break; case OverflowStrategy.Backpressure: if (_pendingOffer != null) { offer.CompletionSource.SetException( new IllegalStateException( "You have to wait for previous offer to be resolved to send another request.")); } else { _pendingOffer = offer; } break; } } }
/// <summary> /// TBD /// </summary> public void DropTail() => _q.DropTail();