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

Added missing FromConfig.Props(props) #1667

Merged
merged 1 commit into from
Feb 1, 2016
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 @@ -3794,6 +3794,7 @@ namespace Akka.Routing
public static Akka.Routing.FromConfig Instance { get; }
public override Akka.Routing.Router CreateRouter(Akka.Actor.ActorSystem system) { }
public override System.Collections.Generic.IEnumerable<Akka.Routing.Routee> GetRoutees(Akka.Routing.RoutedActorCell routedActorCell) { }
public static Akka.Actor.Props Props(Akka.Actor.Props props) { }
public override Akka.Util.ISurrogate ToSurrogate(Akka.Actor.ActorSystem system) { }
public class FromConfigSurrogate : Akka.Util.ISurrogate
{
Expand Down
1 change: 0 additions & 1 deletion src/core/Akka.Remote/RemoteActorRefProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
using Akka.Dispatch.SysMsg;
using Akka.Event;
using Akka.Remote.Configuration;
using Akka.Serialization;
using Akka.Util.Internal;

namespace Akka.Remote
Expand Down
97 changes: 42 additions & 55 deletions src/core/Akka/Routing/RouterConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ public bool Equals(Group other)
{
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
return _paths.SequenceEqual(other._paths);
return Paths.SequenceEqual(other.Paths);
}

/// <summary>
Expand All @@ -276,18 +276,13 @@ public override bool Equals(object obj)
/// </returns>
public override int GetHashCode()
{
return (_paths != null ? _paths.GetHashCode() : 0);
return Paths?.GetHashCode() ?? 0;
}

private readonly string[] _paths;

/// <summary>
/// Retrieves the actor paths used by this router during routee selection.
/// </summary>
public string[] Paths
{
get { return _paths; }
}
public string[] Paths { get; }

/// <summary>
/// Initializes a new instance of the <see cref="Group"/> class.
Expand All @@ -299,7 +294,7 @@ public string[] Paths
/// <param name="paths">An enumeration of actor paths used by the group router.</param>
protected Group(IEnumerable<string> paths) : base(Dispatchers.DefaultDispatcherId)
{
_paths = paths.ToArray();
Paths = paths.ToArray();
}

/// <summary>
Expand All @@ -315,7 +310,7 @@ protected Group(IEnumerable<string> paths) : base(Dispatchers.DefaultDispatcherI
protected Group(IEnumerable<string> paths, string routerDispatcher)
: base(routerDispatcher ?? Dispatchers.DefaultDispatcherId)
{
_paths = paths.ToArray();
Paths = paths.ToArray();
}

/// <summary>
Expand All @@ -329,7 +324,7 @@ protected Group(IEnumerable<string> paths, string routerDispatcher)
protected Group(IEnumerable<IActorRef> routees)
: base(Dispatchers.DefaultDispatcherId)
{
_paths = routees.Select(x => x.Path.ToStringWithAddress()).ToArray();
Paths = routees.Select(x => x.Path.ToStringWithAddress()).ToArray();
}

internal Routee RouteeFor(string path, IActorContext context)
Expand Down Expand Up @@ -388,9 +383,9 @@ public override Router CreateRouter(ActorSystem system)
/// </returns>
public override IEnumerable<Routee> GetRoutees(RoutedActorCell routedActorCell)
{
if (_paths == null) return new Routee[0];
if (Paths == null) return new Routee[0];
return
_paths.Select(((ActorSystemImpl) routedActorCell.System).ActorSelection)
Paths.Select(((ActorSystemImpl) routedActorCell.System).ActorSelection)
.Select(actor => new ActorSelectionRoutee(actor));
}

Expand Down Expand Up @@ -418,10 +413,6 @@ public override bool Equals(RouterConfig other)
/// </summary>
public abstract class Pool : RouterConfig, IEquatable<Pool>
{
private readonly int _nrOfInstances;
private readonly bool _usePoolDispatcher;
private readonly Resizer _resizer;
private readonly SupervisorStrategy _supervisorStrategy;
//TODO: add supervisor strategy to the equality compare

/// <summary>
Expand Down Expand Up @@ -462,7 +453,7 @@ public override int GetHashCode()
{
unchecked
{
int hashCode = (Resizer != null ? Resizer.GetHashCode() : 0);
int hashCode = Resizer?.GetHashCode() ?? 0;
hashCode = (hashCode*397) ^ UsePoolDispatcher.GetHashCode();
hashCode = (hashCode*397) ^ NrOfInstances;
return hashCode;
Expand All @@ -489,11 +480,11 @@ protected Pool(int nrOfInstances, Resizer resizer, SupervisorStrategy supervisor
// OMG, if every member in Java is virtual - you must never call any members in a constructor!!1!
// In all seriousness, without making these members virtual RemoteRouterConfig won't work
// ReSharper disable DoNotCallOverridableMethodsInConstructor
_nrOfInstances = nrOfInstances;
NrOfInstances = nrOfInstances;

_resizer = resizer;
_supervisorStrategy = supervisorStrategy ?? DefaultStrategy;
_usePoolDispatcher = usePoolDispatcher;
Resizer = resizer;
SupervisorStrategy = supervisorStrategy ?? DefaultStrategy;
UsePoolDispatcher = usePoolDispatcher;
}

/// <summary>
Expand All @@ -506,20 +497,17 @@ protected Pool(int nrOfInstances, Resizer resizer, SupervisorStrategy supervisor
/// <param name="config">The configuration used to configure the pool.</param>
protected Pool(Config config) : base(Dispatchers.DefaultDispatcherId)
{
_nrOfInstances = config.GetInt("nr-of-instances");
_resizer = DefaultResizer.FromConfig(config);
_usePoolDispatcher = config.HasPath("pool-dispatcher");
_supervisorStrategy = DefaultStrategy;
NrOfInstances = config.GetInt("nr-of-instances");
Resizer = DefaultResizer.FromConfig(config);
UsePoolDispatcher = config.HasPath("pool-dispatcher");
SupervisorStrategy = DefaultStrategy;
// ReSharper restore DoNotCallOverridableMethodsInConstructor
}

/// <summary>
/// Retrieves the number of routees associated with this pool.
/// </summary>
public virtual int NrOfInstances
{
get { return _nrOfInstances; }
}
public virtual int NrOfInstances { get; }

/// <summary>
/// Used by the <see cref="RoutedActorCell"/> to determine the initial number of routees.
Expand All @@ -539,26 +527,17 @@ public virtual int GetNrOfInstances(ActorSystem system)
/// Retrieve whether or not to use the pool dispatcher. The dispatcher is defined in the
/// 'pool-dispatcher' configuration property in the deployment section of the router.
/// </summary>
public virtual bool UsePoolDispatcher
{
get { return _usePoolDispatcher; }
}
public virtual bool UsePoolDispatcher { get; }

/// <summary>
/// Retrieve the resizer to use when dynamically allocating routees to the pool.
/// </summary>
public virtual Resizer Resizer
{
get { return _resizer; }
}
public virtual Resizer Resizer { get; }

/// <summary>
/// Retrieve the strategy to use when supervising the pool.
/// </summary>
public virtual SupervisorStrategy SupervisorStrategy
{
get { return _supervisorStrategy; }
}
public virtual SupervisorStrategy SupervisorStrategy { get; }

/// <summary>
/// Creates a new <see cref="Routee"/> configured to use the provided <paramref name="routeeProps"/>
Expand Down Expand Up @@ -638,9 +617,9 @@ protected RouterConfig OverrideUnsetConfig(RouterConfig other)
{
Pool wssConf;
var p = other as Pool;
if (SupervisorStrategy == null || (SupervisorStrategy.Equals(Pool.DefaultStrategy) &&
!p.SupervisorStrategy.Equals(Pool.DefaultStrategy)))
wssConf = this.WithSupervisorStrategy(p.SupervisorStrategy);
if (SupervisorStrategy == null || (SupervisorStrategy.Equals(DefaultStrategy) &&
!p.SupervisorStrategy.Equals(DefaultStrategy)))
wssConf = WithSupervisorStrategy(p.SupervisorStrategy);
else
wssConf = this;

Expand Down Expand Up @@ -695,10 +674,7 @@ protected RouterConfig OverrideUnsetConfig(RouterConfig other)
/// The default strategy used is <see cref="OneForOneStrategy"/> with an <see cref="Directive.Escalate"/> decider.
/// </note>
/// </summary>
public static SupervisorStrategy DefaultStrategy
{
get { return new OneForOneStrategy(10, TimeSpan.FromSeconds(10), Decider.From(Directive.Escalate)); }
}
public static SupervisorStrategy DefaultStrategy => new OneForOneStrategy(10, TimeSpan.FromSeconds(10), Decider.From(Directive.Escalate));

#endregion

Expand Down Expand Up @@ -728,23 +704,34 @@ public static SupervisorStrategy DefaultStrategy
/// </summary>
public class FromConfig : RouterConfig
{
private static readonly FromConfig _instance = new FromConfig(Dispatchers.DefaultDispatcherId);

private FromConfig(string routerDispatcher) : base(routerDispatcher)
{
}

/// <summary>
/// Enriches a <see cref="Akka.Actor.Props"/> with what what's stored in the router configuration.
/// <note>
/// This is semantically the same as:
/// <code>
/// props.WithRouter(FromConfig.Instance)
/// </code>
/// </note>
/// </summary>
/// <param name="props">The Props to enrich</param>
/// <returns></returns>
public static Props Props(Props props)
{
return props.WithRouter(Instance);
}

/// <summary>
/// Retrieves a <see cref="RouterConfig"/> based on what's stored in the configuration.
///
/// <note>
/// This router is set to use the default dispatcher <see cref="Dispatchers.DefaultDispatcherId"/>.
/// </note>
/// </summary>
public static FromConfig Instance
{
get { return _instance; }
}
public static FromConfig Instance { get; } = new FromConfig(Dispatchers.DefaultDispatcherId);

/// <summary>
/// Creates a router that is responsible for routing messages to routees within the provided <paramref name="system"/>.
Expand Down