Hi I have an akka actor:
public class StatusActor extends UntypedActor {
public static ActorRef instance = Akka.system().actorOf(
new Props(StatusActor.class));
public void onReceive(Object message) {
Logger.info("Message received");
}
}
And I create a schedule for it ever 5 minutes:
Akka.system().scheduler().schedule(
Duration.create(60, TimeUnit.SECONDS),
Duration.create(5, TimeUnit.MINUTES), StatusActor.instance, null);
The problem I have is I want to change this time dynamically? Is there any way I can do this? I cannot find any methods to stop it. So then I can just start it again.
The only hack way I have thought of is at the end of the onReceive have it call the akka schedule to start again, and change all the values to run once, and have a static variable in the StatusActor for the frequency.
If anyone could tell me how to stop an actor/get access to it would be very helpful.
If you’d look at the return value of schedule, either in your IDE or in the documentation you’d see that it returns a Cancellable, so you can cancel the previous and schedule a new one.
Hope that helps!
Cheers,
√