Skip to content

Commit

Permalink
Added call get to RemainingCapacity for a Sequencer
Browse files Browse the repository at this point in the history
- mirror java 6319789fd4690ad2e1dc54741f56ed1d600c2a82
  • Loading branch information
damageboy committed Jul 10, 2013
1 parent a94645f commit 9b714c7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Disruptor.Tests/SequencerTests.cs
Expand Up @@ -173,6 +173,18 @@ public void ShouldRejectAvailableCapcityLessThanOne()
_sequencer.TryNext(0);
}

[Test]
public void ShouldCalculateRemainingCapacity()
{
Assert.AreEqual(4L, _sequencer.RemainingCapacity());
_sequencer.Publish(_sequencer.Next());
Assert.AreEqual(3L, _sequencer.RemainingCapacity());
_sequencer.Publish(_sequencer.Next());
Assert.AreEqual(2L, _sequencer.RemainingCapacity());
_sequencer.Publish(_sequencer.Next());
Assert.AreEqual(1L, _sequencer.RemainingCapacity());
}

private void FillBuffer()
{
for (int i = 0; i < BufferSize; i++)
Expand Down
7 changes: 7 additions & 0 deletions Disruptor/Sequencer.cs
Expand Up @@ -198,5 +198,12 @@ private void Publish(long sequence, int batchSize)
_claimStrategy.SerialisePublishing(sequence, _cursor, batchSize);
_waitStrategy.SignalAllWhenBlocking();
}

public long RemainingCapacity()
{
long consumed = Util.GetMinimumSequence(_gatingSequences);
long produced = _cursor.Value;
return BufferSize - (produced - consumed);
}
}
}

0 comments on commit 9b714c7

Please sign in to comment.