def invoke()

in actor/src/main/scala/org/apache/pekko/actor/TypedActor.scala [466:499]


    def invoke(proxy: AnyRef, method: Method, args: Array[AnyRef]): AnyRef = method.getName match {
      case "toString" => actor.toString
      case "equals" =>
        (args.length == 1 && (proxy eq args(0)) || actor == extension.getActorRefFor(args(0)))
          .asInstanceOf[AnyRef] // Force boxing of the boolean
      case "hashCode" => actor.hashCode.asInstanceOf[AnyRef]
      case _ =>
        implicit val dispatcher = extension.system.dispatcher
        import pekko.pattern.ask
        MethodCall(method, args) match {
          case m if m.isOneWay =>
            actor ! m; null // Null return value
          case m if m.returnsFuture =>
            ask(actor, m)(timeout).map {
              case NullResponse => null
              case other        => other
            }
          case m if m.returnsJOption || m.returnsOption =>
            val f = ask(actor, m)(timeout)
            (try {
              Await.ready(f, timeout.duration).value
            } catch { case _: TimeoutException => None }) match {
              case None | Some(Success(NullResponse)) | Some(Failure(_: AskTimeoutException)) =>
                if (m.returnsJOption) JOption.none[Any] else None
              case Some(t: Try[_]) =>
                t.get.asInstanceOf[AnyRef]
            }
          case m =>
            Await.result(ask(actor, m)(timeout), timeout.duration) match {
              case NullResponse => null
              case other        => other.asInstanceOf[AnyRef]
            }
        }
    }