To print the list of actors that are running in the actor system, you can add following scheduler that will print actor path every 10 seconds:
import akka.actor.{Actor, ActorIdentity, ActorLogging, ActorRef, Cancellable, Props}
class TestActor extends Actor with ActorLogging {
private var scheduler: Cancellable = _
@scala.throws[Exception](classOf[Exception])
override def preStart(): Unit = {
import scala.concurrent.duration._
scheduler = context.system.scheduler.schedule(
initialDelay = 0 seconds,
interval = 10 seconds,
receiver = self,
message = ActorIdentity("", Some(self))
)
}
@scala.throws[IOException](classOf[IOException])
override def postStop() = {
scheduler.cancel
}
override def receive = {
case ActorIdentity(_, Some(ref)) =>
log.info(ref.path.toString)
}
}
Comments