Skip to content

Instantly share code, notes, and snippets.

Last active Feb 10, 2017
What would you like to do?
class Router(routeeProps: Props, parallelism: Int) extends Actor with ActorLogging {
private def partitionCampaign(cid: String): Int = {
val rawMod = cid.hashCode % parallelism
rawMod + (if (rawMod < 0) parallelism else 0)
override def receive: Receive = initialized(ListMap.empty[Int, ActorRef])
def initialized(routees: Map[Int, ActorRef]): Receive = {
case cacheCmd: CacheCmd =>
val partition = partitionCampaign(cacheCmd.cid)
val (newRoutees, updated) = routees.updateIfMissing(partition)(context.actorOf(routeeProps))
newRoutees(partition).tell(cacheCmd, sender())
if (updated)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment