Class TransientFaultEvidence
- Namespace
- Cuemon.Resilience
- Assembly
- Cuemon.Core.dll
Provides evidence about a faulted operation.
public class TransientFaultEvidence : IEquatable<TransientFaultEvidence>
- Inheritance
-
TransientFaultEvidence
- Implements
Examples
TransientFaultEvidence captures retry attempt details, recovery wait times, latency, and method signature information for transient fault handling scenarios. This example creates evidence with attempts = 3, RecoveryWaitTime = 2s, TotalRecoveryWaitTime = 5s, Latency = 1500ms, and a MethodSignature for PaymentService.ProcessPayment. It also demonstrates equality comparison between two identical evidence instances, and a minimal-info creation with attempts = 1 and Latency = 200ms for simple scenarios. Console output displays the evidence's ToString representation, individual property values, equality results, and hash code consistency.
using System;
using Cuemon.Reflection;
using Cuemon.Resilience;
namespace MyApp.Resilience
{
public class TransientFaultEvidenceExamples
{
public static void CreateWithMethodSignature()
{
var descriptor = new MethodSignature(
"MyApp.Services.PaymentService",
"ProcessPayment",
new[] { "orderId", "amount" },
new object[] { "ORD-12345", 99.99m }
);
var evidence = new TransientFaultEvidence(
attempts: 3,
recoveryWaitTime: TimeSpan.FromSeconds(2),
totalRecoveryWaitTime: TimeSpan.FromSeconds(5),
latency: TimeSpan.FromMilliseconds(1500),
descriptor: descriptor
);
Console.WriteLine(evidence.ToString());
Console.WriteLine("Attempts: {0}", evidence.Attempts);
Console.WriteLine("Last recovery wait: {0}", evidence.RecoveryWaitTime);
Console.WriteLine("Total recovery wait: {0}", evidence.TotalRecoveryWaitTime);
Console.WriteLine("Latency: {0}", evidence.Latency);
Console.WriteLine("Descriptor: {0}", evidence.Descriptor);
}
public static void EqualityComparison()
{
var desc = new MethodSignature("App.MyClass", "DoWork", new[] { "id" }, new object[] { 42 });
var evidence1 = new TransientFaultEvidence(2, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(2), TimeSpan.FromMilliseconds(500), desc);
var evidence2 = new TransientFaultEvidence(2, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(2), TimeSpan.FromMilliseconds(500), desc);
Console.WriteLine("Equals: {0}", evidence1.Equals(evidence2));
Console.WriteLine("HashCode same: {0}", evidence1.GetHashCode() == evidence2.GetHashCode());
}
public static void CreateWithMinimalInfo()
{
var descriptor = new MethodSignature("App.Service", "Execute", Array.Empty<string>(), Array.Empty<object>());
var evidence = new TransientFaultEvidence(
attempts: 1,
recoveryWaitTime: TimeSpan.Zero,
totalRecoveryWaitTime: TimeSpan.Zero,
latency: TimeSpan.FromMilliseconds(200),
descriptor: descriptor
);
Console.WriteLine("Attempts: {0}", evidence.Attempts);
}
}
}
Constructors
TransientFaultEvidence(int, TimeSpan, TimeSpan, TimeSpan, MethodDescriptor)
Initializes a new instance of the TransientFaultEvidence class.
public TransientFaultEvidence(int attempts, TimeSpan recoveryWaitTime, TimeSpan totalRecoveryWaitTime, TimeSpan latency, MethodDescriptor descriptor)
Parameters
attemptsintThe number of attempts the
descriptorwas invoked.recoveryWaitTimeTimeSpanThe last wait time attempting recovery of
descriptor.totalRecoveryWaitTimeTimeSpanThe total wait time attempting recovery of
descriptor.latencyTimeSpanThe latency experienced with
descriptor.descriptorMethodDescriptorThe information about the method being protected from a transient fault.
TransientFaultEvidence(int, TimeSpan, TimeSpan, TimeSpan, MethodSignature)
Initializes a new instance of the TransientFaultEvidence class.
public TransientFaultEvidence(int attempts, TimeSpan recoveryWaitTime, TimeSpan totalRecoveryWaitTime, TimeSpan latency, MethodSignature descriptor)
Parameters
attemptsintThe number of attempts the
descriptorwas invoked.recoveryWaitTimeTimeSpanThe last wait time attempting recovery of
descriptor.totalRecoveryWaitTimeTimeSpanThe total wait time attempting recovery of
descriptor.latencyTimeSpanThe latency experienced with
descriptor.descriptorMethodSignatureThe information about the method being protected from a transient fault.
Properties
Attempts
Gets the number of attempts the Descriptor was invoked.
public int Attempts { get; }
Property Value
- int
The number of attempts the Descriptor was invoked.
Descriptor
Gets the information about the method being protected from a transient fault.
public MethodSignature Descriptor { get; }
Property Value
- MethodSignature
The information about the method being protected from a transient fault.
Latency
Gets the latency experienced with Descriptor.
public TimeSpan Latency { get; }
Property Value
- TimeSpan
The latency experienced with Descriptor.
RecoveryWaitTime
Gets the last wait time attempting recovery of Descriptor.
public TimeSpan RecoveryWaitTime { get; }
Property Value
- TimeSpan
The last wait time attempting recovery of Descriptor.
TotalRecoveryWaitTime
Gets the total wait time attempting recovery of Descriptor.
public TimeSpan TotalRecoveryWaitTime { get; }
Property Value
- TimeSpan
The total wait time attempting recovery of Descriptor.
Methods
Equals(TransientFaultEvidence)
Indicates whether the current object is equal to another object of the same type.
public virtual bool Equals(TransientFaultEvidence other)
Parameters
otherTransientFaultEvidenceAn object to compare with this object.
Returns
- bool
true if the current object is equal to the
otherparameter; otherwise, false.
Equals(object)
Determines whether the specified Object is equal to this instance.
public override bool Equals(object obj)
Parameters
objobjectThe object to compare with the current object.
Returns
GetHashCode()
Returns a hash code for this instance.
public override int GetHashCode()
Returns
- int
A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
ToString()
Returns a string that represents this instance.
public override string ToString()