-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ab6afb7
commit c580258
Showing
41 changed files
with
5,186 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2022 FRACerqueira | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,124 @@ | ||
# **Welcome to RingBufferPlus** | ||
|
||
A generic circular buffer (ring buffer) in C# with Auto-Scaler, Health-Check and Report-Metrics. | ||
RingBufferPlus was developed in c# with the **netstandard2.1, .NET 5 AND .NET6 ** target frameworks. | ||
|
||
## **Official pages** : | ||
|
||
#### **[Visit the RingBufferPlus official page for complete documentation](https://fracerqueira.github.io/RingBufferPlus)** | ||
|
||
## **RingBufferPlus - Sample Minimum Usage** | ||
|
||
```csharp | ||
public class MyClass | ||
{ | ||
private readonly Guid _id; | ||
public MyClassTest() | ||
{ | ||
_id = Guid.NewGuid(); | ||
} | ||
public Guid Id => _id; | ||
} | ||
|
||
var rb = RingBuffer<MyClass> | ||
.CreateRingBuffer(3) | ||
.Factory((ctk) => new MyClass()) | ||
.Build() | ||
.Run(); | ||
|
||
using (var buffer = rb.Accquire()) | ||
{ | ||
Console.WriteLine(buffer.Id); | ||
} | ||
|
||
rb.Dispose(); | ||
|
||
``` | ||
|
||
## **RingBufferPlus - Sample Complex Usage** | ||
|
||
```csharp | ||
public class MyClass : IDisposable | ||
{ | ||
private readonly Guid _id; | ||
private bool _disposedValue; | ||
|
||
public MyClassTest() | ||
{ | ||
_id = Guid.NewGuid(); | ||
} | ||
public bool IsValidState => true; | ||
public Guid Id => _id; | ||
protected virtual void Dispose(bool disposing) | ||
{ | ||
if (!_disposedValue) | ||
{ | ||
if (disposing) | ||
{ | ||
_disposedValue = true; | ||
} | ||
} | ||
} | ||
public void Dispose() | ||
{ | ||
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method | ||
Dispose(disposing: true); | ||
GC.SuppressFinalize(this); | ||
} | ||
} | ||
|
||
var build_rb = RingBuffer<MyClass> | ||
.CreateRingBuffer(5) | ||
.AliasName("Test") | ||
.MinScaler(2) | ||
.MaxScaler(10) | ||
.PolicyTimeoutAccquire(RingBufferPolicyTimeout.UserPolicy, (metric,ctk) => true) | ||
.DefaultTimeoutAccquire(10) | ||
.DefaultIntervalAutoScaler(500) | ||
.DefaultIntervalHealthCheck(1000) | ||
.DefaultIntervalReport(1000) | ||
.Factory((ctk) => New MyClass() ) | ||
.HealthCheck((buffer, ctk) => buffer.IsValidState) | ||
.ReportMetrics((metric,ctk) => Console.WriteLine(metric.ErrorCount)) | ||
.AutoScaler((RingBufferMetric, CancellationToken) => | ||
{ | ||
return 5; | ||
}) | ||
.Build(); | ||
|
||
build_rb.AutoScaleCallback += Ring_AutoScaleCallback; | ||
build_rb.ErrorCallBack += Ring_ErrorCallBack; | ||
build_rb.TimeoutCallBack += Ring_TimeoutCallBack; | ||
|
||
var rb = build_rb.Run(cancellationToken); | ||
|
||
using (var buffer = rb.Accquire()) | ||
{ | ||
Console.WriteLine(buffer.Id); | ||
} | ||
|
||
rb.Dispose(); | ||
|
||
private void Ring_ErrorCallBack(object sender, RingBufferErrorEventArgs e) | ||
{ | ||
Console.WriteLine($"{e.Alias} => Error: {e.Error?.Message ?? "Null"}."); | ||
} | ||
|
||
private void Ring_TimeoutCallBack(object sender, RingBufferTimeoutEventArgs e) | ||
{ | ||
Console.WriteLine($"{e.Alias}/{e.Source} => TimeOut = {e.ElapsedTime}/{e.Timeout} Erros={e.Metric.ErrorCount} Overload = {e.Metric.OverloadCount}. Cap./Run./Aval. = {e.Metric.Capacity}/{e.Metric.Running}/{e.Metric.Avaliable}"); | ||
} | ||
|
||
private void Ring_AutoScaleCallback(object sender, RingBufferAutoScaleEventArgs e) | ||
{ | ||
Console.WriteLine($"{e.Alias} => {e.OldCapacity} to {e.NewCapacity}.Error/Timeout = {e.Metric.ErrorCount}/{e.Metric.TimeoutCount} Over = {e.Metric.OverloadCount} Cap./Run./Aval. = {e.Metric.Capacity}/{e.Metric.Running}/{e.Metric.Avaliable}"); | ||
} | ||
|
||
``` | ||
|
||
|
||
|
||
## **License** | ||
|
||
This project is licensed under the [MIT License](https://github.com/FRACerqueira/RingBufferPlus/blob/master/LICENSE) | ||
|
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 +1,122 @@ | ||
# RingBufferPlus | ||
# **Welcome to RingBufferPlus** | ||
|
||
A generic circular buffer (ring buffer) in C# with Auto-Scaler, Health-Check and Report-Metrics. | ||
RingBufferPlus was developed in c# with the **netstandard2.1, .NET 5 AND .NET6 ** target frameworks. | ||
|
||
## **Official pages** : | ||
|
||
#### **[Visit the RingBufferPlus official page for complete documentation](https://fracerqueira.github.io/RingBufferPlus)** | ||
|
||
## **RingBufferPlus - Sample Minimum Usage** | ||
|
||
```csharp | ||
public class MyClass | ||
{ | ||
private readonly Guid _id; | ||
public MyClassTest() | ||
{ | ||
_id = Guid.NewGuid(); | ||
} | ||
public Guid Id => _id; | ||
} | ||
|
||
var rb = RingBuffer<MyClass> | ||
.CreateRingBuffer(3) | ||
.Factory((ctk) => new MyClass()) | ||
.Build() | ||
.Run(); | ||
|
||
using (var buffer = rb.Accquire()) | ||
{ | ||
Console.WriteLine(buffer.Id); | ||
} | ||
|
||
rb.Dispose(); | ||
|
||
``` | ||
|
||
## **RingBufferPlus - Sample Complex Usage** | ||
|
||
```csharp | ||
public class MyClass : IDisposable | ||
{ | ||
private readonly Guid _id; | ||
private bool _disposedValue; | ||
|
||
public MyClassTest() | ||
{ | ||
_id = Guid.NewGuid(); | ||
} | ||
public bool IsValidState => true; | ||
public Guid Id => _id; | ||
protected virtual void Dispose(bool disposing) | ||
{ | ||
if (!_disposedValue) | ||
{ | ||
if (disposing) | ||
{ | ||
_disposedValue = true; | ||
} | ||
} | ||
} | ||
public void Dispose() | ||
{ | ||
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method | ||
Dispose(disposing: true); | ||
GC.SuppressFinalize(this); | ||
} | ||
} | ||
|
||
var build_rb = RingBuffer<MyClass> | ||
.CreateRingBuffer(5) | ||
.AliasName("Test") | ||
.MinScaler(2) | ||
.MaxScaler(10) | ||
.PolicyTimeoutAccquire(RingBufferPolicyTimeout.UserPolicy, (metric,ctk) => true) | ||
.DefaultTimeoutAccquire(10) | ||
.DefaultIntervalAutoScaler(500) | ||
.DefaultIntervalHealthCheck(1000) | ||
.DefaultIntervalReport(1000) | ||
.Factory((ctk) => New MyClass() ) | ||
.HealthCheck((buffer, ctk) => buffer.IsValidState) | ||
.ReportMetrics((metric,ctk) => Console.WriteLine(metric.ErrorCount)) | ||
.AutoScaler((RingBufferMetric, CancellationToken) => | ||
{ | ||
return 5; | ||
}) | ||
.Build(); | ||
|
||
build_rb.AutoScaleCallback += Ring_AutoScaleCallback; | ||
build_rb.ErrorCallBack += Ring_ErrorCallBack; | ||
build_rb.TimeoutCallBack += Ring_TimeoutCallBack; | ||
|
||
var rb = build_rb.Run(cancellationToken); | ||
|
||
using (var buffer = rb.Accquire()) | ||
{ | ||
Console.WriteLine(buffer.Id); | ||
} | ||
|
||
rb.Dispose(); | ||
|
||
private void Ring_ErrorCallBack(object sender, RingBufferErrorEventArgs e) | ||
{ | ||
Console.WriteLine($"{e.Alias} => Error: {e.Error?.Message ?? "Null"}."); | ||
} | ||
|
||
private void Ring_TimeoutCallBack(object sender, RingBufferTimeoutEventArgs e) | ||
{ | ||
Console.WriteLine($"{e.Alias}/{e.Source} => TimeOut = {e.ElapsedTime}/{e.Timeout} Erros={e.Metric.ErrorCount} Overload = {e.Metric.OverloadCount}. Cap./Run./Aval. = {e.Metric.Capacity}/{e.Metric.Running}/{e.Metric.Avaliable}"); | ||
} | ||
|
||
private void Ring_AutoScaleCallback(object sender, RingBufferAutoScaleEventArgs e) | ||
{ | ||
Console.WriteLine($"{e.Alias} => {e.OldCapacity} to {e.NewCapacity}.Error/Timeout = {e.Metric.ErrorCount}/{e.Metric.TimeoutCount} Over = {e.Metric.OverloadCount} Cap./Run./Aval. = {e.Metric.Capacity}/{e.Metric.Running}/{e.Metric.Avaliable}"); | ||
} | ||
|
||
``` | ||
|
||
## **License** | ||
|
||
This project is licensed under the [MIT License](https://github.com/FRACerqueira/RingBufferPlus/blob/master/LICENSE) | ||
|
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,37 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.0.32014.148 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RingBufferPlus", "RingBufferPlus\RingBufferPlus.csproj", "{C5419815-EE14-4A96-8A5A-88D57A36DDD4}" | ||
EndProject | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RingBufferPlusRabbit", "RingBufferPlusRabbit\RingBufferPlusRabbit.csproj", "{5FA96D7C-BD40-44C3-9B87-4F3CCFE38E30}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RingBufferPlusTest", "RingBufferPlusTest\RingBufferPlusTest.csproj", "{C53D3D66-0233-4F48-BA33-FF41023D91E0}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{C5419815-EE14-4A96-8A5A-88D57A36DDD4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{C5419815-EE14-4A96-8A5A-88D57A36DDD4}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{C5419815-EE14-4A96-8A5A-88D57A36DDD4}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{C5419815-EE14-4A96-8A5A-88D57A36DDD4}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{5FA96D7C-BD40-44C3-9B87-4F3CCFE38E30}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{5FA96D7C-BD40-44C3-9B87-4F3CCFE38E30}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{5FA96D7C-BD40-44C3-9B87-4F3CCFE38E30}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{5FA96D7C-BD40-44C3-9B87-4F3CCFE38E30}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{C53D3D66-0233-4F48-BA33-FF41023D91E0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{C53D3D66-0233-4F48-BA33-FF41023D91E0}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{C53D3D66-0233-4F48-BA33-FF41023D91E0}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{C53D3D66-0233-4F48-BA33-FF41023D91E0}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {4E82EE9E-8ED4-4F9B-820D-03B4C5E3A4A6} | ||
EndGlobalSection | ||
EndGlobal |
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,20 @@ | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
// In SDK-style projects such as this one, several assembly attributes that were historically | ||
// defined in this file are now automatically added during build and populated with | ||
// values defined in project properties. For details of which attributes are included | ||
// and how to customise this process see: https://aka.ms/assembly-info-properties | ||
|
||
|
||
// Setting ComVisible to false makes the types in this assembly not visible to COM | ||
// components. If you need to access a type in this assembly from COM, set the ComVisible | ||
// attribute to true on that type. | ||
|
||
[assembly: ComVisible(false)] | ||
|
||
// The following GUID is for the ID of the typelib if this project is exposed to COM. | ||
|
||
[assembly: Guid("48f1bd0f-694f-4a8b-a14a-522a13a2e423")] | ||
|
||
[assembly: InternalsVisibleTo("RingBufferPlusTest")] |
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,24 @@ | ||
using RingBufferPlus.ObjectValues; | ||
using System; | ||
|
||
namespace RingBufferPlus.Events | ||
{ | ||
public class RingBufferAutoScaleEventArgs : EventArgs | ||
{ | ||
private RingBufferAutoScaleEventArgs() | ||
{ | ||
} | ||
|
||
internal RingBufferAutoScaleEventArgs(string alias, int oldvalue, int newvalue, RingBufferMetric metric) | ||
{ | ||
Alias = alias; | ||
OldCapacity = oldvalue; | ||
NewCapacity = newvalue; | ||
Metric = metric; | ||
} | ||
public string Alias { get; } | ||
public int OldCapacity { get; } | ||
public int NewCapacity { get; } | ||
public RingBufferMetric Metric { get; } | ||
} | ||
} |
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,18 @@ | ||
using System; | ||
|
||
namespace RingBufferPlus.Events | ||
{ | ||
public class RingBufferErrorEventArgs : EventArgs | ||
{ | ||
private RingBufferErrorEventArgs() | ||
{ | ||
} | ||
internal RingBufferErrorEventArgs(string alias, Exception? ex) | ||
{ | ||
Alias = alias; | ||
Error = ex; | ||
} | ||
public string Alias { get; } | ||
public Exception? Error { get; } | ||
} | ||
} |
Oops, something went wrong.