-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add feature flag insights support
- Loading branch information
1 parent
a9b5060
commit d8fd1fb
Showing
39 changed files
with
1,883 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
using System.Threading; | ||
|
||
// From: https://github.com/akkadotnet/akka.net/blob/dev/src/core/Akka/Util/AtomicBoolean.cs | ||
namespace FeatBit.Sdk.Server.Concurrent | ||
{ | ||
/// <summary> | ||
/// Implementation of the java.concurrent.util.AtomicBoolean type. | ||
/// | ||
/// Uses <see cref="Interlocked.MemoryBarrier"/> internally to enforce ordering of writes | ||
/// without any explicit locking. .NET's strong memory on write guarantees might already enforce | ||
/// this ordering, but the addition of the MemoryBarrier guarantees it. | ||
/// </summary> | ||
public class AtomicBoolean | ||
{ | ||
private const int FalseValue = 0; | ||
private const int TrueValue = 1; | ||
|
||
private int _value; | ||
|
||
/// <summary> | ||
/// Sets the initial value of this <see cref="AtomicBoolean"/> to <paramref name="initialValue"/>. | ||
/// </summary> | ||
/// <param name="initialValue">TBD</param> | ||
public AtomicBoolean(bool initialValue = false) | ||
{ | ||
_value = initialValue ? TrueValue : FalseValue; | ||
} | ||
|
||
/// <summary> | ||
/// The current value of this <see cref="AtomicBoolean"/> | ||
/// </summary> | ||
public bool Value | ||
{ | ||
get | ||
{ | ||
Interlocked.MemoryBarrier(); | ||
return _value == TrueValue; | ||
} | ||
set { Interlocked.Exchange(ref _value, value ? TrueValue : FalseValue); } | ||
} | ||
|
||
/// <summary> | ||
/// If <see cref="Value"/> equals <paramref name="expected"/>, then set the Value to | ||
/// <paramref name="newValue"/>. | ||
/// </summary> | ||
/// <param name="expected">TBD</param> | ||
/// <param name="newValue">TBD</param> | ||
/// <returns><c>true</c> if <paramref name="newValue"/> was set</returns> | ||
public bool CompareAndSet(bool expected, bool newValue) | ||
{ | ||
var expectedInt = expected ? TrueValue : FalseValue; | ||
var newInt = newValue ? TrueValue : FalseValue; | ||
return Interlocked.CompareExchange(ref _value, newInt, expectedInt) == expectedInt; | ||
} | ||
|
||
/// <summary> | ||
/// Atomically sets the <see cref="Value"/> to <paramref name="newValue"/> and returns the old <see cref="Value"/>. | ||
/// </summary> | ||
/// <param name="newValue">The new value</param> | ||
/// <returns>The old value</returns> | ||
public bool GetAndSet(bool newValue) | ||
{ | ||
return Interlocked.Exchange(ref _value, newValue ? TrueValue : FalseValue) == TrueValue; | ||
} | ||
|
||
/// <summary> | ||
/// Performs an implicit conversion from <see cref="AtomicBoolean"/> to <see cref="System.Boolean"/>. | ||
/// </summary> | ||
/// <param name="atomicBoolean">The boolean to convert</param> | ||
/// <returns>The result of the conversion.</returns> | ||
public static implicit operator bool(AtomicBoolean atomicBoolean) | ||
{ | ||
return atomicBoolean.Value; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
using FeatBit.Sdk.Server.Events; | ||
using FeatBit.Sdk.Server.Model; | ||
|
||
namespace FeatBit.Sdk.Server.Evaluation | ||
{ | ||
internal interface IEvaluator | ||
{ | ||
EvalResult Evaluate(EvaluationContext context); | ||
(EvalResult evalResult, EvalEvent evalEvent) Evaluate(EvaluationContext context); | ||
|
||
EvalResult Evaluate(FeatureFlag flag, FbUser user); | ||
(EvalResult evalResult, EvalEvent evalEvent) Evaluate(FeatureFlag flag, FbUser user); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace FeatBit.Sdk.Server.Events | ||
{ | ||
internal sealed class DefaultEventBuffer : IEventBuffer | ||
{ | ||
private readonly int _capacity; | ||
private readonly List<IEvent> _events; | ||
|
||
public DefaultEventBuffer(int capacity) | ||
{ | ||
_capacity = capacity; | ||
_events = new List<IEvent>(); | ||
} | ||
|
||
public bool AddEvent(IEvent @event) | ||
{ | ||
if (_events.Count >= _capacity) | ||
{ | ||
return false; | ||
} | ||
|
||
_events.Add(@event); | ||
return true; | ||
} | ||
|
||
public int Count => _events.Count; | ||
|
||
public bool IsEmpty => Count == 0; | ||
|
||
public void Clear() => _events.Clear(); | ||
|
||
public IEvent[] EventsSnapshot => _events.ToArray(); | ||
} | ||
} |
Oops, something went wrong.