# Copyright (C) Lightbend Inc. <https://www.lightbend.com>

# Hack to override some of Akka's defaults in Play

# Play's config file loading logic will load this file with a higher
# priority than reference.conf, but a lower priority than application.conf.
# That allows Play to override Akka's reference.conf (which can't happen
# from in Play's own reference.conf), but still allow users to override
# Play's settings in their application.conf.

akka {

  # Play applications should exit when Akka receives a fatal error.
  # If we don't stop the JVM we would have a stale application that
  # can't handle requests since the Akka system is shutdown only.
  jvm-exit-on-fatal-error = true

  actor {
    default-dispatcher = {
      fork-join-executor {
        # Settings this to 1 instead of 3 seems to improve performance.
        parallelism-factor = 1.0

        # @richdougherty: Not sure why this is set below the Akka
        # default.
        parallelism-max = 24

        # Setting this to LIFO changes the fork-join-executor
        # to use a stack discipline for task scheduling. This usually
        # improves throughput at the cost of possibly increasing
        # latency and risking task starvation (which should be rare).
        task-peeking-mode = LIFO
      }
    }
  }

  # Tell akka to use Slf4jLogger and filter
  loglevel = DEBUG
  loggers = ["akka.event.slf4j.Slf4jLogger"]
  logging-filter = "akka.event.slf4j.Slf4jLoggingFilter"

  # Since Akka 2.5.8 there's a setting to disable all Akka-provided JVM shutdown
  # hooks. Play provides the shutdown hooks and runs the appropriate tasks already.
  # Akka's shutdown hooks are therefore not necessary.
  jvm-shutdown-hooks = off

  # CoordinatedShutdown is an extension introduced in Akka 2.5 that will
  # perform registered tasks in the order that is defined by the phases.
  coordinated-shutdown {

    # Terminate the ActorSystem in the last phase actor-system-terminate.
    terminate-actor-system = on

    # Exit the JVM (System.exit(0)) in the last phase actor-system-terminate.
    # This is disabled by default since it is Play's responsibility
    # to exit the JVM.
    exit-jvm = off

  }
}
