-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Deprecate ClusterSingleton.Init()
and add missing singleton feature to ClusterSingletonSettings
#7387
Merged
Aaronontheweb
merged 5 commits into
akkadotnet:dev
from
Arkatufus:deprecate-ClusterSingleton.Init
Nov 15, 2024
Merged
Deprecate ClusterSingleton.Init()
and add missing singleton feature to ClusterSingletonSettings
#7387
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e1a492f
Deprecate `ClusterSingleton.Init()`
Arkatufus ea51560
Update API Approval list
Arkatufus 6069d6e
Update akkadotnet-v1.5-upgrade-advisories.md
Aaronontheweb cb85427
Update akkadotnet-v1.5-upgrade-advisories.md
Aaronontheweb e940e4e
Merge branch 'dev' into deprecate-ClusterSingleton.Init
Aaronontheweb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
using System.Collections.Concurrent; | ||
using Akka.Actor; | ||
using Akka.Annotations; | ||
using Akka.Configuration; | ||
using Akka.Util; | ||
|
||
namespace Akka.Cluster.Tools.Singleton | ||
|
@@ -22,6 +23,17 @@ public class ClusterSingleton : IExtension | |
{ | ||
private readonly ActorSystem _system; | ||
private readonly Lazy<Cluster> _cluster; | ||
|
||
/// <summary> | ||
/// Returns default HOCON configuration for the cluster singleton. | ||
/// </summary> | ||
public static Config DefaultConfig() | ||
{ | ||
return ConfigurationFactory.FromResource<ClusterSingleton>( | ||
"Akka.Cluster.Tools.Singleton.reference.conf"); | ||
} | ||
|
||
// Cache for singleton proxies, remove in v1.6 | ||
private readonly ConcurrentDictionary<string, IActorRef> _proxies = new(); | ||
|
||
public static ClusterSingleton Get(ActorSystem system) => | ||
|
@@ -30,6 +42,7 @@ public static ClusterSingleton Get(ActorSystem system) => | |
public ClusterSingleton(ExtendedActorSystem system) | ||
{ | ||
_system = system; | ||
_system.Settings.InjectTopLevelFallback(DefaultConfig()); | ||
_cluster = new Lazy<Cluster>(() => Cluster.Get(system)); | ||
} | ||
|
||
|
@@ -40,6 +53,10 @@ public ClusterSingleton(ExtendedActorSystem system) | |
/// <para>If there already is a proxy running for the given `singletonName` on this node, an <see cref="IActorRef"/> to that is returned.</para> | ||
/// </summary> | ||
/// <returns>A proxy actor that can be used to communicate with the singleton in the cluster</returns> | ||
[Obsolete("This convenience method is deprecated and will be removed in v1.6, " + | ||
"please use ClusterSingletonManager.Props and ClusterSingletonProxy.Props directly instead. " + | ||
"See https://getakka.net/community/whats-new/akkadotnet-v1.5-upgrade-advisories.html#upgrading-to-akkanet-v1532. " + | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. LGTM |
||
"Since 1.5.32.")] | ||
public IActorRef Init(SingletonActor singleton) | ||
{ | ||
var settings = singleton.Settings.GetOrElse(ClusterSingletonSettings.Create(_system)); | ||
|
@@ -63,21 +80,23 @@ public IActorRef Init(SingletonActor singleton) | |
return GetProxy(singleton.Name, settings); | ||
} | ||
|
||
[Obsolete("Deprecated, remove in v1.6")] | ||
private IActorRef GetProxy(string name, ClusterSingletonSettings settings) | ||
{ | ||
IActorRef ProxyCreator() | ||
{ | ||
var proxyName = $"singletonProxy{name}"; | ||
return _system.ActorOf(ClusterSingletonProxy.Props( | ||
singletonManagerPath: $"/user/{ManagerNameFor(name)}", | ||
settings: settings.ToProxySettings(name)), | ||
proxyName); | ||
return _system.ActorOf( | ||
props: ClusterSingletonProxy.Props( | ||
singletonManagerPath: $"/user/{ManagerNameFor(name)}", | ||
settings: settings.ToProxySettings(name)), | ||
name: proxyName); | ||
} | ||
|
||
return _proxies.GetOrAdd(name, _ => ProxyCreator()); | ||
} | ||
|
||
|
||
[Obsolete("Deprecated, remove in v1.6")] | ||
private string ManagerNameFor(string singletonName) => $"singletonManager{singletonName}"; | ||
} | ||
|
||
|
@@ -86,6 +105,10 @@ public class ClusterSingletonProvider : ExtensionIdProvider<ClusterSingleton> | |
public override ClusterSingleton CreateExtension(ExtendedActorSystem system) => new(system); | ||
} | ||
|
||
[Obsolete("This setting class is deprecated and will be removed in v1.6, " + | ||
"please use ClusterSingletonManager.Props and ClusterSingletonProxy.Props directly instead. " + | ||
"See https://getakka.net/community/whats-new/akkadotnet-v1.5-upgrade-advisories.html#upgrading-to-akkanet-v1532. " + | ||
"Since 1.5.32.")] | ||
public class SingletonActor | ||
{ | ||
public string Name { get; } | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I agree we don't really need a cache for this - that's a little too clever for its own good.