Merge pull request #1277 from akka/wip-3074-deprecate-actorFor-patriknw
Deprecate actorFor in favor of ActorSelection, see #3074
This commit is contained in:
commit
c77cdeb86b
80 changed files with 1496 additions and 619 deletions
|
|
@ -327,6 +327,37 @@ class ActorDocSpec extends AkkaSpec(Map("akka.loglevel" -> "INFO")) {
|
|||
expectMsg("finished")
|
||||
}
|
||||
|
||||
"using Identify" in {
|
||||
//#identify
|
||||
import akka.actor.{ Actor, Props, Identify, ActorIdentity, Terminated }
|
||||
|
||||
class Follower extends Actor {
|
||||
val identifyId = 1
|
||||
context.actorSelection("/user/another") ! Identify(identifyId)
|
||||
|
||||
def receive = {
|
||||
case ActorIdentity(`identifyId`, Some(ref)) ⇒
|
||||
context.watch(ref)
|
||||
context.become(active(ref))
|
||||
case ActorIdentity(`identifyId`, None) ⇒ context.stop(self)
|
||||
|
||||
}
|
||||
|
||||
def active(another: ActorRef): Actor.Receive = {
|
||||
case Terminated(`another`) ⇒ context.stop(self)
|
||||
}
|
||||
}
|
||||
//#identify
|
||||
|
||||
val a = system.actorOf(Props(new Actor {
|
||||
def receive = Actor.emptyBehavior
|
||||
}))
|
||||
val b = system.actorOf(Props(new Follower))
|
||||
watch(b)
|
||||
system.stop(a)
|
||||
expectMsgType[akka.actor.Terminated].actor must be === b
|
||||
}
|
||||
|
||||
"using pattern gracefulStop" in {
|
||||
val actorRef = system.actorOf(Props[MyActor])
|
||||
//#gracefulStop
|
||||
|
|
@ -386,9 +417,9 @@ class ActorDocSpec extends AkkaSpec(Map("akka.loglevel" -> "INFO")) {
|
|||
lastSender must be === actor
|
||||
actor ! me
|
||||
expectMsg("reply")
|
||||
lastSender must be === system.actorFor("/user")
|
||||
lastSender.path.elements.mkString("/", "/", "") must be === "/user"
|
||||
expectMsg("reply")
|
||||
lastSender must be === system.actorFor("/user")
|
||||
lastSender.path.elements.mkString("/", "/", "") must be === "/user"
|
||||
}
|
||||
|
||||
"using ActorDSL outside of akka.actor package" in {
|
||||
|
|
|
|||
|
|
@ -4,17 +4,15 @@
|
|||
package docs.actor
|
||||
|
||||
import language.postfixOps
|
||||
|
||||
//#imports
|
||||
import scala.concurrent.{ Promise, Future, Await }
|
||||
import scala.concurrent.duration._
|
||||
import akka.actor.{ ActorContext, TypedActor, TypedProps }
|
||||
|
||||
//#imports
|
||||
|
||||
import org.scalatest.{ BeforeAndAfterAll, WordSpec }
|
||||
import org.scalatest.matchers.MustMatchers
|
||||
import akka.testkit._
|
||||
//#typed-actor-impl
|
||||
import java.lang.String.{ valueOf ⇒ println } //Mr funny man avoids printing to stdout AND keeping docs alright
|
||||
import akka.actor.ActorRef
|
||||
|
||||
//#typed-actor-iface
|
||||
trait Squarer {
|
||||
|
|
@ -46,8 +44,6 @@ class SquarerImpl(val name: String) extends Squarer {
|
|||
def squareNow(i: Int): Int = i * i
|
||||
//#typed-actor-impl-methods
|
||||
}
|
||||
//#typed-actor-impl
|
||||
import java.lang.String.{ valueOf ⇒ println } //Mr funny man avoids printing to stdout AND keeping docs alright
|
||||
//#typed-actor-supercharge
|
||||
trait Foo {
|
||||
def doFoo(times: Int): Unit = println("doFoo(" + times + ")")
|
||||
|
|
@ -145,12 +141,13 @@ class TypedActorDocSpec extends AkkaSpec(Map("akka.loglevel" -> "INFO")) {
|
|||
}
|
||||
|
||||
"proxy any ActorRef" in {
|
||||
val actorRefToRemoteActor: ActorRef = system.deadLetters
|
||||
//#typed-actor-remote
|
||||
val typedActor: Foo with Bar =
|
||||
TypedActor(system).
|
||||
typedActorOf(
|
||||
TypedProps[FooBar],
|
||||
system.actorFor("akka://SomeSystem@somehost:2552/user/some/foobar"))
|
||||
actorRefToRemoteActor)
|
||||
//Use "typedActor" as a FooBar
|
||||
//#typed-actor-remote
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,13 +10,15 @@ import akka.routing.RoundRobinRouter
|
|||
import akka.testkit._
|
||||
import com.typesafe.config.ConfigFactory
|
||||
import scala.concurrent.duration._
|
||||
import akka.actor.ActorPath
|
||||
|
||||
object RouterViaProgramDocSpec {
|
||||
case class Message1(nbr: Int)
|
||||
case class Reply1(name: String, m: Message1)
|
||||
|
||||
class ExampleActor1 extends Actor {
|
||||
def receive = {
|
||||
case m @ Message1(nbr) ⇒ sender ! ((self, m))
|
||||
case m @ Message1(nbr) ⇒ sender ! Reply1(self.path.name, m)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -43,9 +45,9 @@ class RouterViaProgramDocSpec extends AkkaSpec with ImplicitSender {
|
|||
1 to 6 foreach { i ⇒ router ! Message1(i) }
|
||||
val received = receiveN(6, 5.seconds.dilated)
|
||||
1 to 6 foreach { i ⇒
|
||||
val expectedActor = system.actorFor(routees((i - 1) % routees.length))
|
||||
val expectedName = (routees((i - 1) % routees.length)).split("/").last
|
||||
val expectedMsg = Message1(i)
|
||||
received must contain[AnyRef]((expectedActor, expectedMsg))
|
||||
received must contain[AnyRef](Reply1(expectedName, expectedMsg))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -157,7 +157,7 @@ package docs.serialization {
|
|||
|
||||
"demonstrate serialization of ActorRefs" in {
|
||||
val theActorRef: ActorRef = system.deadLetters
|
||||
val theActorSystem: ActorSystem = system
|
||||
val extendedSystem: ExtendedActorSystem = system.asInstanceOf[ExtendedActorSystem]
|
||||
|
||||
//#actorref-serializer
|
||||
// Serialize
|
||||
|
|
@ -168,7 +168,7 @@ package docs.serialization {
|
|||
|
||||
// Deserialize
|
||||
// (beneath fromBinary)
|
||||
val deserializedActorRef = theActorSystem actorFor identifier
|
||||
val deserializedActorRef = extendedSystem.provider.resolveActorRef(identifier)
|
||||
// Then just use the ActorRef
|
||||
//#actorref-serializer
|
||||
|
||||
|
|
@ -182,7 +182,7 @@ package docs.serialization {
|
|||
}
|
||||
|
||||
def serializeTo(ref: ActorRef, remote: Address): String =
|
||||
ref.path.toSerializationFormatWithAddress(ExternalAddress(theActorSystem).addressFor(remote))
|
||||
ref.path.toSerializationFormatWithAddress(ExternalAddress(extendedSystem).addressFor(remote))
|
||||
//#external-address
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -208,10 +208,13 @@ class TestkitDocSpec extends AkkaSpec with DefaultTimeout with ImplicitSender {
|
|||
|
||||
"demonstrate probe watch" in {
|
||||
import akka.testkit.TestProbe
|
||||
val target = system.actorFor("/buh")
|
||||
val target = system.actorOf(Props(new Actor {
|
||||
def receive = Actor.emptyBehavior
|
||||
}))
|
||||
//#test-probe-watch
|
||||
val probe = TestProbe()
|
||||
probe watch target
|
||||
target ! PoisonPill
|
||||
probe.expectMsgType[Terminated].actor must be(target)
|
||||
//#test-probe-watch
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue