What is the (best) way to get an ActorRef for a Singleton Actor
This is the code I use:
ActorRef instance = system.actorOf(Props.create(ContactServer.class, encoding, this));
instance.tell(new AbstractMap.SimpleImmutableEntry<>(device, actionJson), ActorRef.noSender());
The problem I am having is that the Actor never closes, so I end up with a whole lot of actors:
akka://application/user/$e
akka://application/user/$f
akka://application/user/$g
akka://application/user/$h
akka://application/user/$i
However, while I could close the Actor with "getContext().stop(getSelf())", it seems to make more sense to use it as a Singleton as there are no states saved in the Actor. But how to I get a reference to this Actor without creating new ones all the time?
To get the reference of an existing actor, you may either:
ActorRef
around after it is initialized in the actor system.In the system I'm currently working on, the 2nd approach works well because it is simple.