cdugga
cdugga

Reputation: 3859

Can i use singleton scope for an Akka supervisor Actor in Spring?

I have a supervisor Actor which is responsible for throttling requests to a number of upstream systems. This supervisor actor creates child actors with a scope of prototype which do the actual heavy lifting of sending the requests.

I want to create just a single instance of my supervisor actor, i know it is recommended to give Akka Actors a scope of prototype however in this situation can i use a singleton scoped Actor to ensure all requests use the same supervisor?

Upvotes: 0

Views: 792

Answers (1)

pushy
pushy

Reputation: 9645

Ah, did not see that one before responding to your other question.

The reason that prototype scope should be used, is that Akka will restart actors on failures. If you have singleton scope this might lead to problems. However, Akka will not create new instances of your actor randomly. When you create an actor using actorOf, there will be an actor created each time, but only one actor (unless you use a router of course). So as long as you create your actors correctly you will only have one instance of this actor, and the ActorRef you got back from actorOf will always point to an instance of your actor. When exceptions occur, the actor will be stopped and a new instance is started, the actorRef will still point to that actor.

Upvotes: 2

Related Questions