-
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.
Merge pull request #55 from engineering87/develop
Decouple API and SignalR with an In-Memory Queue
- Loading branch information
Showing
11 changed files
with
278 additions
and
43 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
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
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 @@ | ||
// (c) 2024 Francesco Del Re <[email protected]> | ||
// This code is licensed under MIT license (see LICENSE.txt for details) | ||
using Microsoft.AspNetCore.Mvc.Filters; | ||
using System.Collections.Generic; | ||
|
||
namespace WART_Core.Entity | ||
{ | ||
/// <summary> | ||
/// Represents an event that contains additional filter metadata. | ||
/// </summary> | ||
public class WartEventWithFilters | ||
{ | ||
/// <summary> | ||
/// The main WartEvent object. | ||
/// </summary> | ||
public WartEvent WartEvent { get; set; } | ||
|
||
/// <summary> | ||
/// A list of filters applied to the event. | ||
/// </summary> | ||
public List<IFilterMetadata> Filters { get; set; } | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the WartEventWithFilters class. | ||
/// </summary> | ||
/// <param name="wartEvent">The WartEvent to associate with the filters.</param> | ||
/// <param name="filters">The list of filters applied to the event.</param> | ||
public WartEventWithFilters(WartEvent wartEvent, List<IFilterMetadata> filters) | ||
{ | ||
// Initialize the WartEvent and Filters properties | ||
WartEvent = wartEvent; | ||
Filters = filters; | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// (c) 2024 Francesco Del Re <[email protected]> | ||
// This code is licensed under MIT license (see LICENSE.txt for details) | ||
using System.Collections.Concurrent; | ||
using WART_Core.Entity; | ||
|
||
namespace WART_Core.Services | ||
{ | ||
/// <summary> | ||
/// A service that manages a concurrent queue for WartEvent objects with filters. | ||
/// This class provides methods for enqueuing and dequeuing events. | ||
/// </summary> | ||
public class WartEventQueueService | ||
{ | ||
// A thread-safe queue to hold WartEvent objects along with their associated filters. | ||
private readonly ConcurrentQueue<WartEventWithFilters> _queue = new ConcurrentQueue<WartEventWithFilters>(); | ||
|
||
/// <summary> | ||
/// Enqueues a WartEventWithFilters object to the queue. | ||
/// </summary> | ||
/// <param name="wartEventWithFilters">The WartEventWithFilters object to enqueue.</param> | ||
public void Enqueue(WartEventWithFilters wartEventWithFilters) | ||
{ | ||
// Adds the event with filters to the concurrent queue. | ||
_queue.Enqueue(wartEventWithFilters); | ||
} | ||
|
||
/// <summary> | ||
/// Attempts to dequeue a WartEventWithFilters object from the queue. | ||
/// </summary> | ||
/// <param name="wartEventWithFilters">The dequeued WartEventWithFilters object.</param> | ||
/// <returns>True if an event was dequeued; otherwise, false.</returns> | ||
public bool TryDequeue(out WartEventWithFilters wartEventWithFilters) | ||
{ | ||
// Attempts to remove and return the event with filters from the queue. | ||
return _queue.TryDequeue(out wartEventWithFilters); | ||
} | ||
|
||
/// <summary> | ||
/// Gets the current count of events in the queue. | ||
/// </summary> | ||
public int Count => _queue.Count; | ||
} | ||
} |
Oops, something went wrong.