Class MessageQueueRegistry
- Namespace
- DotCompute.Core.Messaging
- Assembly
- DotCompute.Core.dll
Centralized registry for managing named message queues across all backends. Provides thread-safe registration, discovery, and lifecycle management.
public sealed class MessageQueueRegistry : IDisposable
- Inheritance
-
MessageQueueRegistry
- Implements
- Inherited Members
- Extension Methods
Remarks
Performance Note: Logging in this class uses direct ILogger calls rather than LoggerMessage.Define since this is infrastructure code not in hot paths. XFIX003 analyzer warnings are suppressed for this file.
This registry acts as a global namespace for message queues, allowing: - Cross-backend queue sharing (CPU ↔ CUDA ↔ OpenCL ↔ Metal) - Queue discovery and enumeration - Centralized lifecycle management - Type-safe queue retrieval
Thread Safety: All operations are thread-safe using ConcurrentDictionary.
Disposal: Disposing the registry disposes all registered queues.
Constructors
MessageQueueRegistry(ILogger<MessageQueueRegistry>?)
Initializes a new instance of the MessageQueueRegistry class.
public MessageQueueRegistry(ILogger<MessageQueueRegistry>? logger = null)
Parameters
loggerILogger<MessageQueueRegistry>Optional logger for diagnostics.
Properties
Count
Gets the total number of registered queues.
public int Count { get; }
Property Value
Methods
Clear(bool)
Clears all registered queues and optionally disposes them.
[SuppressMessage("Performance", "XFIX003:Use LoggerMessage.Define", Justification = "Infrastructure code not in hot path")]
public void Clear(bool disposeQueues = true)
Parameters
disposeQueuesboolIf true, disposes all queues before clearing.
Exceptions
- ObjectDisposedException
Thrown if the registry has been disposed.
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
[SuppressMessage("Performance", "XFIX003:Use LoggerMessage.Define", Justification = "Infrastructure code not in hot path")]
public void Dispose()
GetMetadata(string)
Gets metadata about a registered queue.
public QueueMetadata? GetMetadata(string queueName)
Parameters
queueNamestringQueue name.
Returns
- QueueMetadata
Queue metadata if found; otherwise null.
Exceptions
- ArgumentException
Thrown if
queueNameis null or whitespace.- ObjectDisposedException
Thrown if the registry has been disposed.
ListQueues()
Lists all registered queue names.
public IReadOnlyCollection<string> ListQueues()
Returns
- IReadOnlyCollection<string>
Read-only collection of queue names.
Exceptions
- ObjectDisposedException
Thrown if the registry has been disposed.
ListQueuesByBackend(string)
Lists all queues registered for a specific backend.
public IReadOnlyCollection<string> ListQueuesByBackend(string backend)
Parameters
backendstringBackend identifier to filter by.
Returns
- IReadOnlyCollection<string>
Read-only collection of queue names for the specified backend.
Exceptions
- ArgumentException
Thrown if
backendis null or whitespace.- ObjectDisposedException
Thrown if the registry has been disposed.
TryGet<T>(string)
Retrieves a message queue by name with type safety.
[SuppressMessage("Performance", "XFIX003:Use LoggerMessage.Define", Justification = "Infrastructure code not in hot path")]
public IMessageQueue<T>? TryGet<T>(string queueName) where T : IRingKernelMessage
Parameters
queueNamestringQueue name to retrieve.
Returns
- IMessageQueue<T>
The queue if found and types match; otherwise null.
Type Parameters
TExpected message type.
Exceptions
- ArgumentException
Thrown if
queueNameis null or whitespace.- ObjectDisposedException
Thrown if the registry has been disposed.
TryRegister(Type, string, object, string?)
Registers a message queue with the specified name using reflection.
[SuppressMessage("Performance", "XFIX003:Use LoggerMessage.Define", Justification = "Infrastructure code not in hot path")]
public bool TryRegister(Type messageType, string queueName, object queue, string? backend = null)
Parameters
messageTypeTypeMessage type (must implement IRingKernelMessage).
queueNamestringUnique queue name.
queueobjectQueue instance to register (must be IMessageQueue<T> where T is messageType).
backendstringOptional backend identifier (e.g., "CPU", "CUDA").
Returns
- bool
True if registration succeeded; false if a queue with the same name already exists.
Exceptions
- ArgumentException
Thrown if parameters are invalid.
- ObjectDisposedException
Thrown if the registry has been disposed.
TryRegister<T>(string, IMessageQueue<T>, string?)
Registers a message queue with the specified name.
[SuppressMessage("Performance", "XFIX003:Use LoggerMessage.Define", Justification = "Infrastructure code not in hot path")]
public bool TryRegister<T>(string queueName, IMessageQueue<T> queue, string? backend = null) where T : IRingKernelMessage
Parameters
queueNamestringUnique queue name.
queueIMessageQueue<T>Queue instance to register.
backendstringOptional backend identifier (e.g., "CPU", "CUDA").
Returns
- bool
True if registration succeeded; false if a queue with the same name already exists.
Type Parameters
TMessage type implementing IRingKernelMessage.
Exceptions
- ArgumentException
Thrown if
queueNameis null or whitespace.- ArgumentNullException
Thrown if
queueis null.- ObjectDisposedException
Thrown if the registry has been disposed.
TryUnregister(string, bool)
Unregisters a message queue and optionally disposes it.
[SuppressMessage("Performance", "XFIX003:Use LoggerMessage.Define", Justification = "Infrastructure code not in hot path")]
public bool TryUnregister(string queueName, bool disposeQueue = true)
Parameters
queueNamestringQueue name to unregister.
disposeQueueboolIf true, disposes the queue after unregistering.
Returns
- bool
True if the queue was found and unregistered; false otherwise.
Exceptions
- ArgumentException
Thrown if
queueNameis null or whitespace.- ObjectDisposedException
Thrown if the registry has been disposed.