/type-actors-routing.scala Secret
Created
December 11, 2013 11:48
Star
You must be signed in to star a gist
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