I am currently adding Akka to our existing system that currently does
distributed programming with Executors in Hazelcast. Obviously he executor
system is not scaling so I am currently working on how to convert it to an
actor system. The temptation I have is to do the code below for my scoring
manager but it feels so boilerplate and common that I feel I must be
missing something or doing something wrong. The scoring manager exists once
per node and I need to call it from a lot of places including other actors
so, upon reading the docs, I read that using ActorSelection to call all the
time is a performance issue so I thought caching the ref would be a good
idea. This is how I went about it.
private static ActorRef scoringManagerRef = null;
public static ActorRef start(final ActorSystem system) {
if (scoringManagerRef != null) throw new IllegalStateException("Already
started.");
scoringManagerRef = system.actorOf(Props.create(LiveScoringManager.class));
return scoringManagerRef;
}
private static ActorSelection actorSelection(final ActorSystem system) {
return system.actorSelection(DEFAULT_PATH);
}
public static ActorRef actorRef() {
if (scoringManagerRef == null || scoringManagerRef.isTerminated()) {
scoringManagerRef = null;
final Option<Try<ActorRef>> value =
actorSelection(Ruckus.getActorSystem())
.resolveOne(new Timeout(1, TimeUnit.SECONDS)).value();
if (value.isDefined()) scoringManagerRef = value.get().get();
}
return scoringManagerRef;
}
The idea is that since there is only one per node, we can start it when the
ActorSystem goes up but if the actor system restarts the manager then we
want to refresh the ref. Of course there is always the chance that
milliseconds after we check for "isTerminated" the actor is actually
terminated. I am not so sure what would happen then, messages to DLQ?
Hopefully an exception would occur but which?
Anyway I would need this pretty much everywhere on all of my Actors to make
calling them efficient so this seems to be something I must be doing
incorrectly. Any advice is appreciated.
--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ:
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.