Class SpanBasedMessageRouter<TMessage>
High-performance message router that uses Span<T> and avoids allocations. Optimized for scenarios where routing decisions must be made in microseconds.
public sealed class SpanBasedMessageRouter<TMessage> : IDisposable where TMessage : unmanaged, IRoutableMessage
Type Parameters
TMessage
- Inheritance
-
SpanBasedMessageRouter<TMessage>
- Implements
- Inherited Members
- Extension Methods
Constructors
SpanBasedMessageRouter(int, int)
High-performance message router that uses Span<T> and avoids allocations. Optimized for scenarios where routing decisions must be made in microseconds.
public SpanBasedMessageRouter(int maxRoutes, int cacheSize = 1024)
Parameters
Methods
ClearCache()
Clears the internal routing cache to force fresh evaluation of routing decisions.
public void ClearCache()
Dispose()
Disposes the message router, releasing thread-local buffers and other resources.
public void Dispose()
FindAllRoutes(in TMessage, Span<int>)
Find all matching routes for a message (for multicast scenarios).
public int FindAllRoutes(in TMessage message, Span<int> matchingRoutes)
Parameters
Returns
GetStatistics()
Gets comprehensive statistics about the routing performance and state.
public RouteStatistics GetStatistics()
Returns
- RouteStatistics
Statistics including active routes, cache performance, and routing metrics.
RouteBatch(ReadOnlySpan<TMessage>, Span<int>)
Route multiple messages in batch with optimized memory access.
public void RouteBatch(ReadOnlySpan<TMessage> messages, Span<int> routeIds)
Parameters
messagesReadOnlySpan<TMessage>routeIdsSpan<int>
RouteMessage(in TMessage)
Route a single message with minimal overhead.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public int RouteMessage(in TMessage message)
Parameters
messageTMessage
Returns
TryAddRoute(int, Predicate<TMessage>, int)
Add a route to the router.
public bool TryAddRoute(int routeId, Predicate<TMessage> predicate, int priority = 0)