Path: redb-route/redb.Route/Configuration/ThreadPoolProfile.cs
Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route
Page: https://redbase.app/src/dev-2026-12-06/redb-route/redb.Route/Configuration/ThreadPoolProfile.cs
----
namespace redb.Route.Configuration;
///
/// The bounds of the pool a detached step runs on (a WireTap, an asynchronous OnCompletion), Apache
/// Camel's thread pool profile. Every such step gets a pool of its own built from a profile: the context's default
/// profile, or a named one the step picks with executorService.
///
/// At most branches of one step run at a time and at most wait;
/// a branch that finds both full is handled by . Branches are tasks, not threads: the
/// limit bounds how much work a step has in flight, not how many threads it holds.
///
///
public sealed class ThreadPoolProfile
{
/// Branches of one step that run at a time (Camel maxPoolSize). Default: 20.
public int MaxConcurrency { get; set; } = 20;
/// Branches of one step that wait for a free slot (Camel maxQueueSize). Default: 1000.
public int MaxQueueSize { get; set; } = 1000;
///
/// What a branch that finds the pool and its queue full does (Camel rejectedPolicy). Default:
/// , so nothing is lost and the source slows down.
///
public ThreadPoolRejectedPolicy RejectedPolicy { get; set; } = ThreadPoolRejectedPolicy.CallerRuns;
/// Checks the bounds; names the profile in the message.
internal void Validate(string name)
{
if (MaxConcurrency < 1)
throw new ArgumentOutOfRangeException(nameof(MaxConcurrency), MaxConcurrency,
$"Thread pool profile '{name}': MaxConcurrency must be at least 1.");
if (MaxQueueSize < 0)
throw new ArgumentOutOfRangeException(nameof(MaxQueueSize), MaxQueueSize,
$"Thread pool profile '{name}': MaxQueueSize must not be negative.");
if (!Enum.IsDefined(RejectedPolicy))
throw new ArgumentOutOfRangeException(nameof(RejectedPolicy), RejectedPolicy,
$"Thread pool profile '{name}': unknown RejectedPolicy.");
}
/// Whether sets the same bounds.
internal bool SameAs(ThreadPoolProfile other) =>
MaxConcurrency == other.MaxConcurrency
&& MaxQueueSize == other.MaxQueueSize
&& RejectedPolicy == other.RejectedPolicy;
/// A copy, so a profile registered with a context is not changed through the caller's instance.
internal ThreadPoolProfile Copy() => new()
{
MaxConcurrency = MaxConcurrency,
MaxQueueSize = MaxQueueSize,
RejectedPolicy = RejectedPolicy,
};
///
public override string ToString() =>
$"MaxConcurrency={MaxConcurrency}, MaxQueueSize={MaxQueueSize}, RejectedPolicy={RejectedPolicy}";
}
/// What a branch that finds its pool and the pool's queue full does (Camel's rejected policies).
public enum ThreadPoolRejectedPolicy
{
/// The caller runs the branch itself before it goes on: nothing is lost, the source slows down.
CallerRuns,
/// The branch is dropped, counted and logged; the caller goes on at once.
Discard,
/// The caller's step fails with , which its route can handle.
Abort,
}