Skip to content

Commit

Permalink
Add interfaces to Polly
Browse files Browse the repository at this point in the history
Adds interfaces to Polly.  Delivers App-vNext#257
  • Loading branch information
reisenberger committed Jun 27, 2017
1 parent ec283ce commit 41a7677
Show file tree
Hide file tree
Showing 42 changed files with 1,328 additions and 48 deletions.
4 changes: 2 additions & 2 deletions src/Polly.Shared/Bulkhead/BulkheadPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Polly.Bulkhead
/// <summary>
/// A bulkhead-isolation policy which can be applied to delegates.
/// </summary>
public partial class BulkheadPolicy : Policy, IDisposable
public partial class BulkheadPolicy : Policy, IBulkheadPolicy
{
private readonly SemaphoreSlim _maxParallelizationSemaphore;
private readonly SemaphoreSlim _maxQueuedActionsSemaphore;
Expand Down Expand Up @@ -58,7 +58,7 @@ public void Dispose()
/// <summary>
/// A bulkhead-isolation policy which can be applied to delegates returning a value of type <typeparamref name="TResult"/>.
/// </summary>
public partial class BulkheadPolicy<TResult> : Policy<TResult>, IDisposable
public partial class BulkheadPolicy<TResult> : Policy<TResult>, IBulkheadPolicy<TResult>
{
private readonly SemaphoreSlim _maxParallelizationSemaphore;
private readonly SemaphoreSlim _maxQueuedActionsSemaphore;
Expand Down
4 changes: 2 additions & 2 deletions src/Polly.Shared/Bulkhead/BulkheadPolicyAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Polly.Bulkhead
{
public partial class BulkheadPolicy
public partial class BulkheadPolicy : IBulkheadPolicy
{
internal BulkheadPolicy(Func<Func<Context, CancellationToken, Task>, Context, CancellationToken, bool, Task> asyncExceptionPolicy,
int maxParallelization,
Expand All @@ -27,7 +27,7 @@ internal BulkheadPolicy(Func<Func<Context, CancellationToken, Task>, Context, Ca
}
}

public partial class BulkheadPolicy<TResult>
public partial class BulkheadPolicy<TResult> : IBulkheadPolicy<TResult>
{
internal BulkheadPolicy(
Func<Func<Context, CancellationToken, Task<TResult>>, Context, CancellationToken, bool, Task<TResult>> asyncExecutionPolicy,
Expand Down
29 changes: 29 additions & 0 deletions src/Polly.Shared/Bulkhead/IBulkheadPolicy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;

namespace Polly.Bulkhead
{
/// <summary>
/// Defines properties and methods common to all bulkhead policies.
/// </summary>

public interface IBulkheadPolicy : IsPolicy, IDisposable
{
/// <summary>
/// Gets the number of slots currently available for executing actions through the bulkhead.
/// </summary>
int BulkheadAvailableCount { get; }

/// <summary>
/// Gets the number of slots currently available for queuing actions for execution through the bulkhead.
/// </summary>
int QueueAvailableCount { get; }
}

/// <summary>
/// Defines properties and methods common to all bulkhead policies generic-typed for executions returning results of type <typeparamref name="TResult"/>.
/// </summary>
public interface IBulkheadPolicy<TResult> : IBulkheadPolicy
{

}
}
4 changes: 2 additions & 2 deletions src/Polly.Shared/CircuitBreaker/CircuitBreakerPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Polly.CircuitBreaker
/// <summary>
/// A circuit-breaker policy that can be applied to delegates.
/// </summary>
public partial class CircuitBreakerPolicy : Policy
public partial class CircuitBreakerPolicy : Policy, ICircuitBreakerPolicy
{
internal readonly ICircuitController<EmptyStruct> _breakerController;

Expand Down Expand Up @@ -58,7 +58,7 @@ public void Reset()
/// <summary>
/// A circuit-breaker policy that can be applied to delegates returning a value of type <typeparamref name="TResult"/>.
/// </summary>
public partial class CircuitBreakerPolicy<TResult> : Policy<TResult>
public partial class CircuitBreakerPolicy<TResult> : Policy<TResult>, ICircuitBreakerPolicy<TResult>
{
internal readonly ICircuitController<TResult> _breakerController;

Expand Down
4 changes: 2 additions & 2 deletions src/Polly.Shared/CircuitBreaker/CircuitBreakerPolicyAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Polly.CircuitBreaker
{
public partial class CircuitBreakerPolicy
public partial class CircuitBreakerPolicy : ICircuitBreakerPolicy
{
internal CircuitBreakerPolicy(
Func<Func<Context, CancellationToken, Task>, Context, CancellationToken, bool, Task> asyncExceptionPolicy,
Expand All @@ -19,7 +19,7 @@ ICircuitController<EmptyStruct> breakerController
}
}

public partial class CircuitBreakerPolicy<TResult>
public partial class CircuitBreakerPolicy<TResult> : ICircuitBreakerPolicy<TResult>
{
internal CircuitBreakerPolicy(
Func<Func<Context, CancellationToken, Task<TResult>>, Context, CancellationToken, bool, Task<TResult>> asyncExecutionPolicy,
Expand Down
43 changes: 43 additions & 0 deletions src/Polly.Shared/CircuitBreaker/ICircuitBreakerPolicy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;

namespace Polly.CircuitBreaker
{
/// <summary>
/// Defines properties and methods common to all circuit-breaker policies.
/// </summary>
public interface ICircuitBreakerPolicy : IsPolicy
{
/// <summary>
/// Gets the state of the underlying circuit.
/// </summary>
CircuitState CircuitState { get; }

/// <summary>
/// Gets the last exception handled by the circuit-breaker.
/// <remarks>This will be null if no exceptions have been handled by the circuit-breaker since the circuit last closed.</remarks>
/// </summary>
Exception LastException { get; }

/// <summary>
/// Isolates (opens) the circuit manually, and holds it in this state until a call to <see cref="CircuitBreakerPolicy.Reset"/> is made.
/// </summary>
void Isolate();

/// <summary>
/// Closes the circuit, and resets any statistics controlling automated circuit-breaking.
/// </summary>
void Reset();
}

/// <summary>
/// Defines properties and methods common to all circuit-breaker policies generic-typed for executions returning results of type <typeparamref name="TResult"/>.
/// </summary>
public interface ICircuitBreakerPolicy<TResult> : ICircuitBreakerPolicy
{
/// <summary>
/// Gets the last result returned from a user delegate which the circuit-breaker handled.
/// <remarks>This will be default(<typeparamref name="TResult"/>) if no results have been handled by the circuit-breaker since the circuit last closed, or if the last event handled by the circuit was an exception.</remarks>
/// </summary>
TResult LastHandledResult { get; }
}
}
4 changes: 2 additions & 2 deletions src/Polly.Shared/Fallback/FallbackPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Polly.Fallback
/// <summary>
/// A fallback policy that can be applied to delegates.
/// </summary>
public partial class FallbackPolicy : Policy
public partial class FallbackPolicy : Policy, IFallbackPolicy
{
internal FallbackPolicy(Action<Action<Context, CancellationToken>, Context, CancellationToken> exceptionPolicy, IEnumerable<ExceptionPredicate> exceptionPredicates)
: base(exceptionPolicy, exceptionPredicates)
Expand All @@ -18,7 +18,7 @@ internal FallbackPolicy(Action<Action<Context, CancellationToken>, Context, Canc
/// <summary>
/// A fallback policy that can be applied to delegates returning a value of type <typeparamref name="TResult"/>.
/// </summary>
public partial class FallbackPolicy<TResult> : Policy<TResult>
public partial class FallbackPolicy<TResult> : Policy<TResult>, IFallbackPolicy<TResult>
{
internal FallbackPolicy(
Func<Func<Context, CancellationToken, TResult>, Context, CancellationToken, TResult> executionPolicy,
Expand Down
4 changes: 2 additions & 2 deletions src/Polly.Shared/Fallback/FallbackPolicyAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@

namespace Polly.Fallback
{
public partial class FallbackPolicy
public partial class FallbackPolicy : IFallbackPolicy
{
internal FallbackPolicy(Func<Func<Context, CancellationToken, Task>, Context, CancellationToken, bool, Task> asyncExceptionPolicy, IEnumerable<ExceptionPredicate> exceptionPredicates)
: base(asyncExceptionPolicy, exceptionPredicates)
{
}
}

public partial class FallbackPolicy<TResult>
public partial class FallbackPolicy<TResult> : IFallbackPolicy<TResult>
{
internal FallbackPolicy(
Func<Func<Context, CancellationToken, Task<TResult>>, Context, CancellationToken, bool, Task<TResult>> asyncExecutionPolicy,
Expand Down
18 changes: 18 additions & 0 deletions src/Polly.Shared/Fallback/IFallbackPolicy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace Polly.Fallback
{
/// <summary>
/// Defines properties and methods common to all Fallback policies.
/// </summary>

public interface IFallbackPolicy : IsPolicy
{
}

/// <summary>
/// Defines properties and methods common to all Fallback policies generic-typed for executions returning results of type <typeparamref name="TResult"/>.
/// </summary>
public interface IFallbackPolicy<TResult> : IFallbackPolicy
{

}
}
Loading

0 comments on commit 41a7677

Please sign in to comment.