Useful utils for Akka Actors
Actor which will pass message to child actor defined for route. If no actors found, it may create a new one.
Broadcast message to all child actors
Actor which run a job at a certain interval
Converts duration to string
import com.github.t3hnar.akkax.DurationToString
DurationToString(Duration(60, TimeUnit.SECONDS)) == "1 minute"
DurationToString(Duration(60, TimeUnit.MINUTES)) == "1 hour"
DurationToString(Duration(180, TimeUnit.MINUTES)) == "3 hours"
Mix this trait to enable on restart notification for actor.
import com.github.t3hnar.akkax.{NotifyParentOnRestart, Restarted}
class ChildActor extends Actor with NotifyParentOnRestart {
def receive = { case _ => }
}
class ParentActor extends Actor {
val child = context.actorOf(Props(new ChildActor))
def receive = {
case Restarted(`child`) => // your code for handling restart
}
}
Trait IgnoreIfBusy
will allow your actor to ignore all messages while it busy with running heavy call
import com.github.t3hnar.akkax.IgnoreIfBusy
class IgnoreIfBusyExample extends Actor with ActorLogging with IgnoreIfBusy {
def receive = receiveRun
def run(data: Option[Any]) {
// heavy call
}
}
- Maven:
<dependency>
<groupId>com.github.t3hnar</groupId>
<artifactId>akkax_2.11</artifactId>
<version>2.3</version>
</dependency>
- Sbt
libraryDependencies += "com.github.t3hnar" %% "akkax" % "2.3"