Akka Actor Re-enable after failure

I have an actor who oversees another actor (who is removed, so you cannot refer to him directly). He gets a link to the actor using actorSelectionand Identify, and then looks at the resulting one ActorRef. It works.

But now I want to automatically connect the same way as when another actor completes, so I reuse the same one actorSelection(the Actor instance gets the instance in the same place), but this time the search through is Identifycompleted forever. I have no idea why this works when the actor is already created at the beginning, but no, otherwise.

Edit: What is also strange is that association errors occur before the first connection, while there is no association error when trying to reconnect, even if the remote jvm is completely completed. I just noticed that if you wait minutes or more after the failure, the association error returns and the connection ends again. Is there a way to configure this mechanism (is it a Cache mechanism?).

Is this standard behavior or is something wrong with me?

In case I messed up something with my code:

object ServerMonitor {
  case object Request
  case class Reply(ref: ActorRef)
}

class ServerMonitor(path: String) extends Actor with ActorLogging {
  import ServerMonitor._

  var server: Option[ActorRef] = None  
  var listeners: Set[ActorRef] = Set.empty

  def receive = {
    case ActorIdentity("server", Some(ref)) =>
      server = Some(ref)
      context.watch(ref)
      listeners.foreach(_ ! Reply(ref))
      listeners = Set.empty
      log.info(s"connected to the server at $path")

    case ActorIdentity("server", None) =>
      server = None
      log.warning(s"couldnt reach the server at $path")
      import context.dispatcher
      context.system.scheduler.scheduleOnce(1 second) {
        context.actorSelection(path) ! Identify("server")
      }

    case Terminated(ref) =>
      log.warning("server terminated")
      server = None
      context.actorSelection(path) ! Identify("server")

    case Request =>
      server.fold { 
        listeners += sender
      } { ref =>
        sender ! Reply(ref)
      }
  }

  override def preStart() {
    context.actorSelection(path) ! Identify("server")
  }
}
+4
source share
1 answer

Ok, I just found out what the problem is. Configuration value:

# The length of time to gate an address whose name lookup has failed
# or has explicitly signalled that it will not accept connections
# (remote system is shutting down or the requesting system is quarantined).
# No connection attempts will be made to an address while it remains
# gated. Any messages sent to a gated address will be directed to dead
# letters instead. Name lookups are costly, and the time to recovery
# is typically large, therefore this setting should be a value in the
# order of seconds or minutes.
gate-invalid-addresses-for = 60 s

, . 60- .

+3

All Articles