Why don't acc actors have a postStart method?

Here is the situation I have to deal with - I am using websockets with a replay framework and each websocket connection has its own Actor

as described here . Now, as soon as the websocket connection is established, I need to start another one Actor

that subscribes to the channel Redis

, and when it receives any published message on the channel, it passes that message to its parent ie Websocket Actor

. So I need to run Redis Subscriber Actor

after startup Websocket Actor

. But actors have no method postStart

. I tried to create Redis Subscriber Actor

in the method preStart

for Websocket Actor

and it works great, but I don't understand why it Actors

doesn't have a methodpostStart

... Isn't that a common scenario where actors create child actors. Or is this the wrong approach?

+3


source to share


1 answer


As stated in my comment, I'm not sure why preStart

not enough for your needs, this is one of the best places to create a child actor (the other is the body of the constructor). The point preStart

is, it really means pre-processing messages. The actor itself is running, but is not yet receiving messages from the mailbox. This is a good place to make sure any other dependencies are created before you start processing messages. If you did this after the actor started processing messages, you could hit a race condition where the (child) dependency hasn't been created yet



For more clarity, you should view the actor lifecycle diagram here

+9


source







All Articles