Table of Contents

Class BulkheadPolicy

Namespace
Excalibur.Dispatch.Resilience.Polly
Assembly
Excalibur.Dispatch.Resilience.Polly.dll

Bulkhead policy implementation using Polly.

public class BulkheadPolicy : IBulkheadPolicy, IDisposable, IAsyncDisposable
Inheritance
BulkheadPolicy
Implements
Inherited Members
Extension Methods

Constructors

BulkheadPolicy(string, BulkheadOptions, ILogger?)

Initializes a new instance of the BulkheadPolicy class.

public BulkheadPolicy(string name, BulkheadOptions options, ILogger? logger = null)

Parameters

name string

The bulkhead identifier.

options BulkheadOptions

The bulkhead configuration options.

logger ILogger

The logger used for diagnostic output.

Properties

HasCapacity

Gets a value indicating whether the bulkhead has available capacity.

public bool HasCapacity { get; }

Property Value

bool

true when capacity remains; otherwise, false.

Methods

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

Dispose(bool)

Releases managed resources.

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

Indicates whether the method is called from Dispose().

DisposeAsync()

Asynchronously releases resources used by the bulkhead policy.

public ValueTask DisposeAsync()

Returns

ValueTask

ExecuteAsync<T>(Func<CancellationToken, Task<T>>, CancellationToken)

Executes an operation that observes both caller cancellation and its execution timeout.

public Task<T> ExecuteAsync<T>(Func<CancellationToken, Task<T>> operation, CancellationToken cancellationToken)

Parameters

operation Func<CancellationToken, Task<T>>

The operation, which must observe the supplied strategy token.

cancellationToken CancellationToken

The caller cancellation token.

Returns

Task<T>

The operation result.

Type Parameters

T

The result type.

Remarks

Existing implementations retain the original overload and may implement this capability explicitly.

Exceptions

NotSupportedException

The implementation does not support token-aware execution.

ExecuteAsync<T>(Func<Task<T>>, CancellationToken)

Executes an operation with bulkhead isolation.

public Task<T> ExecuteAsync<T>(Func<Task<T>> operation, CancellationToken cancellationToken)

Parameters

operation Func<Task<T>>

The delegate to execute within the bulkhead constraints.

cancellationToken CancellationToken

A token used to observe cancellation requests.

Returns

Task<T>

A task that completes with the asynchronous result produced by the operation.

Type Parameters

T

The type returned by the asynchronous operation.

Remarks

This overload cannot supply the execution timeout token to the operation. Use the token-aware overload for cooperative cancellation; a timeout waits for the operation to finish cancelling.

GetMetrics()

Gets the current bulkhead metrics.

public BulkheadMetrics GetMetrics()

Returns

BulkheadMetrics

The current BulkheadMetrics snapshot.