Table of Contents

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

logger ILogger<MessageQueueRegistry>

Optional logger for diagnostics.

Properties

Count

Gets the total number of registered queues.

public int Count { get; }

Property Value

int

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

disposeQueues bool

If 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

queueName string

Queue name.

Returns

QueueMetadata

Queue metadata if found; otherwise null.

Exceptions

ArgumentException

Thrown if queueName is 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

backend string

Backend identifier to filter by.

Returns

IReadOnlyCollection<string>

Read-only collection of queue names for the specified backend.

Exceptions

ArgumentException

Thrown if backend is 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

queueName string

Queue name to retrieve.

Returns

IMessageQueue<T>

The queue if found and types match; otherwise null.

Type Parameters

T

Expected message type.

Exceptions

ArgumentException

Thrown if queueName is 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

messageType Type

Message type (must implement IRingKernelMessage).

queueName string

Unique queue name.

queue object

Queue instance to register (must be IMessageQueue<T> where T is messageType).

backend string

Optional 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

queueName string

Unique queue name.

queue IMessageQueue<T>

Queue instance to register.

backend string

Optional backend identifier (e.g., "CPU", "CUDA").

Returns

bool

True if registration succeeded; false if a queue with the same name already exists.

Type Parameters

T

Message type implementing IRingKernelMessage.

Exceptions

ArgumentException

Thrown if queueName is null or whitespace.

ArgumentNullException

Thrown if queue is 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

queueName string

Queue name to unregister.

disposeQueue bool

If true, disposes the queue after unregistering.

Returns

bool

True if the queue was found and unregistered; false otherwise.

Exceptions

ArgumentException

Thrown if queueName is null or whitespace.

ObjectDisposedException

Thrown if the registry has been disposed.