Respond to calling actor from trait (trait doesn't extend actor)

Scenario:

How do I alert the sender , after 3 retries are done by back off supervisor ? The parent can be any actor calling the trait(that has backoff supervisor).I have a trait backoffsupervisor which has def to call the supervisor . When there is an exception thrown from an actor class, it calls this trait def(does 3 retries with supervisor strategy). Now what I would like is to respond to the calling actor after 3 retries are done( I am unable to use the sender() option). Once the actor receives that 3 retries are done, it will log the error info into mongo db.

trait backoff{
def getbackoff(props:Props):Props{
BackoffSupervisor.props(
      BackoffOpts.onFailure(
      props,
      props.getClass.getSimpleName,
      1.seconds,
      1.seconds,
      0
    )
      .withSupervisorStrategy(OneForOneStrategy(maxNrOfRetries = 3){
        case _ :Exception=> //println(s"inside back off and exception is ${this.getClass.getName}")
          SupervisorStrategy.restart
      })
    )
}
}  
 
//com.scala.callingActor
import com.scala.AnotherActor.{Result,fail}
object CallingActor extends backoff{
def props={val actorProps=Props(classOf[CallingActor])
getbackoff(actorprops)}
}
class CallingActor extends Actor{
override def recieve:Recieve={
case Result=>context.parent ! fail
throws Exception("somrthing happened")}
}

Options I tried : saved the actorref in a val and sent it to back off supervisor. Editted code below:

  1. //custom exception to send actor ref
  2. case class MyException(msg:String,ref:ActorRef) extends Exception
  • trait backoff{
  1. def getbackoff(props:Props):Props{
  2. BackoffSupervisor.props(
  3. BackoffOpts.onFailure(
  4. props,
  5. props.getClass.getSimpleName,
  6. 1.seconds,
  7. 1.seconds,
  8. 0
  9. )
  10. .withSupervisorStrategy(OneForOneStrategy(maxNrOfRetries = 3){
  11. case e :MyException=> println(s"inside back off and exception is ${this.getClass.getName}")
  12. e.ref !“retriesDone”
  13. SupervisorStrategy.restart
  14. })
  15. )
  16. }
  17. }
  1. import com.scala.AnotherActor.{Result,fail}
  2. object CallingActor extends backoff{
  3. def props={val actorProps=Props(classOf[CallingActor])
  4. getbackoff(actorprops)}
  5. }
  6. class CallingActor extends Actor{
  7. override def recieve:Recieve={
  8. case Result=>context.parent ! fail
  9. throw MyException(“somrthing happened”,context.self)
  10. case message:String=>println(s"message= ${message}")
  11. }
  12. }

The message is going to dead letters and not passed to the sender. I also tried sending the message to parent of the sender by passing parent actor ref, but that didn’t work either.Any other suggestion? to resolve this issue