Skip to content

Commit

Permalink
changed Router.Routees to just return underlying array
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaronontheweb committed Aug 31, 2021
1 parent a8a8156 commit d83f605
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/common.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<Copyright>Copyright © 2013-2021 Akka.NET Team</Copyright>
<Authors>Akka.NET Team</Authors>
<VersionPrefix>1.4.23</VersionPrefix>
<VersionPrefix>1.4.25</VersionPrefix>
<PackageIconUrl>https://getakka.net/images/akkalogo.png</PackageIconUrl>
<PackageProjectUrl>https://github.com/akkadotnet/akka.net</PackageProjectUrl>
<PackageLicenseUrl>https://github.com/akkadotnet/akka.net/blob/master/LICENSE</PackageLicenseUrl>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4472,7 +4472,7 @@ namespace Akka.Routing
[Akka.Annotations.InternalApiAttribute()]
public Router(Akka.Routing.RoutingLogic logic, Akka.Actor.IActorRef routee, params Akka.Actor.IActorRef[] routees) { }
public Router(Akka.Routing.RoutingLogic logic, params Akka.Routing.Routee[] routees) { }
public System.Collections.Generic.IEnumerable<Akka.Routing.Routee> Routees { get; }
public Akka.Routing.Routee[] Routees { get; }
public Akka.Routing.RoutingLogic RoutingLogic { get; }
public virtual Akka.Routing.Router AddRoutee(Akka.Routing.Routee routee) { }
public Akka.Routing.Router AddRoutee(Akka.Actor.IActorRef routee) { }
Expand Down
25 changes: 10 additions & 15 deletions src/core/Akka/Routing/Router.cs
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,6 @@ public abstract class RoutingLogic : INoSerializationVerificationNeeded
/// </summary>
public class Router
{
private readonly Routee[] _routees;

//The signature might look funky. Why not just Router(RoutingLogic logic, params ActorRef[] routees) ?
//We need one unique constructor to handle this call: new Router(logic). The other constructor will handle that.
//So in order to not confuse the compiler we demand at least one ActorRef. /@hcanber
Expand All @@ -265,22 +263,22 @@ public Router(RoutingLogic logic, IActorRef routee, params IActorRef[] routees)
{
if (routees == null || routees.Length == 0)
{
_routees = new []{ Routee.FromActorRef(routee) };
Routees = new []{ Routee.FromActorRef(routee) };
}
else
{
var routeesLength = routees.Length;

//Convert and put routee first in a new array
_routees = new Routee[routeesLength+1];
_routees[0] = Routee.FromActorRef(routee);
Routees = new Routee[routeesLength+1];
Routees[0] = Routee.FromActorRef(routee);

//Convert all routees and put them into the new array
for (var i = 0; i < routees.Length; i++)
{
var actorRef = routees[i];
var r = Routee.FromActorRef(actorRef);
_routees[i + 1] = r;
Routees[i + 1] = r;
}
}
RoutingLogic = logic;
Expand All @@ -294,17 +292,14 @@ public Router(RoutingLogic logic, IActorRef routee, params IActorRef[] routees)
/// <param name="routees">TBD</param>
public Router(RoutingLogic logic, params Routee[] routees)
{
_routees = routees ?? Array.Empty<Routee>();
Routees = routees ?? Array.Empty<Routee>();
RoutingLogic = logic;
}

/// <summary>
/// The set of <see cref="Routees"/> that this router is currently targeting.
/// </summary>
public IEnumerable<Routee> Routees
{
get { return _routees; }
}
public Routee[] Routees { get; }

/// <summary>
/// The logic used to determine which <see cref="Routee"/> will process a given message.
Expand Down Expand Up @@ -332,14 +327,14 @@ public virtual void Route(object message, IActorRef sender)
if (message is Broadcast)
{
var unwrapped = UnWrap(message);
foreach (var r in _routees)
foreach (var r in Routees)
{
r.Send(unwrapped, sender);
}
}
else
{
Send(RoutingLogic.Select(message, _routees), message, sender);
Send(RoutingLogic.Select(message, Routees), message, sender);
}
}

Expand Down Expand Up @@ -372,7 +367,7 @@ public virtual Router WithRoutees(params Routee[] routees)
/// <returns>A new <see cref="Router"/> instance with this routee added.</returns>
public virtual Router AddRoutee(Routee routee)
{
return new Router(RoutingLogic, _routees.Union(new[]{routee}).ToArray());
return new Router(RoutingLogic, Routees.Union(new[]{routee}).ToArray());
}

/// <summary>
Expand Down Expand Up @@ -402,7 +397,7 @@ public Router AddRoutee(ActorSelection routee)
/// <returns>A new <see cref="Router"/> instance with this same configuration, sans routee.</returns>
public virtual Router RemoveRoutee(Routee routee)
{
var routees = _routees.Where(r => !r.Equals(routee)).ToArray();
var routees = Routees.Where(r => !r.Equals(routee)).ToArray();
return new Router(RoutingLogic, routees);
}

Expand Down

0 comments on commit d83f605

Please sign in to comment.