Class CorrelationManager
- Namespace
- DotCompute.Core.Messaging
- Assembly
- DotCompute.Core.dll
Manages correlation between request and response messages.
public sealed class CorrelationManager : ICorrelationManager, IDisposable
- Inheritance
-
CorrelationManager
- Implements
- Inherited Members
- Extension Methods
Constructors
CorrelationManager(ILogger<CorrelationManager>)
Creates a new correlation manager.
public CorrelationManager(ILogger<CorrelationManager> logger)
Parameters
loggerILogger<CorrelationManager>Logger for diagnostics.
Properties
PendingCorrelationIds
Gets all pending correlation IDs.
public IReadOnlyCollection<Guid> PendingCorrelationIds { get; }
Property Value
PendingRequestCount
Gets the number of pending requests.
public int PendingRequestCount { get; }
Property Value
Methods
CancelRequest(Guid)
Cancels a pending request.
public bool CancelRequest(Guid correlationId)
Parameters
correlationIdGuidThe correlation ID of the request to cancel.
Returns
- bool
True if the request was found and cancelled; otherwise, false.
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
RegisterRequest<TResponse>(IRequestMessage<TResponse>, TimeSpan, CancellationToken)
Registers a request and returns a task that completes when the response arrives.
public CorrelationContext<TResponse> RegisterRequest<TResponse>(IRequestMessage<TResponse> request, TimeSpan timeout, CancellationToken cancellationToken = default) where TResponse : IResponseMessage
Parameters
requestIRequestMessage<TResponse>The request message being sent.
timeoutTimeSpanThe timeout for waiting for the response.
cancellationTokenCancellationTokenCancellation token.
Returns
- CorrelationContext<TResponse>
A correlation context that can be used to wait for the response.
Type Parameters
TResponseThe expected response type.
TryCompleteRequest(IResponseMessage)
Attempts to complete a pending request with the given response.
public bool TryCompleteRequest(IResponseMessage response)
Parameters
responseIResponseMessageThe response message received.
Returns
- bool
True if a matching pending request was found and completed; otherwise, false.
Events
RequestTimedOut
Occurs when a request times out.
public event EventHandler<CorrelationTimeoutEventArgs>? RequestTimedOut