-
Notifications
You must be signed in to change notification settings - Fork 1
README
Complete API documentation for Murphy for Delphi.
Murphy's API is organized into layers:
- Base Layer - Core interfaces and base classes used by all policies
- Policy Implementations - Specific resilience pattern implementations
- Support Services - Helper classes and utilities
-
Base Policy - Core interfaces, base classes, and builders
-
IPolicyinterface -
TPolicybase class -
TPolicyBuilder<T>generic builder
-
-
Retry Policy - Automatic retry with configurable delays
-
IRetryPolicyinterface -
TRetryPolicyimplementation -
TRetryBuilderbuilder -
TRetryContextcontext
-
-
Circuit Breaker Policy - Prevent cascading failures
-
ICircuitBreakerPolicyinterface -
TCircuitBreakerPolicyimplementation -
TCircuitBreakerBuilderbuilder -
TCircuitStateenumeration -
EBrokenCircuitExceptionexception
-
-
Fallback Policy - Provide alternative results
-
IFallbackPolicy<TResult>generic interface -
TFallbackPolicy<TResult>generic implementation -
TFallbackBuilder<TResult>generic builder
-
-
Rate Limit Policy - Control operation rate
-
IRateLimitPolicyinterface -
TRateLimitPolicyimplementation -
TRateLimitBuilderbuilder -
ERateLimitRejectedExceptionexception
-
-
Timeout Policy - Abort operations that take too long
-
ITimeoutPolicyinterface -
TTimeoutPolicyimplementation -
TTimeoutBuilderbuilder -
TTimeoutContextcontext -
ETimeoutRejectedExceptionexception
-
-
Bulkhead Policy - Limit concurrent executions
-
IBulkheadPolicyinterface -
TBulkheadPolicyimplementation -
TBulkheadBuilderbuilder -
EBulkheadRejectedExceptionexception
-
-
Cache Policy - Cache expensive results
-
ICachePolicy<TResult>generic interface -
TCachePolicy<TResult>generic implementation -
TCacheBuilder<TResult>generic builder
-
-
Hedging Policy - Reduce tail latency with parallel attempts
-
IHedgingPolicyinterface -
THedgingPolicyimplementation -
THedgingBuilderbuilder -
THedgingContextcontext
-
-
Policy Wrap - Combine multiple policies into one
-
IPolicyWrapinterface -
TPolicyWrapimplementation -
TPolicyWrapBuilderbuilder
-
All policies follow this pattern:
var
Policy: IPolicyType;
begin
Policy := TPolicyBuilder.Create
.Handle(ExceptionType)
.ConfigMethod1(Value)
.ConfigMethod2(Value)
.Build;
end;Policies provide Execute methods:
// For procedures (no return value)
Policy.Execute(
procedure
begin
// Your code
end);
// For functions (with return value)
var Result := Policy.Execute(
function: TResultType
begin
Result := YourFunction;
end);Configure which exceptions to handle:
Policy := TBuilder.Create
.Handle(EFirstException)
.Handle(ESecondException)
.Build;| Unit | Description | Key Types |
|---|---|---|
Murphy.Base.Policy |
Base interfaces and classes |
IPolicy, TPolicy, TPolicyBuilder<T>
|
Murphy.Policy.Retry |
Retry pattern |
IRetryPolicy, TRetryPolicy, TRetryBuilder
|
Murphy.Policy.CircuitBreaker |
Circuit Breaker pattern |
ICircuitBreakerPolicy, TCircuitBreakerPolicy
|
Murphy.Policy.Fallback |
Fallback pattern |
IFallbackPolicy<T>, TFallbackPolicy<T>
|
Murphy.Policy.RateLimit |
Rate Limit pattern |
IRateLimitPolicy, TRateLimitPolicy
|
Murphy.Policy.Timeout |
Timeout pattern |
ITimeoutPolicy, TTimeoutPolicy
|
Murphy.Policy.Bulkhead |
Bulkhead pattern |
IBulkheadPolicy, TBulkheadPolicy
|
Murphy.Policy.Cache |
Cache pattern |
ICachePolicy<T>, TCachePolicy<T>
|
Murphy.Policy.Hedging |
Hedging pattern |
IHedgingPolicy, THedgingPolicy
|
Murphy.Policy.Wrap |
Policy Wrap (composition) |
IPolicyWrap, TPolicyWrap
|
Murphy.Services.Schedulers |
Time abstraction |
IScheduler, TConcreteScheduler, TTestScheduler
|
Murphy.Globals |
Global configuration | MurphyTestModeEnabled |
IPolicy (base interface)
│
├── IExecutablePolicy (procedure Execute(AProc: TProc))
│ │
│ ├── IRetryPolicy
│ ├── ICircuitBreakerPolicy
│ ├── IRateLimitPolicy
│ ├── ITimeoutPolicy
│ ├── IBulkheadPolicy
│ ├── IHedgingPolicy
│ └── IPolicyWrap
│
├── IFallbackPolicy<TResult> (function Execute(AFunc: TFunc<TResult>): TResult)
└── ICachePolicy<TResult> (function Execute(AFunc: TFunc<TResult>): TResult)
TPolicy (base class)
│
├── TRetryPolicy
├── TCircuitBreakerPolicy
├── TFallbackPolicy<TResult>
├── TRateLimitPolicy
├── TTimeoutPolicy
├── TBulkheadPolicy
├── TCachePolicy<TResult>
├── THedgingPolicy
└── TPolicyWrap
TPolicyBuilder<TPolicy> (generic base builder)
│
├── TRetryBuilder
├── TCircuitBreakerBuilder
├── TFallbackBuilder<TResult>
├── TRateLimitBuilder
├── TTimeoutBuilder
├── TBulkheadBuilder
├── TCacheBuilder<TResult>
└── THedgingBuilder
TPolicyWrapBuilder (standalone builder, no exception filter of its own)
All policies implement this base interface:
type
IPolicy = interface
function IsHandled(AException: Exception): Boolean;
end;Method:
-
IsHandled(AException)- ReturnsTrueif the policy handles this exception type
Policies that execute a parameterless action implement this interface, which extends IPolicy:
type
IExecutablePolicy = interface(IPolicy)
procedure Execute(AProc: TProc);
end;Method:
-
Execute(AProc)- RunsAProcunder the policy's resilience logic
Purpose: Only types implementing IExecutablePolicy can be combined via Policy Wrap. IRetryPolicy, ICircuitBreakerPolicy, IRateLimitPolicy, ITimeoutPolicy, IBulkheadPolicy, IHedgingPolicy, and IPolicyWrap all extend it. IFallbackPolicy<TResult> and ICachePolicy<TResult> do not, since they return a value via TFunc<TResult> instead.
Most policies provide Execute methods with this signature:
// For procedures (IExecutablePolicy)
procedure Execute(AProc: TProc);
// For functions (IFallbackPolicy<TResult>, ICachePolicy<TResult>)
function Execute(AFunc: TFunc<TResult>): TResult;Murphy defines these custom exceptions:
| Exception | Thrown By | Meaning |
|---|---|---|
EBrokenCircuitException |
Circuit Breaker | Circuit is open or isolated |
ERateLimitRejectedException |
Rate Limit | Rate limit exceeded |
ETimeoutRejectedException |
Timeout | Operation exceeded its timeout duration |
EBulkheadRejectedException |
Bulkhead | No execution slots available |
Unit: Murphy.Globals
Type: Boolean
Default: False
Purpose: Enable test mode to disable actual delays (for unit testing)
Usage:
uses Murphy.Globals;
procedure SetupTest;
begin
MurphyTestModeEnabled := True;
end;
procedure TeardownTest;
begin
MurphyTestModeEnabled := False;
end;Click on any of the links below for complete API documentation:
- Base Policy API - Foundation for all policies
- Retry Policy API - Retry pattern implementation
- Circuit Breaker Policy API - Circuit breaker pattern
- Fallback Policy API - Fallback pattern
- Rate Limit Policy API - Rate limiting pattern
- Timeout Policy API - Timeout pattern
- Bulkhead Policy API - Bulkhead pattern
- Cache Policy API - Cache pattern
- Hedging Policy API - Hedging pattern
- Policy Wrap API - Policy composition
- Pattern Guides - Usage guides with examples
- Architecture - Internal design and extension points
- Getting Started - Quick start guide