Skip to content

Instantly share code, notes, and snippets.

@ubourdon
Created January 10, 2014 02:04
Show Gist options
  • Save ubourdon/8345778 to your computer and use it in GitHub Desktop.
Save ubourdon/8345778 to your computer and use it in GitHub Desktop.
Problem with Akka Actors that is when you use it, you must use ActorRef Scalatype. It means Akka Actors were not typed. We can "solve" this problem using simpla "companion class" api.
class AClassUsingActor(myClass: MyClass) {
def useActor = myClass.ref ! message
}
object CreateActorClass {
val system = ActorSystem("system")
val classUsingActor = new AClassUsingActor(new MyClass(system))
classUsingActor.useActor
}
import akka.actor._
// the class for use specific type instead of ActorRef
class MyClass(val ref: ActorRef) {
def this(system: ActorSystem) = this(system.actorOf(MyClass.props, MyClass.name))
}
// companion object of Actor for define name & props
object MyClass {
val name = "myClass"
def props = Props[MyClassActor]
}
// the Actor
class MyClassActor extends Actor with ActorLogging {
def receive = ???
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment