These are chat archives for petabridge/akka-bootcamp

24th
Feb 2015
Jorge Fioranelli
@jorgef
Feb 24 2015 02:42
Hi, in lesson 3 you show a way to create an actor from another actor: https://github.com/petabridge/akka-bootcamp/tree/master/src/Unit-1/lesson3#1-create-the-actor but I don't see any ActorOf method on the ActorRef object. From what I can see it is only available on the ActorRefFactory interface. Am I missing something?
Aaron Stannard
@Aaronontheweb
Feb 24 2015 02:42
muahah, yes we tricked you! :p
ah crap, that's a mistake actually
damnit, nevermind :(
Jorge Fioranelli
@jorgef
Feb 24 2015 02:43
lol, I couldn
Aaron Stannard
@Aaronontheweb
Feb 24 2015 02:43
the ActorOf call you do inside an Actor is Context.ActorOf
and Context inherits from ActorRefFactory
Jorge Fioranelli
@jorgef
Feb 24 2015 02:44
I couldn't find the equivalent in F#, and then I realized is not even possible in C# :p
cool, thanks
Aaron Stannard
@Aaronontheweb
Feb 24 2015 02:47
going to change it to this:
// have to create the child actor somewhere inside myFirstActor
// usually happens inside OnReceive or PreStart
class MyActorClass : UntypedActor{
    protected override void PreStart(){
        ActorRef myFirstChildActor = Context.ActorOf(Props.Create(() => new MyChildActorClass()), "myFirstChildActor")
    }
}
Aaron Stannard
@Aaronontheweb
Feb 24 2015 02:56
just sent in a PR, should be fixed now
thanks for pointing that out :p
Jorge Fioranelli
@jorgef
Feb 24 2015 03:02
cool, looks good, thanks
Ralf Westphal
@ralfw
Feb 24 2015 11:22

ActorRefs are often injected into actors through the ctor in Props.Create():

var p = Props.Create(() => new MyActor(someActorRef));

I tried to do use field/property injection instead, e.g.

var p = Props.Create(() => new MyActor{SomeRef = someActorRef});

But it does not seem to work. All's well at compile time. But at runtime an InvalidCastException is thrown. Why's that? I'm using the same someActorRef in both cases.

Roger Johansson
@rogeralsing
Feb 24 2015 11:53
@ralfw this is a limitation on how actors are created, the new MyActor(..) will be treated as a linq expression, where we extract all the inparamterers from the constructor. we need to extract these in order to be able to remote deploy the actor to another server. also, since actors are black-boxes, there is no real need to expose anything public on them.
HÃ¥kan Canberger
@HCanber
Feb 24 2015 12:06
@ralfw In short: Only inject through constructor. Public prop-getters can be useful when writing unit tests, but that's the only usage of properties in actors I can think of, see http://blog.canberger.se/2014/10/introducing-testkit-for-akkanet.html
Ralf Westphal
@ralfw
Feb 24 2015 13:06
Ok. Thx for the info. Good to know.
Aaron Stannard
@Aaronontheweb
Feb 24 2015 21:57
@/all for everyone wondering what you're going to do in Unit 2, thought I'd give you a preview: https://twitter.com/petabridge/status/570341638662328321
Jorge Fioranelli
@jorgef
Feb 24 2015 22:28
nice!!
Ralph Willgoss
@ralphwillgoss
Feb 24 2015 23:08
can't wait!
just finishing Unit 1 now