0

I am facing a weird exception

java.lang.ClassCastException: Cannot cast akka.actor.Status$Success$ to akka.actor.Status$Success
    at java.lang.Class.cast(Class.java:3094) ~[na:1.7.0_45]
    at scala.concurrent.Future$$anonfun$mapTo$1.apply(Future.scala:405) ~[scala-library.jar:na]
    at scala.util.Success$$anonfun$map$1.apply(Try.scala:206) ~[scala-library.jar:na]
    at scala.util.Try$.apply(Try.scala:161) ~[scala-library.jar:na]
    at scala.util.Success.map(Try.scala:206) ~[scala-library.jar:na]

Where the problem is the trailing $ - something like inner class or so ..

My code follows:

  post {
    authenticate(BasicAuth(pifUserPasswordAuthenticator _, realm = "bd pif import api")) {
      user =>
        entity(as[Array[Byte]]) { e =>
          val resp = pifImportService.ask(PifTransactions("storeId","dob",e)).mapTo[akka.actor.Status.Success]
          complete {
            resp
          }
        }
    }
  }

Because of my actor is replying as follows:

  Try(kafkaProducer.send(payload)) match {
    case Success(_) =>
      log.debug(s"$storeId - $dob - sending payload sucessfully sended to kafka")
      sender() ! akka.actor.Status.Success
    case Failure(throwable) =>
      log.debug(s"$storeId - $dob - sending payload attempt failed $throwable")
      sender() ! akka.actor.Status.Failure(throwable)
  }

Am I missing any trick or am I using a wrong name here?

thx

shutty
  • 3,298
  • 16
  • 27
jaksky
  • 3,305
  • 4
  • 35
  • 68
  • In addition to the answer below you need to decide what your answer should be. Then you put the type of the answer into the `mapTo`. – jrudolph Jun 04 '15 at 10:22
  • Could you be more specific? I understand that I order to propagate the error I need to send akka.actor.Status.Failure, but for success I need Success message. I understood the mapTo as if success than mapted else Failure. – jaksky Jun 04 '15 at 12:27
  • It's somewhat explained in the chapter about the ask pattern: http://doc.akka.io/docs/akka/2.3.11/scala/actors.html#Ask__Send-And-Receive-Future – jrudolph Jun 05 '15 at 13:41

1 Answers1

1

sender() ! akka.actor.Status.Success

akka.actor.status.Success is a case class requiring one argument. Looks like that you've replied not with a class instance, but with a partially-applied Success.apply(_) function, which is not you've planned to do, I believe:

case Success(_) =>
  sender() ! akka.actor.Status.Success(storeId)
shutty
  • 3,298
  • 16
  • 27