=cdd #17778 Convert samples to java

This commit is contained in:
Patrik Nordwall 2015-07-01 09:46:58 +02:00
parent 7bfc56f3f0
commit 94a61c7eb2
32 changed files with 2220 additions and 67 deletions

View file

@ -101,6 +101,8 @@ class ReplicatedMetrics(measureInterval: FiniteDuration, cleanupInterval: Finite
case MemberRemoved(m, _)
nodesInCluster -= nodeKey(m.address)
if (m.address == cluster.selfAddress)
context.stop(self)
case Cleanup
def cleanupRemoved(data: LWWMap[Long]): LWWMap[Long] =

View file

@ -35,7 +35,7 @@ object ServiceRegistry {
*/
final case class Bindings(name: String, services: Set[ActorRef])
/**
* Published to `System.eventStream` when services are changed.
* Published to `ActorSystem.eventStream` when services are changed.
*/
final case class BindingChanged(name: String, services: Set[ActorRef])
@ -78,8 +78,8 @@ class ServiceRegistry extends Actor with ActorLogging {
// add the service
replicator ! Update(dKey, ORSet(), WriteLocal)(_ + service)
case Lookup(key)
sender() ! Bindings(key, services.getOrElse(key, Set.empty))
case Lookup(name)
sender() ! Bindings(name, services.getOrElse(name, Set.empty))
case c @ Changed(AllServicesKey)
val newKeys = c.get(AllServicesKey).elements

View file

@ -69,15 +69,16 @@ class ShoppingCart(userId: String) extends Actor {
cart updateCart(cart, item)
}
replicator ! update
case GetFailure(DataKey, Some(AddItem(item)))
// ReadMajority of Update failed, fall back to best effort local value
replicator ! Update(DataKey, LWWMap.empty[LineItem], writeMajority, None) {
cart updateCart(cart, item)
}
}
//#add-item
def updateCart(data: LWWMap[LineItem], item: LineItem): LWWMap[LineItem] =
data.get(item.productId) match {
case Some(LineItem(_, _, existingQuantity))
data + (item.productId -> item.copy(quantity = existingQuantity + item.quantity))
case None data + (item.productId -> item)
}
//#remove-item
def receiveRemoveItem: Receive = {
case cmd @ RemoveItem(productId)
@ -107,11 +108,4 @@ class ShoppingCart(userId: String) extends Actor {
case e: UpdateFailure[_] throw new IllegalStateException("Unexpected failure: " + e)
}
def updateCart(data: LWWMap[LineItem], item: LineItem): LWWMap[LineItem] =
data.get(item.productId) match {
case Some(LineItem(_, _, existingQuantity))
data + (item.productId -> item.copy(quantity = existingQuantity + item.quantity))
case None data + (item.productId -> item)
}
}

View file

@ -61,14 +61,14 @@ class ReplicatedMetricsSpec extends MultiNodeSpec(ReplicatedMetricsSpec) with ST
val probe = TestProbe()
system.eventStream.subscribe(probe.ref, classOf[UsedHeap])
awaitAssert {
probe.expectMsgType[UsedHeap].percentPerNode.size should be(3)
probe.expectMsgType[UsedHeap](1.second).percentPerNode.size should be(3)
}
probe.expectMsgType[UsedHeap].percentPerNode.size should be(3)
probe.expectMsgType[UsedHeap].percentPerNode.size should be(3)
enterBarrier("after-2")
}
"cleanup removed node" in within(15.seconds) {
"cleanup removed node" in within(25.seconds) {
val node3Address = node(node3).address
runOn(node1) {
cluster.leave(node3Address)
@ -77,7 +77,7 @@ class ReplicatedMetricsSpec extends MultiNodeSpec(ReplicatedMetricsSpec) with ST
val probe = TestProbe()
system.eventStream.subscribe(probe.ref, classOf[UsedHeap])
awaitAssert {
probe.expectMsgType[UsedHeap].percentPerNode.size should be(2)
probe.expectMsgType[UsedHeap](1.second).percentPerNode.size should be(2)
}
probe.expectMsgType[UsedHeap].percentPerNode should not contain (
nodeKey(node3Address))

View file

@ -45,6 +45,12 @@ It is eventually consistent and geared toward providing high read and write avai
out-of-date value.
</p>
<p>
Note that there are some
<a href="http://doc.akka.io/docs/akka/2.4-SNAPSHOT/scala/distributed-data.html#Limitations" target="_blank">Limitations</a>
that you should be aware of. For example, Akka Distributed Data is not intended for <i>Big Data</i>.
</p>
</div>
<div>
@ -127,6 +133,7 @@ The multi-node test for the <code>VotingService</code> can be found in
Read the
<a href="http://doc.akka.io/docs/akka/2.4-SNAPSHOT/scala/distributed-data.html#Using_the_Replicator" target="_blank">Using the Replicator</a>
documentation for more details of how to use <code>Get</code>, <code>Update</code>, and <code>Subscribe</code>.
</p>
</div>