0

I am using Akka HTTP for REST support, and I need to use Actors in another part of the server I'm developing. My understanding is that one typically needs to use exactly ONE ActorSystem instance throughout one's application. From the definition of akka.http.scaladsl.Http.apply(), it seems that when I use the Http method, as in the snippet from my code below --

val service: FooRestService = new FooRestService()
Http(). bindAndHandle(service.route, "localhost", 8080)   // something is supplying the imply method w/ implicit ActorSystem ! 

--- somehow the Http object's apply() method is getting supplied with an implicit ActorSystem instance... For easy reference, Http.apply() is defined like this:

package akka.http.scaladsl.Http
        ...
    object Http {
        ...
      def apply()(implicit system: ActorSystem): HttpExt = super.apply(system)

Since I need to stick to exactly one ActorSystem instance, I want to supply the other (non-REST) Actor-based code in my system with the SAME reference as the one that is being supplied to the Http apply() method.

I guessed that my code must be doing a package import of a package with a package object with an implicit ActorSystem, or there must be some other way this implicit is slipping in like a ninja in the dead of night. I've poked around quite a bit, but couldn't figure it out ;^(

Any suggestions much appreciated !

Chris Bedford
  • 2,560
  • 3
  • 28
  • 60

2 Answers2

1

Not sure I fully understood what the problem is but in your every actor you have context: ActorContext. You can obtain ActorSystem from context.system. Thus you don't need to explicitly pass ActorSystem around.

expert
  • 29,290
  • 30
  • 110
  • 214
  • Thank you ! Your hint helped me figure out where the implicit was coming from. I detailed how I used your suggestion to debug my problem in my supplemental answer, below. – Chris Bedford Feb 22 '16 at 00:43
0

Here is how I used @expert's answer (above) to debug where my implicit was coming from. The key thing is to dump out the system variable from the Actor that is getting the implicit.. then look at the name to figure out where the implicit came from. In my case the implicit was coming from my own code (how dumb!). Anyway.. thanks to the answer above my problem is solved.

    val http: HttpExt = Http()
    val sys = http.system
    System.out.println("sys:" + sys);
    http. bindAndHandle(
        service.route, "localhost", injector.getInstance(classOf[Conf]).getInt(PROVISIONER_PORT )
      )
Chris Bedford
  • 2,560
  • 3
  • 28
  • 60