score:2

Accepted answer

i don't think, it is started twice.

your create funciton is recursive and executed whenever case subscriberschanged(actors) => happens.

so whenever your list of subscribers changes, you will see your log message.

you refactor create to exclude the log message from recursion ... something like this:

def create(initialsubscribers: vector[actorref[serverevent]]): behavior[informantevent] = {
  behaviors.setup { context =>

    context.log.info(s"=============> start informantactor <=============")

    def behavior(subscribers: vector[actorref[serverevent]]): behavior[informantevent] = behaviors.receivemessage[informantevent] {
      case serverofflineconfirmed =>
        subscribers.foreach(a => a ! serverofflineapproved)
        behavior.same
      case serveronlineconfirmed =>
        subscribers.foreach(a => a ! serveronlineapproved)
        behavior.same
      case subscriberschanged(actors) =>
        behavior(actors)
    }

    behavior(initialsubscribers)
  }
}

Related Query

More Query from same tag