I'm relatively new to the idea of actors, and was wondering if I could get some critique on what I am doing. For part of a project, I need to have an actor that tells a collection of listening actors the time. The listening actors must be able to be added to this actor.
Currently I have this:
import akka.actor.Actor;
import akka.actor.ActorRef;
import com.github.nscala_time.time.Imports._;
class TimeManager extends Actor {
var actors:List[ActorRef] = List();
def receive = {
case AdvanceTime() => actors foreach (_ ! DateTime.now)
case AddListener(x) => actors = x :: actors
}
}
Is there any way that I can remove the state (var actors) from this code to make it more functional?