The idea is to filter the sources, replacing @<var>@ occurrences with the mapping for <var> (which is currently hard-coded). @@ -> @. In order to make this work, I had to move the doc sources one directory down (into akka-docs/rst) so that the filtered result could be in a sibling directory so that relative links (to _sphinx plugins or real code) would continue to work. While I was at it I also changed it so that WARNINGs and ERRORs are not swallowed into the debug dump anymore but printed at [warn] level (minimum). One piece of fallout is that the (online) html build is now run after the normal one, not in parallel.
73 lines
1.8 KiB
Scala
73 lines
1.8 KiB
Scala
/**
|
|
* Copyright (C) 2009-2012 Typesafe Inc. <http://www.typesafe.com>
|
|
*/
|
|
package docs.routing
|
|
|
|
import akka.testkit.AkkaSpec
|
|
import akka.testkit.ImplicitSender
|
|
|
|
object ConsistentHashingRouterDocSpec {
|
|
|
|
//#cache-actor
|
|
import akka.actor.Actor
|
|
import akka.routing.ConsistentHashingRouter.ConsistentHashable
|
|
|
|
class Cache extends Actor {
|
|
var cache = Map.empty[String, String]
|
|
|
|
def receive = {
|
|
case Entry(key, value) ⇒ cache += (key -> value)
|
|
case Get(key) ⇒ sender ! cache.get(key)
|
|
case Evict(key) ⇒ cache -= key
|
|
}
|
|
}
|
|
|
|
case class Evict(key: String)
|
|
|
|
case class Get(key: String) extends ConsistentHashable {
|
|
override def consistentHashKey: Any = key
|
|
}
|
|
|
|
case class Entry(key: String, value: String)
|
|
//#cache-actor
|
|
|
|
}
|
|
|
|
class ConsistentHashingRouterDocSpec extends AkkaSpec with ImplicitSender {
|
|
|
|
import ConsistentHashingRouterDocSpec._
|
|
|
|
"demonstrate usage of ConsistentHashableRouter" in {
|
|
|
|
//#consistent-hashing-router
|
|
import akka.actor.Props
|
|
import akka.routing.ConsistentHashingRouter
|
|
import akka.routing.ConsistentHashingRouter.ConsistentHashMapping
|
|
import akka.routing.ConsistentHashingRouter.ConsistentHashableEnvelope
|
|
|
|
def hashMapping: ConsistentHashMapping = {
|
|
case Evict(key) ⇒ key
|
|
}
|
|
|
|
val cache = system.actorOf(Props[Cache].withRouter(ConsistentHashingRouter(10,
|
|
hashMapping = hashMapping)), name = "cache")
|
|
|
|
cache ! ConsistentHashableEnvelope(
|
|
message = Entry("hello", "HELLO"), hashKey = "hello")
|
|
cache ! ConsistentHashableEnvelope(
|
|
message = Entry("hi", "HI"), hashKey = "hi")
|
|
|
|
cache ! Get("hello")
|
|
expectMsg(Some("HELLO"))
|
|
|
|
cache ! Get("hi")
|
|
expectMsg(Some("HI"))
|
|
|
|
cache ! Evict("hi")
|
|
cache ! Get("hi")
|
|
expectMsg(None)
|
|
|
|
//#consistent-hashing-router
|
|
}
|
|
|
|
}
|