Aaronontheweb on dev
Remove string interpolation fro… (compare)
Aaronontheweb on dev
Made cleanup call thread-safe (… (compare)
dependabot-preview[bot] on nuget
Bump System.Data.SqlClient from… (compare)
@robertmircea I think your question is too general. Depending on what you want to get done, different solutions applies.
I was trying to port Akka.IO from JVM to .NET - I remember, that I've got serious problems with integrating akka threading model with async sockets (first tried a way similar to cannonical Akka, but Java NIO cannot be reflected directly in .NET) and that @Aaronontheweb already encouraged them when he was creating Helios, but I don't remember specifics
//this code is part of the actor
var receiveSaea = new SocketAsyncEventArgs();
receiveSaea.Completed += ReceivedCompleted;
receiveSaea.AcceptSocket = socket;
socket.ReceiveAsync(receiveSaea);
[...]
//later, this callback is called when socket read is completed
private void ReceivedCompleted(object sender, SocketAsyncEventArgs e)
{
var connectionInfo = e.UserToken as ConnectionInfo;
if (connectionInfo == null)
throw new InvalidOperationException("Could not find a reference to ConnectionInfo");
if (e.SocketError != SocketError.Success)
{
log.Error("IO error while receiving data over socket: " + e.SocketError);
//TODO: I need to tell the calling actor to shutdown itself, but I cannot use Context.Stop(connectionInfo.Sender) here
return;
}
ConnectionInfo
contains an ActionRef to the actor.
.PipeTo(Self)
on that task.. 2) use a closure that binds a copy of Context in a local var.. 3) download the latest source and use our new TPL support
var context = Context;
var receiveSaea = new SocketAsyncEventArgs();
receiveSaea.Completed += ReceivedCompleted;
receiveSaea.AcceptSocket = socket;
socket.ReceiveAsync((sender,e) => {
var connectionInfo = e.UserToken as ConnectionInfo;
if (connectionInfo == null)
throw new InvalidOperationException("Could not find a reference to ConnectionInfo");
if (e.SocketError != SocketError.Success)
{
log.Error("IO error while receiving data over socket: " + e.SocketError);
Context.Stop(connectionInfo.Sender)
return;
}
});
@nvivo @Aaronontheweb I have been playing around with a few ideas dealing with calling Context.ActorOf<SomeActor>().Tell(message); from within an actor that was created using the DI Extension but that extension not being used by the extension method.
namespace Akka.Actor
{
public static class ActorRefFactoryExtensions
{
public static ActorRef ActorOf<TActor>(this ActorRefFactory factory, string name = null) where TActor : ActorBase, new()
{
return factory.ActorOf(Props.Create<TActor>(), name: name);
}
}
}
Every time I tried to make it transparent it just got messy. It's not to say it can't be done but I think it's not worth the effort. That being said I came up with my own prototype of an extension for the DI.Core that works but requires you to add the namespace which is kind of a compromise because @nvivo you were looking for something not requiring you to know that you are using the DI extension but I think it works. What do you think?
public static ActorRef ActorOf<TActor>(this IActorContext context, string name = null) where TActor : ActorBase, new()
{
var producer = context.System.GetExtension<DIExt>();
return context.ActorOf(producer.Props(typeof(TActor).Name),name);
}
You still have to be careful but it turns this
var producer = Context.System.GetExtension<DIExt>();
Context.ActorOf(producer.Props("TypedWorker")).Tell(message);
Into this
Context.ActorOf<TypedWorker>().Tell(message);