5
votes

My use case is very simple - to exchange few (< 100) messages between two objects, Scala actors were excellent for this purpose (light weight, no complicated life cycle management, start/terminate at any time).

Now I am migrating from Scala Actors to Akka, however I can no longer find those light weight Actors!

With Akka, not only I need to create ActorSystem/Props for Actor creation, but also need to take care of the life cycle of ActorSystem.

Is there an Akka Actor which does not require complicated ActorSystem life cycle management?

2

2 Answers

7
votes

You could create your own default ActorSystem in global singleton object and you don't have to stop it manually - it will stop on program shutdown.

UPD

See the answer by Roland Kuhn for solution how to prevent ActorSystem from keeping the JVM from shutting down.

object global {
  import com.typesafe.config.ConfigFactory
  // From answer by Roland Kuhn
  implicit lazy val actorSystem: ActorSystem =
    ActorSystem("default", ConfigFactory.parseString("akka.daemonic=on"))
}

You could use package object for such purpose.

You could also use ActorDSL for light-weight actor creation syntax:

import ActorDSL._
import global._

val a = actor( new Act {
  become {
      case msg => ...
  }
})
5
votes

Actors are active processing entities, hence they need to shut down when no longer needed. You can make the ActorSystem's lifecycle implicit by setting akka.daemonic=on, which means that it will not keep the JVM from shutting down, but it also means that it is your job to ensure that the actors are done with their work when your main program returns.