Skip to content

Commit

Permalink
Netstandard2.0 (#13)
Browse files Browse the repository at this point in the history
* migrated all libraries to .NET Standard 2.0

* added v0.1.0 release notes
  • Loading branch information
Aaronontheweb authored Mar 10, 2022
1 parent 5f815d3 commit f50dbf4
Show file tree
Hide file tree
Showing 10 changed files with 614 additions and 595 deletions.
4 changes: 2 additions & 2 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
## [0.3.0] / 14 January 2022
- Fixed bugs
## [0.1.0] / 09 March 2022
- Initial release of Akka.Hosting, Akka.Remote.Hosting, Akka.Cluster.Hosting, and Akka.Persistence.SqlServer.Hosting
3 changes: 1 addition & 2 deletions src/Akka.Cluster.Hosting/Akka.Cluster.Hosting.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">


<PropertyGroup>
<TargetFramework>$(LibraryFramework)</TargetFramework>
<PackageReadmeFile>README.md</PackageReadmeFile>
<Description>Akka.Cluster and Akka.Cluster.Sharding Microsoft.Extensions.Hosting support.</Description>
<LangVersion>9</LangVersion>
</PropertyGroup>
<ItemGroup>
<None Include="..\..\README.md" Pack="true" PackagePath="\" />
Expand Down
452 changes: 231 additions & 221 deletions src/Akka.Cluster.Hosting/AkkaClusterHostingExtensions.cs

Large diffs are not rendered by default.

180 changes: 91 additions & 89 deletions src/Akka.Hosting/ActorRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,110 +3,112 @@
using System.Collections.Generic;
using Akka.Actor;

namespace Akka.Hosting;

/// <summary>
/// INTERNAL API
/// </summary>
public class ActorRegistryExtension : ExtensionIdProvider<ActorRegistry>
{
public override ActorRegistry CreateExtension(ExtendedActorSystem system)
{
return new ActorRegistry();
}
}

/// <summary>
/// Mutable, but thread-safe <see cref="ActorRegistry"/>.
/// </summary>
/// <remarks>
/// Should only be used for top-level actors that need to be accessed from inside or outside the <see cref="ActorSystem"/>.
///
/// If you are adding every single actor in your <see cref="ActorSystem"/> to the registry you are definitely using it wrong.
/// </remarks>
public class ActorRegistry : IExtension
namespace Akka.Hosting
{
private readonly ConcurrentDictionary<Type, IActorRef> _actorRegistrations = new ConcurrentDictionary<Type, IActorRef>();

/// <summary>
/// Attempts to register an actor with the registry.
/// INTERNAL API
/// </summary>
/// <param name="actor">The bound <see cref="IActorRef"/>, if any. Is set to <see cref="ActorRefs.Nobody"/> if key is not found.</param>
/// <param name="overwrite">If <c>true</c>, allows overwriting of a previous actor with the same key. Defaults to <c>false</c>.</param>
/// <returns><c>true</c> if the actor was set to this key in the registry, <c>false</c> otherwise.</returns>
public bool TryRegister<TKey>(IActorRef actor, bool overwrite = false)
public class ActorRegistryExtension : ExtensionIdProvider<ActorRegistry>
{
return TryRegister(typeof(TKey), actor, overwrite);
}

/// <summary>
/// Attempts to register an actor with the registry.
/// </summary>
/// <param name="key">The key for a particular actor.</param>
/// <param name="actor">The bound <see cref="IActorRef"/>, if any. Is set to <see cref="ActorRefs.Nobody"/> if key is not found.</param>
/// <param name="overwrite">If <c>true</c>, allows overwriting of a previous actor with the same key. Defaults to <c>false</c>.</param>
/// <returns><c>true</c> if the actor was set to this key in the registry, <c>false</c> otherwise.</returns>
public bool TryRegister(Type key, IActorRef actor, bool overwrite = false)
{
if (!overwrite)
return _actorRegistrations.TryAdd(key, actor);
else
_actorRegistrations[key] = actor;
return true;
}

/// <summary>
/// Try to retrieve an <see cref="IActorRef"/> with the given <see cref="TKey"/>.
/// </summary>
/// <param name="actor">The bound <see cref="IActorRef"/>, if any. Is set to <see cref="ActorRefs.Nobody"/> if key is not found.</param>
/// <returns><c>true</c> if an actor with this key exists, <c>false</c> otherwise.</returns>
public bool TryGet<TKey>(out IActorRef actor)
{
return TryGet(typeof(TKey), out actor);
public override ActorRegistry CreateExtension(ExtendedActorSystem system)
{
return new ActorRegistry();
}
}

/// <summary>
/// Try to retrieve an <see cref="IActorRef"/> with the given <see cref="TKey"/>.
/// Mutable, but thread-safe <see cref="ActorRegistry"/>.
/// </summary>
/// <param name="key">The key for a particular actor.</param>
/// <param name="actor">The bound <see cref="IActorRef"/>, if any. Is set to <see cref="ActorRefs.Nobody"/> if key is not found.</param>
/// <returns><c>true</c> if an actor with this key exists, <c>false</c> otherwise.</returns>
public bool TryGet(Type key, out IActorRef actor)
/// <remarks>
/// Should only be used for top-level actors that need to be accessed from inside or outside the <see cref="ActorSystem"/>.
///
/// If you are adding every single actor in your <see cref="ActorSystem"/> to the registry you are definitely using it wrong.
/// </remarks>
public class ActorRegistry : IExtension
{
if (_actorRegistrations.ContainsKey(key))
private readonly ConcurrentDictionary<Type, IActorRef> _actorRegistrations =
new ConcurrentDictionary<Type, IActorRef>();

/// <summary>
/// Attempts to register an actor with the registry.
/// </summary>
/// <param name="actor">The bound <see cref="IActorRef"/>, if any. Is set to <see cref="ActorRefs.Nobody"/> if key is not found.</param>
/// <param name="overwrite">If <c>true</c>, allows overwriting of a previous actor with the same key. Defaults to <c>false</c>.</param>
/// <returns><c>true</c> if the actor was set to this key in the registry, <c>false</c> otherwise.</returns>
public bool TryRegister<TKey>(IActorRef actor, bool overwrite = false)
{
actor = _actorRegistrations[key];
return TryRegister(typeof(TKey), actor, overwrite);
}

/// <summary>
/// Attempts to register an actor with the registry.
/// </summary>
/// <param name="key">The key for a particular actor.</param>
/// <param name="actor">The bound <see cref="IActorRef"/>, if any. Is set to <see cref="ActorRefs.Nobody"/> if key is not found.</param>
/// <param name="overwrite">If <c>true</c>, allows overwriting of a previous actor with the same key. Defaults to <c>false</c>.</param>
/// <returns><c>true</c> if the actor was set to this key in the registry, <c>false</c> otherwise.</returns>
public bool TryRegister(Type key, IActorRef actor, bool overwrite = false)
{
if (!overwrite)
return _actorRegistrations.TryAdd(key, actor);
else
_actorRegistrations[key] = actor;
return true;
}

actor = ActorRefs.Nobody;
return false;
}
/// <summary>
/// Try to retrieve an <see cref="IActorRef"/> with the given <see cref="TKey"/>.
/// </summary>
/// <param name="actor">The bound <see cref="IActorRef"/>, if any. Is set to <see cref="ActorRefs.Nobody"/> if key is not found.</param>
/// <returns><c>true</c> if an actor with this key exists, <c>false</c> otherwise.</returns>
public bool TryGet<TKey>(out IActorRef actor)
{
return TryGet(typeof(TKey), out actor);
}

/// <summary>
/// Fetches the <see cref="IActorRef"/> by key.
/// </summary>
/// <typeparam name="TKey">The key type to retrieve this actor.</typeparam>
/// <returns>If found, the underlying <see cref="IActorRef"/>.
/// If not found, returns <see cref="ActorRefs.Nobody"/>.</returns>
public IActorRef Get<TKey>()
{
if (TryGet<TKey>(out var actor))
return actor;
return ActorRefs.Nobody;
}
/// <summary>
/// Try to retrieve an <see cref="IActorRef"/> with the given <see cref="TKey"/>.
/// </summary>
/// <param name="key">The key for a particular actor.</param>
/// <param name="actor">The bound <see cref="IActorRef"/>, if any. Is set to <see cref="ActorRefs.Nobody"/> if key is not found.</param>
/// <returns><c>true</c> if an actor with this key exists, <c>false</c> otherwise.</returns>
public bool TryGet(Type key, out IActorRef actor)
{
if (_actorRegistrations.ContainsKey(key))
{
actor = _actorRegistrations[key];
return true;
}

/// <summary>
/// Allows enumerated access to the collection of all registered actors.
/// </summary>
/// <returns></returns>
public IEnumerator<KeyValuePair<Type, IActorRef>> GetEnumerator()
{
return _actorRegistrations.GetEnumerator();
}
actor = ActorRefs.Nobody;
return false;
}

public static ActorRegistry For(ActorSystem actorSystem)
{
return actorSystem.WithExtension<ActorRegistry, ActorRegistryExtension>();
/// <summary>
/// Fetches the <see cref="IActorRef"/> by key.
/// </summary>
/// <typeparam name="TKey">The key type to retrieve this actor.</typeparam>
/// <returns>If found, the underlying <see cref="IActorRef"/>.
/// If not found, returns <see cref="ActorRefs.Nobody"/>.</returns>
public IActorRef Get<TKey>()
{
if (TryGet<TKey>(out var actor))
return actor;
return ActorRefs.Nobody;
}

/// <summary>
/// Allows enumerated access to the collection of all registered actors.
/// </summary>
/// <returns></returns>
public IEnumerator<KeyValuePair<Type, IActorRef>> GetEnumerator()
{
return _actorRegistrations.GetEnumerator();
}

public static ActorRegistry For(ActorSystem actorSystem)
{
return actorSystem.WithExtension<ActorRegistry, ActorRegistryExtension>();
}
}
}
Loading

0 comments on commit f50dbf4

Please sign in to comment.