Created
October 3, 2012 12:16
-
-
Save patriknw/3826631 to your computer and use it in GitHub Desktop.
Spotlight for ConsistentHashingRouter
This file contains hidden or 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
import akka.routing.ConsistentHashingRouter | |
import akka.routing.ConsistentHashingRouter.ConsistentHashMapping | |
import akka.actor.Actor | |
import akka.pattern.ask | |
case class Entry(key: String, value: String) | |
class Cache extends Actor { | |
var cache = Map.empty[String, String] | |
def receive = { | |
case Entry(key, value) => cache += (key -> value) | |
case key: String => sender ! cache.get(key) | |
} | |
} | |
def hashMapping: ConsistentHashMapping = { | |
case Entry(key, _) => key | |
case s: String => s | |
} | |
val cache = system.actorOf(Props[Cache].withRouter( | |
ConsistentHashingRouter(10, hashMapping = hashMapping)), | |
name = "cache") | |
cache ! Entry("hello", "HELLO") | |
cache ? "hello" onSuccess { case x => println(x) } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment