diff --git a/akka-docs/java/routing.rst b/akka-docs/java/routing.rst index 0096c9e3e8..dad68ecf30 100644 --- a/akka-docs/java/routing.rst +++ b/akka-docs/java/routing.rst @@ -306,7 +306,8 @@ Code example: FIXME Java example of consistent routing In the above example you see that the ``Get`` message implements ``ConsistentHashable`` itself, -while the ``Entry`` message is wrapped in a ``ConsistentHashableEnvelope``. +while the ``Entry`` message is wrapped in a ``ConsistentHashableEnvelope``. The ``Evict`` +message is handled by the ``withConsistentHashMapping``. This is an example of how to define a consistent-hashing router in configuration: diff --git a/akka-docs/scala/code/docs/routing/ConsistentHashingRouterDocSpec.scala b/akka-docs/scala/code/docs/routing/ConsistentHashingRouterDocSpec.scala index 42af05c049..89a329c743 100644 --- a/akka-docs/scala/code/docs/routing/ConsistentHashingRouterDocSpec.scala +++ b/akka-docs/scala/code/docs/routing/ConsistentHashingRouterDocSpec.scala @@ -19,7 +19,7 @@ object ConsistentHashingRouterDocSpec { def receive = { case Entry(key, value) ⇒ cache += (key -> value) case Get(key) ⇒ sender ! cache.get(key) - case Evict(key) => cache -= key + case Evict(key) ⇒ cache -= key } } @@ -30,10 +30,6 @@ object ConsistentHashingRouterDocSpec { } case class Entry(key: String, value: String) - case class EntryEnvelope(entry: Entry) extends ConsistentHashableEnvelope { - override def consistentHashKey: Any = entry.key - override def message: Any = entry - } //#cache-actor } @@ -47,16 +43,31 @@ class ConsistentHashingRouterDocSpec extends AkkaSpec with ImplicitSender { //#consistent-hashing-router import akka.actor.Props import akka.routing.ConsistentHashingRouter + import akka.routing.ConsistentHashingRouter.ConsistentHashRoute + import akka.routing.ConsistentHashingRouter.ConsistentHashableEnvelope - val cache = system.actorOf(Props[Cache].withRouter(ConsistentHashingRouter(10)), "cache") + def consistentHashRoute: ConsistentHashingRouter.ConsistentHashRoute = { + case Evict(key) ⇒ key + } - cache ! EntryEnvelope(Entry("hello", "HELLO")) - cache ! EntryEnvelope(Entry("hi", "HI")) + val cache = system.actorOf(Props[Cache].withRouter(ConsistentHashingRouter(10, + consistentHashRoute = consistentHashRoute)), name = "cache") + + cache ! ConsistentHashableEnvelope( + message = Entry("hello", "HELLO"), consistentHashKey = "hello") + cache ! ConsistentHashableEnvelope( + message = Entry("hi", "HI"), consistentHashKey = "hi") cache ! Get("hello") - cache ! Get("hi") expectMsg(Some("HELLO")) + + cache ! Get("hi") expectMsg(Some("HI")) + + cache ! Evict("hi") + cache ! Get("hi") + expectMsg(None) + //#consistent-hashing-router } diff --git a/akka-docs/scala/routing.rst b/akka-docs/scala/routing.rst index 0cffa3c1a7..e10a353988 100644 --- a/akka-docs/scala/routing.rst +++ b/akka-docs/scala/routing.rst @@ -313,7 +313,8 @@ Code example: .. includecode:: code/docs/routing/ConsistentHashingRouterDocSpec.scala#consistent-hashing-router In the above example you see that the ``Get`` message implements ``ConsistentHashable`` itself, -while the ``Entry`` message is wrapped in a ``ConsistentHashableEnvelope``. +while the ``Entry`` message is wrapped in a ``ConsistentHashableEnvelope``. The ``Evict`` +message is handled by the ``consistentHashRoute`` partial function. This is an example of how to define a consistent-hashing router in configuration: