Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor AdaptiveLoadBalancingRoutingLogic to use IClusterMetricsRoutingLogic #5237

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blowing up here is definitely better than doing it as an NRE inside the AdaptiveLoadBalancingMetricsListener, IMHO.

}

/// <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