1

I am writing the setting of my disptacher in addtional conf file and then loading it in application.conf but dispatcher is not working when i am giving the full path where the dispatcher located in my file i am also assuring that it dispatcher exsits or not by using if statarements

val config = ConfigFactory.load()

      // an actor needs an ActorSystem
      val system = ActorSystem("TestActorSystem",config)
      if(system.dispatchers.hasDispatcher("akka.actor.directUserWriteMongoActor-dispatcher"))
      {println("directUserWriteMongoActor-dispatcher exists")}
      else
      {
        println("dispatcher does not exists")
      }

when i run that directUserWriteMongoActor-dispatcher exists printed on console but when i try to attached it via code

 val DirectUserWriteMongoActor = system.actorOf(Props[DirectUserWriteMongoActor].withDispatcher("akka.actor.directUserWriteMongoActor-dispatcher"), name = "directwritemongoactorr")
      DirectUserWriteMongoActor ! DirectUserWriteToMongo(directUser)

log indicate that it is using default-dispatcher rather then my own dispatcher named directUserWriteMongoActor-dispatcher here is my full code

application.conf

include "DirectUserWriteMongoActor" 

akka {
   loggers = ["akka.event.slf4j.Slf4jLogger"]
   loglevel = "DEBUG"

}

DirectUserWriteMongoActor.conf

akka {
   loggers = ["akka.event.slf4j.Slf4jLogger"]
   loglevel = "DEBUG"

  actor{
     loggers = ["akka.event.slf4j.Slf4jLogger"]
   loglevel = "DEBUG"
    ############################### Setting for a Dispatcher #####################################              
    directUserWriteMongoActor-dispatcher {
         type = Dispatcher
    executor = "fork-join-executor"
  fork-join-executor {
    parallelism-min = 2
    parallelism-factor = 2.0
    parallelism-max = 10
  }
  throughput = 10         
                  } #end default-dispatcher 

   }  #end Actor
}  #end Akka        

and here is my code

object TestActor extends App{
 val config = ConfigFactory.load()
 val system = ActorSystem("TestActorSystem",config)

      if(system.dispatchers.hasDispatcher("akka.actor.directUserWriteMongoActor-dispatcher"))
      {println("directUserWriteMongoActor-dispatcher exists")}
      else
      {
        println("directUserWriteMongoActor-dispatcher does not exists")
      }

      val DirectUserWriteMongoActor = system.actorOf(Props[DirectUserWriteMongoActor].withDispatcher("akka.actor.directUserWriteMongoActor-dispatcher"), name = "directwritemongoactorr")
      DirectUserWriteMongoActor ! DirectUserWriteToMongo(directUser)

DirectUserWriteMongoActor.scala

    case class DirectUserWriteToMongo (directuser:DirectUser) 

     class DirectUserWriteMongoActor extends Actor{

      val log = Logging(context.system, this)
     def receive = {
      case DirectUserWriteToMongo(directuser) =>
          log.debug("writing to mogo")

           log.info("message received DirectUserWriteInMongo")
           val directUserStore= new directUserStore
           log.info("going to call store in mongo")
}}

here is the output printed on console

2015-04-27 10:40:01.392 INFO  Slf4jLogger [TestActorSystem-akka.actor.default-dispatcher-2]  -Slf4jLogger started
directUserWriteMongoActor-dispatcher exists
2015-04-27 10:40:02.262 INFO  DirectUserWriteMongoActor [TestActorSystem-akka.actor.default-dispatcher-3] akka://TestActorSystem/user/directwritemongoactorr -message received DirectUserWriteInMongo
2015-04-27 10:40:02.263 INFO  DirectUserWriteMongoActor [TestActorSystem-akka.actor.default-dispatcher-3] akka://TestActorSystem/user/directwritemongoactorr -going to call store in mongo

please help me what is wrong in my code or in my conf setting disptacher was there but it is not working why os that so This should be printed

TestActorSystem-akka.actor.directUserWriteMongoActor-dispatcher-3

instead of this

TestActorSystem-akka.actor.default-dispatcher-3

please help me also i am using akka dispatch and additional conf files for the very first time

swaheed
  • 3,671
  • 10
  • 42
  • 103

1 Answers1

3

You're probably using SimpleLogger. This logger uses the default dispatcher for logging.

There is nothing wrong with you code. Including this: println(context.dispatcher) to your actor receive method will inform you, that he is using the correct directUserWriteMongoActor dispatcher.

On the other hand, if you add println(system.dispatcher) to your App object, you will find out, that outside the actor the default dispatcher is used. This is correct since you specified only the dispatcher of the actor, not the globally used dispatcher.

Quizzie
  • 879
  • 4
  • 15
  • so which logger should be used to display the current dispatcher.?? because based on my logs i figured out that my dispatcher was not working – swaheed Apr 27 '15 at 10:23
  • What about the default Akka logger? Just remove loggers = ["akka.event.slf4j.Slf4jLogger"] from all the places. – Quizzie Apr 27 '15 at 10:27
  • ok its working but i am using loggers = ["akka.event.slf4j.Slf4jLogger"] to write logs to text file when i removed the this loggers line logs stop writing to file what should i do now ? – swaheed Apr 27 '15 at 10:46
  • Then you might want to stay with SLF4J, but choose a different implementation than SimpleLogger, for example logback. Here is a question you might want to read: http://stackoverflow.com/questions/14149798/akka-slf4j-logback-configuration-and-usage – Quizzie Apr 27 '15 at 11:05