Skip to content

Commit 2d2a1d3

Browse files
committed
Add APIs to track content of Stash
1 parent 2fe0143 commit 2d2a1d3

File tree

6 files changed

+52
-3
lines changed

6 files changed

+52
-3
lines changed

src/core/Akka.API.Tests/verify/CoreAPISpec.ApproveCore.DotNet.verified.txt

+8
Original file line numberDiff line numberDiff line change
@@ -1134,6 +1134,10 @@ namespace Akka.Actor
11341134
}
11351135
public interface IStash
11361136
{
1137+
int Count { get; }
1138+
bool IsEmpty { get; }
1139+
bool IsFull { get; }
1140+
bool NonEmpty { get; }
11371141
System.Collections.Generic.IEnumerable<Akka.Actor.Envelope> ClearStash();
11381142
void Prepend(System.Collections.Generic.IEnumerable<Akka.Actor.Envelope> envelopes);
11391143
void Stash();
@@ -1933,6 +1937,10 @@ namespace Akka.Actor.Internal
19331937
public abstract class AbstractStash : Akka.Actor.IStash
19341938
{
19351939
protected AbstractStash(Akka.Actor.IActorContext context) { }
1940+
public int Count { get; }
1941+
public bool IsEmpty { get; }
1942+
public bool IsFull { get; }
1943+
public bool NonEmpty { get; }
19361944
public System.Collections.Generic.IEnumerable<Akka.Actor.Envelope> ClearStash() { }
19371945
public void Prepend(System.Collections.Generic.IEnumerable<Akka.Actor.Envelope> envelopes) { }
19381946
public void Stash() { }

src/core/Akka.API.Tests/verify/CoreAPISpec.ApproveCore.Net.verified.txt

+8
Original file line numberDiff line numberDiff line change
@@ -1132,6 +1132,10 @@ namespace Akka.Actor
11321132
}
11331133
public interface IStash
11341134
{
1135+
int Count { get; }
1136+
bool IsEmpty { get; }
1137+
bool IsFull { get; }
1138+
bool NonEmpty { get; }
11351139
System.Collections.Generic.IEnumerable<Akka.Actor.Envelope> ClearStash();
11361140
void Prepend(System.Collections.Generic.IEnumerable<Akka.Actor.Envelope> envelopes);
11371141
void Stash();
@@ -1931,6 +1935,10 @@ namespace Akka.Actor.Internal
19311935
public abstract class AbstractStash : Akka.Actor.IStash
19321936
{
19331937
protected AbstractStash(Akka.Actor.IActorContext context) { }
1938+
public int Count { get; }
1939+
public bool IsEmpty { get; }
1940+
public bool IsFull { get; }
1941+
public bool NonEmpty { get; }
19341942
public System.Collections.Generic.IEnumerable<Akka.Actor.Envelope> ClearStash() { }
19351943
public void Prepend(System.Collections.Generic.IEnumerable<Akka.Actor.Envelope> envelopes) { }
19361944
public void Stash() { }

src/core/Akka.Persistence/Eventsourced.cs

+5
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,11 @@ public void Prepend(IEnumerable<Envelope> envelopes)
695695
{
696696
_userStash.Prepend(envelopes);
697697
}
698+
699+
public int Count => _userStash.Count;
700+
public bool IsEmpty => _userStash.IsEmpty;
701+
public bool NonEmpty => _userStash.NonEmpty;
702+
public bool IsFull => _userStash.IsFull;
698703
}
699704
}
700705
}

src/core/Akka/Actor/Stash/IStash.cs

+25-2
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,37 @@ public interface IStash
4343
/// Returns all messages and clears the stash.
4444
/// The stash is guaranteed to be empty afterwards.
4545
/// </summary>
46-
/// <returns>TBD</returns>
46+
/// <returns>The previous stashed messages.</returns>
4747
IEnumerable<Envelope> ClearStash();
4848

4949
/// <summary>
50-
/// TBD
50+
/// Prepend a set of envelopes to the front of the stash.
5151
/// </summary>
5252
/// <param name="envelopes">TBD</param>
5353
void Prepend(IEnumerable<Envelope> envelopes);
54+
55+
/// <summary>
56+
/// The number of messages currently inside the stash.
57+
/// </summary>
58+
public int Count { get; }
59+
60+
/// <summary>
61+
/// Returns <c>true</c> when <see cref="Count"/> is zero.
62+
/// </summary>
63+
public bool IsEmpty { get; }
64+
65+
/// <summary>
66+
/// Returns <c>true</c> when <see cref="Count"/> is greater than zero.
67+
/// </summary>
68+
public bool NonEmpty { get; }
69+
70+
/// <summary>
71+
/// When using a bounded stash, this returns <c>true</c> when the stash is full.
72+
/// </summary>
73+
/// <remarks>
74+
/// Always returns <c>false</c> when using an unbounded stash.
75+
/// </remarks>
76+
public bool IsFull { get; }
5477
}
5578
}
5679

src/core/Akka/Actor/Stash/Internal/AbstractStash.cs

+5
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,11 @@ public void Prepend(IEnumerable<Envelope> envelopes)
189189
}
190190
}
191191

192+
public int Count => _theStash.Count;
193+
public bool IsEmpty => Count == 0;
194+
public bool NonEmpty => !IsEmpty;
195+
public bool IsFull => _theStash.Count >= _capacity;
196+
192197
/// <summary>
193198
/// Enqueues <paramref name="msg"/> at the first position in the mailbox. If the message contained in
194199
/// the envelope is a <see cref="Terminated"/> message, it will be ensured that it can be re-received

src/core/Akka/Dispatch/ISemantics.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
namespace Akka.Dispatch
1212
{
1313
/// <summary>
14-
/// TBD
14+
/// Describes the message queue semantics of a mailbox.
1515
/// </summary>
1616
public interface ISemantics
1717
{

0 commit comments

Comments
 (0)