Skip to content

Commit

Permalink
Refactor AdaptiveLoadBalancingRoutingLogic to use IClusterMetricsRout…
Browse files Browse the repository at this point in the history
…ingLogic instead (#5237)

Co-authored-by: Aaron Stannard <[email protected]>
  • Loading branch information
Arkatufus and Aaronontheweb authored Aug 31, 2021
1 parent 1c183fa commit 8c800cf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,17 @@

namespace Akka.Cluster.Metrics
{
public interface IClusterMetricsRoutingLogic
{
void MetricsChanged(ClusterMetricsChanged @event);
}

/// <summary>
/// Load balancing of messages to cluster nodes based on cluster metric data.
///
/// It uses random selection of routees based on probabilities derived from the remaining capacity of corresponding node.
/// </summary>
public sealed class AdaptiveLoadBalancingRoutingLogic : RoutingLogic
public sealed class AdaptiveLoadBalancingRoutingLogic : RoutingLogic, IClusterMetricsRoutingLogic
{
private readonly ActorSystem _system;
private readonly IMetricsSelector _metricsSelector;
Expand Down Expand Up @@ -176,7 +181,7 @@ public override Router CreateRouter(ActorSystem system)
/// <inheritdoc />
public override Props RoutingLogicController(RoutingLogic routingLogic)
{
return Actor.Props.Create(() => new AdaptiveLoadBalancingMetricsListener(routingLogic as AdaptiveLoadBalancingRoutingLogic));
return Actor.Props.Create(() => new AdaptiveLoadBalancingMetricsListener((IClusterMetricsRoutingLogic)routingLogic));
}

/// <inheritdoc />
Expand Down Expand Up @@ -328,7 +333,7 @@ public override Router CreateRouter(ActorSystem system)
/// <inheritdoc />
public override Props RoutingLogicController(RoutingLogic routingLogic)
{
return Actor.Props.Create(() => new AdaptiveLoadBalancingMetricsListener(routingLogic as AdaptiveLoadBalancingRoutingLogic));
return Actor.Props.Create(() => new AdaptiveLoadBalancingMetricsListener((IClusterMetricsRoutingLogic)routingLogic));
}

/// <inheritdoc />
Expand Down Expand Up @@ -392,10 +397,10 @@ public ISurrogated FromSurrogate(ActorSystem system)
[InternalApi]
public class AdaptiveLoadBalancingMetricsListener : ActorBase
{
private readonly AdaptiveLoadBalancingRoutingLogic _routingLogic;
private readonly IClusterMetricsRoutingLogic _routingLogic;
private readonly ClusterMetrics _extension = ClusterMetrics.Get(Context.System);

public AdaptiveLoadBalancingMetricsListener(AdaptiveLoadBalancingRoutingLogic routingLogic)
public AdaptiveLoadBalancingMetricsListener(IClusterMetricsRoutingLogic routingLogic)
{
_routingLogic = routingLogic;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace Akka.Cluster.Metrics
[Akka.Annotations.InternalApiAttribute()]
public class AdaptiveLoadBalancingMetricsListener : Akka.Actor.ActorBase
{
public AdaptiveLoadBalancingMetricsListener(Akka.Cluster.Metrics.AdaptiveLoadBalancingRoutingLogic routingLogic) { }
public AdaptiveLoadBalancingMetricsListener(Akka.Cluster.Metrics.IClusterMetricsRoutingLogic routingLogic) { }
protected override void PostStop() { }
protected override void PreStart() { }
protected override bool Receive(object message) { }
Expand Down Expand Up @@ -52,7 +52,7 @@ namespace Akka.Cluster.Metrics
public Akka.Util.ISurrogated FromSurrogate(Akka.Actor.ActorSystem system) { }
}
}
public sealed class AdaptiveLoadBalancingRoutingLogic : Akka.Routing.RoutingLogic
public sealed class AdaptiveLoadBalancingRoutingLogic : Akka.Routing.RoutingLogic, Akka.Cluster.Metrics.IClusterMetricsRoutingLogic
{
public AdaptiveLoadBalancingRoutingLogic(Akka.Actor.ActorSystem system, Akka.Cluster.Metrics.IMetricsSelector metricsSelector = null) { }
public void MetricsChanged(Akka.Cluster.Metrics.Events.ClusterMetricsChanged @event) { }
Expand Down Expand Up @@ -120,6 +120,10 @@ namespace Akka.Cluster.Metrics
public CpuMetricsSelector() { }
public override System.Collections.Immutable.IImmutableDictionary<Akka.Actor.Address, double> Capacity(System.Collections.Immutable.IImmutableSet<Akka.Cluster.Metrics.Serialization.NodeMetrics> nodeMetrics) { }
}
public interface IClusterMetricsRoutingLogic
{
void MetricsChanged(Akka.Cluster.Metrics.Events.ClusterMetricsChanged @event);
}
public interface IMetricsCollector : System.IDisposable
{
Akka.Cluster.Metrics.Serialization.NodeMetrics Sample();
Expand Down

0 comments on commit 8c800cf

Please sign in to comment.