+doc #3656 correcting the TypedActor documentation
This commit is contained in:
parent
577aed548a
commit
4769a44875
3 changed files with 18 additions and 32 deletions
|
|
@ -364,24 +364,23 @@ class DistributedPubSubMediatorSpec extends MultiNodeSpec(DistributedPubSubMedia
|
|||
// this test is configured with max-delta-elements = 500
|
||||
val many = 1010
|
||||
runOn(first) {
|
||||
for (i <- 0 until many)
|
||||
for (i ← 0 until many)
|
||||
mediator ! Put(createChatUser("u" + (1000 + i)))
|
||||
|
||||
mediator ! Status(versions = Map.empty)
|
||||
val deltaBuckets1 = expectMsgType[Delta].buckets
|
||||
deltaBuckets1.map(_.content.size).sum must be(500)
|
||||
|
||||
mediator ! Status(versions = deltaBuckets1.map(b => b.owner -> b.version).toMap)
|
||||
mediator ! Status(versions = deltaBuckets1.map(b ⇒ b.owner -> b.version).toMap)
|
||||
val deltaBuckets2 = expectMsgType[Delta].buckets
|
||||
deltaBuckets1.map(_.content.size).sum must be(500)
|
||||
|
||||
mediator ! Status(versions = deltaBuckets2.map(b => b.owner -> b.version).toMap)
|
||||
mediator ! Status(versions = deltaBuckets2.map(b ⇒ b.owner -> b.version).toMap)
|
||||
val deltaBuckets3 = expectMsgType[Delta].buckets
|
||||
|
||||
deltaBuckets3.map(_.content.size).sum must be(7 + 6 + 2 + many - 500 - 500)
|
||||
}
|
||||
|
||||
|
||||
enterBarrier("verified-delta-with-many")
|
||||
within(10.seconds) {
|
||||
awaitCount(13 + many)
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import akka.actor.{ ActorContext, TypedActor, TypedProps }
|
|||
import org.scalatest.{ BeforeAndAfterAll, WordSpec }
|
||||
import org.scalatest.matchers.MustMatchers
|
||||
import akka.testkit._
|
||||
//#typed-actor-impl
|
||||
|
||||
//Mr funny man avoids printing to stdout AND keeping docs alright
|
||||
import java.lang.String.{ valueOf ⇒ println }
|
||||
import akka.actor.ActorRef
|
||||
|
|
@ -34,26 +34,24 @@ class SquarerImpl(val name: String) extends Squarer {
|
|||
|
||||
def this() = this("default")
|
||||
//#typed-actor-impl-methods
|
||||
import TypedActor.dispatcher //So we can create Promises
|
||||
|
||||
def squareDontCare(i: Int): Unit = i * i //Nobody cares :(
|
||||
|
||||
def square(i: Int): Future[Int] = Promise.successful(i * i).future
|
||||
def square(i: Int): Future[Int] = Future.successful(i * i)
|
||||
|
||||
def squareNowPlease(i: Int): Option[Int] = Some(i * i)
|
||||
|
||||
def squareNow(i: Int): Int = i * i
|
||||
//#typed-actor-impl-methods
|
||||
}
|
||||
//#typed-actor-impl
|
||||
//#typed-actor-supercharge
|
||||
trait Foo {
|
||||
def doFoo(times: Int): Unit = println("doFoo(" + times + ")")
|
||||
}
|
||||
|
||||
trait Bar {
|
||||
import TypedActor.dispatcher //So we have an implicit dispatcher for our Promise
|
||||
def doBar(str: String): Future[String] =
|
||||
Promise.successful(str.toUpperCase).future
|
||||
Future.successful(str.toUpperCase)
|
||||
}
|
||||
|
||||
class FooBar extends Foo with Bar
|
||||
|
|
|
|||
|
|
@ -60,13 +60,14 @@ Our example interface:
|
|||
|
||||
.. includecode:: code/docs/actor/TypedActorDocSpec.scala
|
||||
:include: imports,typed-actor-iface
|
||||
:exclude: typed-actor-iface-methods
|
||||
|
||||
Our example implementation of that interface:
|
||||
Alright, now we've got some methods we can call, but we need to implement those in SquarerImpl.
|
||||
|
||||
.. includecode:: code/docs/actor/TypedActorDocSpec.scala
|
||||
:include: imports,typed-actor-impl
|
||||
:exclude: typed-actor-impl-methods
|
||||
|
||||
Excellent, now we have an interface and an implementation of that interface,
|
||||
and we know how to create a Typed Actor from that, so let's look at calling these methods.
|
||||
|
||||
The most trivial way of creating a Typed Actor instance
|
||||
of our Squarer:
|
||||
|
|
@ -81,18 +82,6 @@ If you need to call a specific constructor you do it like this:
|
|||
:include: typed-actor-create2
|
||||
|
||||
Since you supply a Props, you can specify which dispatcher to use, what the default timeout should be used and more.
|
||||
Now, our Squarer doesn't have any methods, so we'd better add those.
|
||||
|
||||
.. includecode:: code/docs/actor/TypedActorDocSpec.scala
|
||||
:include: imports,typed-actor-iface
|
||||
|
||||
Alright, now we've got some methods we can call, but we need to implement those in SquarerImpl.
|
||||
|
||||
.. includecode:: code/docs/actor/TypedActorDocSpec.scala
|
||||
:include: imports,typed-actor-impl
|
||||
|
||||
Excellent, now we have an interface and an implementation of that interface,
|
||||
and we know how to create a Typed Actor from that, so let's look at calling these methods.
|
||||
|
||||
Method dispatch semantics
|
||||
-------------------------
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue