0

Hi I have applied supervision on Parent actor and the child is Throwing MongoTimeOutException (I intentionally raised that exception for testing purpose) but the default case got invoked in supervision.

Here is the code:

class child extends Actor {
 def receive = {
  case insertData(data) => 
     //insertion code ,MongoTimeOutException is raised i have killed the service intentionally 
 }
}

class parent extends Actor {

val child=context.actorOf.....//actor creation code

override val supervisorStrategy = OneForOneStrategy(
                                    maxNrOfRetries = 10, withinTimeRange = 10 seconds) {
    case _:MongoException=>
      log.error("Got some MongosException, Supervision Strategy says Resume")  
      Resume
    case _:ElasticsearchTimeoutException=>
      log.error("Got some ElasticsearchTimeoutException, Supervision Strategy says Resume")  
      Resume
    case _:ElasticsearchException=>
      log.error("Got some ElasticsearchException, Supervision Strategy says Resume")  
      Resume
    case _ => 
      log.error("Got some Exception, Supervision Strategy says Resume")
      Resume
  }

 def receive = {
  case Msg(data) => 
     child ! insertData(data)
 }
}

object test extends App
{
 val parent = system.actorof....//actor creation code
 parent !Msg(data)
}

When I run this code MongoTimeOutException do occur but this case got invoked in supervision.

case _ => 
      log.error("Got some Exception, Supervision Strategy says Resume")
      Resume

Why is that so? According to me it should invoke this case:

case _:MongoException=>
  log.error("Got some MongosException, Supervision Strategy says Resume")  

Am I doing something wrong?

Please help me .

Elydasian
  • 2,016
  • 5
  • 23
  • 41
swaheed
  • 3,671
  • 10
  • 42
  • 103

1 Answers1

0

Print the class of the default case value and see what is the real exception so that you can handle it.

Here is your code

case _ => 
      log.error("Got some Exception, Supervision Strategy says Resume")
      Resume

Here is what you have to do (Print the exception class)

case ex =>
     log.error(s"Exception $ex of type ${ex.getClass}.Got some Exception, Supervision Strategy says Resume", ex)
    Resume

The above code will help you understand what is the exact message which could not be caught.

Nagarjuna Pamu
  • 14,737
  • 3
  • 22
  • 40