-
-
Save rtfpessoa/689aba7c420d106bca41 to your computer and use it in GitHub Desktop.
Simple example implementation of routing with akka typed actors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val defaultAkkaTimeout = 60 | |
val defaultNumberOfActors = 10 | |
def getComponentActor[T <: AnyRef](timeout: akka.util.Timeout = Timeout(Duration(defaultAkkaTimeout, SECONDS)))(implicit m: Manifest[T]): T = { | |
val className = this.classCache.get(m.runtimeClass.getName) | |
val actorCount = defaultNumberOfActors | |
val actors = createRouterActors(actorCount,className,timeout) | |
val router = system.actorOf(Props.empty.withRouter(SmallestMailboxRouter.create(actors.toIterable.asJava))) | |
TypedActor(system).typedActorOf(TypedProps(Reflect(system).actorClassFor(className.get)).withTimeout(timeout), router) | |
} | |
def createRouterActors[T <: AnyRef](actorCount:Int, className:Option[String], timeout:akka.util.Timeout)(implicit m: Manifest[T]): Seq[ActorRef] = { | |
(1 to actorCount).map { | |
i => | |
TypedActor.get(system).getActorRefFor(TypedActor.get(system).typedActorOf(TypedProps(Reflect(system).actorClassFor(className.get)).withTimeout(timeout))) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment