Akkit is a collection of usefull general-purpose Akka actors and modules.
Akkit is published to Sonatype OSSRH, so all you have to do is add the following
dependencies to your build.sbt:
libraryDependencies ++= Seq(
"com.ataraxer" %% "zooowner-core" % "0.1.0",
"com.ataraxer" %% "zooowner-macro" % "0.1.0")@safeActor macro annotation adds following entities to actor's companion object:
propsmethod -- which will accept the same arguments as annotated actor and return an instance ofSafeProps[T], whereTis a type of annotated actor;applymethod -- which will accept the same arguments as annotated actor and implicitActorRefFactoryand create a new actor of that type, returning aSafeRef[T], whereTis a type of annotated actor;Reftype alias -- equivalent toSafeRef[T], whereTis a type of annotated actor;<actor class name>Reftype alias -- as an alias toRef.
This allows you to dramatically decrease boilerplate while defining actors, while making sure that you do not enclose over any unwanted state and passing references to correct actors.
import akkit._
import akka.actor._
@safeActor
class Printer(prefix: String) extends Actor {
def receive = { case msg => println(prefix -> msg) }
}
@safeActor
class Pinger(printer: Printer.Ref) extends Actor {
def receive = { case "ping" => printer ! "pong" }
}
object Demo extends App {
implicit val system = ActorSystem("demo-system")
val printer = Printer(">>>")
val pinger = Pinger(printer)
pinger ! "ping" // results in "ping" printed to stdout
}