Skip to content

Instantly share code, notes, and snippets.

Created December 11, 2013 11:48
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Simple example implementation of routing with akka typed actors
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 =>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment