Trying to configure ActorSystems

46 views
Skip to first unread message

Ian Nowland

unread,
Jan 28, 2016, 7:42:33 PM1/28/16
to Akka User List
Hello,

I'm trying to configure an ActorSystem, but no matter what I do, seem to be getting the default dispatcher. Here's what I've got going on:

val customConf = ConfigFactory.parseString(
  """
    |akka {
    |
    |  actor{
    |
    |    /function-scheduler {
    |      dispatcher = function-scheduler-dispatcher
    |    }
    |
    |    function-scheduler-dispatcher {
    |      type = Dispatcher
    |      executor = "fork-join-executor"
    |      fork-join-executor {
    |        # Min number of threads
    |        parallelism-min = 2
    |        # available processors * factor
    |        parallelism-factor = 4.0
    |        # Max number of threads
    |        parallelism-max = 32
    |      }
    |    }
    |  }
    |
    |}
  """.stripMargin)

val system:ActorSystem = ActorSystem("function-scheduler",ConfigFactory.load(customConf))
import system.dispatcher

def scheduleOnce(delayTime: Long)(f:() => Unit):Unit = {
  import scala.language.postfixOps
  system.scheduler.scheduleOnce(delayTime milliseconds) {
    f()
  }
}

As you can see, what I'm trying to do is use a scheduler to be able to schedule arbitrary tasks. The problem is that everything I've tried in that customConf still results in system using the akka.actor.default-dispatcher. I definitely don't understand how the configuration stuff works, but my theory is that I'm configuring the dispatcher that would be used for created ActorRefs if I was to call something like:

val myActor = system.actorOf(Props[MyActor].withDispatcher("function-scheduler-dispatcher"), "myactor1")

rather than configuring the system itself.

Patrik Nordwall

unread,
Jan 29, 2016, 12:34:28 PM1/29/16
to Akka User List
Remove the import system.dispatcher and you will see that you need to provide an ExecutionContext, which you can lookup from the config, via the system.dispatchers.lookup (I think)

--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ: http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+...@googlegroups.com.
To post to this group, send email to akka...@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Ian Nowland

unread,
Jan 29, 2016, 12:39:45 PM1/29/16
to Akka User List
So, I've tried replacing the

import system.dispatcher

with

implicit val executionContext = system.dispatchers.lookup("akka.actor.habari-function-scheduler-dispatcher")

but I'm still getting the system.dispatcher as the akka.default

Johan Andrén

unread,
Feb 1, 2016, 10:52:19 AM2/1/16
to Akka User List
I think the namespaces in your config are incorrect, deployment config for an actor should 
be under "akka.actor.deployment" (described in the docs here: 
and the dispatcher you refer to from your actor is actually under akka.actor.function-scheduler-dispatcher
in your sample but you then refer to it only by the last name in the path "function-scheduler-dispatcher". 

I think what you intend would be:

akka.actor.deployment {
  /function-scheduler {
    dispatcher = function-scheduler-dispatcher
  }
}
 
function-scheduler-dispatcher {
   ... dispatcher config ...
}


I hope this helps
--
Johan Andrén
Typesafe -  Reactive apps on the JVM
Twitter: @apnylle

Ian Nowland

unread,
Feb 1, 2016, 11:01:41 AM2/1/16
to akka...@googlegroups.com
Thanks, that helps.

--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ: http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to a topic in the Google Groups "Akka User List" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/akka-user/66SsNPb_ANo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to akka-user+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages