#3077 - Deprecating ActorRef.isTerminated
This commit is contained in:
parent
718e2d115c
commit
7b263365aa
12 changed files with 61 additions and 64 deletions
|
|
@ -348,23 +348,23 @@ class SerializationCompatibilitySpec extends AkkaSpec(SerializationTests.mostlyR
|
||||||
verify(Terminate(), "aced00057372000c7363616c612e5475706c6532bc7daadf46211a990200024c00025f317400124c6a6176612f6c616e672f4f626a6563743b4c00025f3271007e000178707372001e616b6b612e64697370617463682e7379736d73672e5465726d696e61746509d66ca68318700f02000078707671007e0003")
|
verify(Terminate(), "aced00057372000c7363616c612e5475706c6532bc7daadf46211a990200024c00025f317400124c6a6176612f6c616e672f4f626a6563743b4c00025f3271007e000178707372001e616b6b612e64697370617463682e7379736d73672e5465726d696e61746509d66ca68318700f02000078707671007e0003")
|
||||||
}
|
}
|
||||||
"be preserved for the Supervise SystemMessage" in {
|
"be preserved for the Supervise SystemMessage" in {
|
||||||
verify(Supervise(FakeActorRef("child"), true), "aced00057372000c7363616c612e5475706c6532bc7daadf46211a990200024c00025f317400124c6a6176612f6c616e672f4f626a6563743b4c00025f3271007e000178707372001e616b6b612e64697370617463682e7379736d73672e5375706572766973652d0b363f56ab5feb0200025a00056173796e634c00056368696c647400154c616b6b612f6163746f722f4163746f725265663b7870017372001f616b6b612e73657269616c697a6174696f6e2e46616b654163746f7252656600000000000000010200014c00046e616d657400124c6a6176612f6c616e672f537472696e673b7872001b616b6b612e6163746f722e496e7465726e616c4163746f72526566db6eaed9e69a356302000078720013616b6b612e6163746f722e4163746f72526566c3585dde655f469402000078707400056368696c647671007e0003")
|
verify(Supervise(FakeActorRef("child"), true), "aced00057372000c7363616c612e5475706c6532bc7daadf46211a990200024c00025f317400124c6a6176612f6c616e672f4f626a6563743b4c00025f3271007e000178707372001e616b6b612e64697370617463682e7379736d73672e5375706572766973652d0b363f56ab5feb0200025a00056173796e634c00056368696c647400154c616b6b612f6163746f722f4163746f725265663b7870017372001f616b6b612e73657269616c697a6174696f6e2e46616b654163746f7252656600000000000000010200014c00046e616d657400124c6a6176612f6c616e672f537472696e673b7872001b616b6b612e6163746f722e496e7465726e616c4163746f72526566869e6c3669e60e5f02000078720013616b6b612e6163746f722e4163746f72526566c3585dde655f469402000078707400056368696c647671007e0003")
|
||||||
}
|
}
|
||||||
"be preserved for the ChildTerminated SystemMessage" in {
|
"be preserved for the ChildTerminated SystemMessage" in {
|
||||||
verify(ChildTerminated(FakeActorRef("child")), "aced00057372000c7363616c612e5475706c6532bc7daadf46211a990200024c00025f317400124c6a6176612f6c616e672f4f626a6563743b4c00025f3271007e0001787073720024616b6b612e64697370617463682e7379736d73672e4368696c645465726d696e617465644c84222437ed5db40200014c00056368696c647400154c616b6b612f6163746f722f4163746f725265663b78707372001f616b6b612e73657269616c697a6174696f6e2e46616b654163746f7252656600000000000000010200014c00046e616d657400124c6a6176612f6c616e672f537472696e673b7872001b616b6b612e6163746f722e496e7465726e616c4163746f72526566db6eaed9e69a356302000078720013616b6b612e6163746f722e4163746f72526566c3585dde655f469402000078707400056368696c647671007e0003")
|
verify(ChildTerminated(FakeActorRef("child")), "aced00057372000c7363616c612e5475706c6532bc7daadf46211a990200024c00025f317400124c6a6176612f6c616e672f4f626a6563743b4c00025f3271007e0001787073720024616b6b612e64697370617463682e7379736d73672e4368696c645465726d696e617465644c84222437ed5db40200014c00056368696c647400154c616b6b612f6163746f722f4163746f725265663b78707372001f616b6b612e73657269616c697a6174696f6e2e46616b654163746f7252656600000000000000010200014c00046e616d657400124c6a6176612f6c616e672f537472696e673b7872001b616b6b612e6163746f722e496e7465726e616c4163746f72526566869e6c3669e60e5f02000078720013616b6b612e6163746f722e4163746f72526566c3585dde655f469402000078707400056368696c647671007e0003")
|
||||||
}
|
}
|
||||||
"be preserved for the Watch SystemMessage" in {
|
"be preserved for the Watch SystemMessage" in {
|
||||||
verify(Watch(FakeActorRef("watchee"), FakeActorRef("watcher")), "aced00057372000c7363616c612e5475706c6532bc7daadf46211a990200024c00025f317400124c6a6176612f6c616e672f4f626a6563743b4c00025f3271007e000178707372001a616b6b612e64697370617463682e7379736d73672e57617463682e1e65bc74394fc40200024c0007776174636865657400154c616b6b612f6163746f722f4163746f725265663b4c00077761746368657271007e000478707372001f616b6b612e73657269616c697a6174696f6e2e46616b654163746f7252656600000000000000010200014c00046e616d657400124c6a6176612f6c616e672f537472696e673b7872001b616b6b612e6163746f722e496e7465726e616c4163746f72526566db6eaed9e69a356302000078720013616b6b612e6163746f722e4163746f72526566c3585dde655f46940200007870740007776174636865657371007e0006740007776174636865727671007e0003")
|
verify(Watch(FakeActorRef("watchee"), FakeActorRef("watcher")), "aced00057372000c7363616c612e5475706c6532bc7daadf46211a990200024c00025f317400124c6a6176612f6c616e672f4f626a6563743b4c00025f3271007e000178707372001a616b6b612e64697370617463682e7379736d73672e57617463682e1e65bc74394fc40200024c0007776174636865657400154c616b6b612f6163746f722f4163746f725265663b4c00077761746368657271007e000478707372001f616b6b612e73657269616c697a6174696f6e2e46616b654163746f7252656600000000000000010200014c00046e616d657400124c6a6176612f6c616e672f537472696e673b7872001b616b6b612e6163746f722e496e7465726e616c4163746f72526566869e6c3669e60e5f02000078720013616b6b612e6163746f722e4163746f72526566c3585dde655f46940200007870740007776174636865657371007e0006740007776174636865727671007e0003")
|
||||||
}
|
}
|
||||||
"be preserved for the Unwatch SystemMessage" in {
|
"be preserved for the Unwatch SystemMessage" in {
|
||||||
verify(Unwatch(FakeActorRef("watchee"), FakeActorRef("watcher")), "aced00057372000c7363616c612e5475706c6532bc7daadf46211a990200024c00025f317400124c6a6176612f6c616e672f4f626a6563743b4c00025f3271007e000178707372001c616b6b612e64697370617463682e7379736d73672e556e776174636858501f7ee63dc2100200024c0007776174636865657400154c616b6b612f6163746f722f4163746f725265663b4c00077761746368657271007e000478707372001f616b6b612e73657269616c697a6174696f6e2e46616b654163746f7252656600000000000000010200014c00046e616d657400124c6a6176612f6c616e672f537472696e673b7872001b616b6b612e6163746f722e496e7465726e616c4163746f72526566db6eaed9e69a356302000078720013616b6b612e6163746f722e4163746f72526566c3585dde655f46940200007870740007776174636865657371007e0006740007776174636865727671007e0003")
|
verify(Unwatch(FakeActorRef("watchee"), FakeActorRef("watcher")), "aced00057372000c7363616c612e5475706c6532bc7daadf46211a990200024c00025f317400124c6a6176612f6c616e672f4f626a6563743b4c00025f3271007e000178707372001c616b6b612e64697370617463682e7379736d73672e556e776174636858501f7ee63dc2100200024c0007776174636865657400154c616b6b612f6163746f722f4163746f725265663b4c00077761746368657271007e000478707372001f616b6b612e73657269616c697a6174696f6e2e46616b654163746f7252656600000000000000010200014c00046e616d657400124c6a6176612f6c616e672f537472696e673b7872001b616b6b612e6163746f722e496e7465726e616c4163746f72526566869e6c3669e60e5f02000078720013616b6b612e6163746f722e4163746f72526566c3585dde655f46940200007870740007776174636865657371007e0006740007776174636865727671007e0003")
|
||||||
}
|
}
|
||||||
"be preserved for the NoMessage SystemMessage" in {
|
"be preserved for the NoMessage SystemMessage" in {
|
||||||
verify(NoMessage, "aced00057372000c7363616c612e5475706c6532bc7daadf46211a990200024c00025f317400124c6a6176612f6c616e672f4f626a6563743b4c00025f3271007e000178707372001f616b6b612e64697370617463682e7379736d73672e4e6f4d65737361676524b401a3610ccb70dd02000078707671007e0003")
|
verify(NoMessage, "aced00057372000c7363616c612e5475706c6532bc7daadf46211a990200024c00025f317400124c6a6176612f6c616e672f4f626a6563743b4c00025f3271007e000178707372001f616b6b612e64697370617463682e7379736d73672e4e6f4d65737361676524b401a3610ccb70dd02000078707671007e0003")
|
||||||
}
|
}
|
||||||
"be preserved for the Failed SystemMessage" in {
|
"be preserved for the Failed SystemMessage" in {
|
||||||
// Using null as the cause to avoid a large serialized message
|
// Using null as the cause to avoid a large serialized message
|
||||||
verify(Failed(FakeActorRef("child"), cause = null, uid = 0), "aced00057372000c7363616c612e5475706c6532bc7daadf46211a990200024c00025f317400124c6a6176612f6c616e672f4f626a6563743b4c00025f3271007e000178707372001b616b6b612e64697370617463682e7379736d73672e4661696c656400000000000000030200034900037569644c000563617573657400154c6a6176612f6c616e672f5468726f7761626c653b4c00056368696c647400154c616b6b612f6163746f722f4163746f725265663b787000000000707372001f616b6b612e73657269616c697a6174696f6e2e46616b654163746f7252656600000000000000010200014c00046e616d657400124c6a6176612f6c616e672f537472696e673b7872001b616b6b612e6163746f722e496e7465726e616c4163746f72526566db6eaed9e69a356302000078720013616b6b612e6163746f722e4163746f72526566c3585dde655f469402000078707400056368696c647671007e0003")
|
verify(Failed(FakeActorRef("child"), cause = null, uid = 0), "aced00057372000c7363616c612e5475706c6532bc7daadf46211a990200024c00025f317400124c6a6176612f6c616e672f4f626a6563743b4c00025f3271007e000178707372001b616b6b612e64697370617463682e7379736d73672e4661696c656400000000000000030200034900037569644c000563617573657400154c6a6176612f6c616e672f5468726f7761626c653b4c00056368696c647400154c616b6b612f6163746f722f4163746f725265663b787000000000707372001f616b6b612e73657269616c697a6174696f6e2e46616b654163746f7252656600000000000000010200014c00046e616d657400124c6a6176612f6c616e672f537472696e673b7872001b616b6b612e6163746f722e496e7465726e616c4163746f72526566869e6c3669e60e5f02000078720013616b6b612e6163746f722e4163746f72526566c3585dde655f469402000078707400056368696c647671007e0003")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -411,7 +411,7 @@ protected[akka] case class FakeThrowable(msg: String) extends Throwable(msg) wit
|
||||||
protected[akka] case class FakeActorRef(name: String) extends InternalActorRef with ActorRefScope {
|
protected[akka] case class FakeActorRef(name: String) extends InternalActorRef with ActorRefScope {
|
||||||
override def path = RootActorPath(Address("proto", "SomeSystem"), name)
|
override def path = RootActorPath(Address("proto", "SomeSystem"), name)
|
||||||
override def forward(message: Any)(implicit context: ActorContext) = ???
|
override def forward(message: Any)(implicit context: ActorContext) = ???
|
||||||
override def isTerminated = ???
|
@deprecated("Use context.watch(actor) and receive Terminated(actor)", "2.2") override def isTerminated = ???
|
||||||
override def start() = ???
|
override def start() = ???
|
||||||
override def resume(causedByFailure: Throwable) = ???
|
override def resume(causedByFailure: Throwable) = ???
|
||||||
override def suspend() = ???
|
override def suspend() = ???
|
||||||
|
|
|
||||||
|
|
@ -133,7 +133,7 @@ abstract class ActorRef extends java.lang.Comparable[ActorRef] with Serializable
|
||||||
* The contract is that if this method returns true, then it will never be false again.
|
* The contract is that if this method returns true, then it will never be false again.
|
||||||
* But you cannot rely on that it is alive if it returns false, since this by nature is a racy method.
|
* But you cannot rely on that it is alive if it returns false, since this by nature is a racy method.
|
||||||
*/
|
*/
|
||||||
def isTerminated: Boolean
|
@deprecated("Use context.watch(actor) and receive Terminated(actor)", "2.2") def isTerminated: Boolean
|
||||||
|
|
||||||
final override def hashCode: Int = {
|
final override def hashCode: Int = {
|
||||||
if (path.uid == ActorCell.undefinedUid) path.hashCode
|
if (path.uid == ActorCell.undefinedUid) path.hashCode
|
||||||
|
|
@ -247,6 +247,12 @@ private[akka] abstract class InternalActorRef extends ActorRef with ScalaActorRe
|
||||||
* i.e. whose mailbox is directly reachable etc.
|
* i.e. whose mailbox is directly reachable etc.
|
||||||
*/
|
*/
|
||||||
def isLocal: Boolean
|
def isLocal: Boolean
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns “true” if the actor is locally known to be terminated, “false” if
|
||||||
|
* alive or uncertain.
|
||||||
|
*/
|
||||||
|
def isTerminated: Boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -302,7 +308,7 @@ private[akka] class LocalActorRef private[akka] (
|
||||||
* If this method returns true, it will never return false again, but if it
|
* If this method returns true, it will never return false again, but if it
|
||||||
* returns false, you cannot be sure if it's alive still (race condition)
|
* returns false, you cannot be sure if it's alive still (race condition)
|
||||||
*/
|
*/
|
||||||
override def isTerminated: Boolean = actorCell.isTerminated
|
@deprecated("Use context.watch(actor) and receive Terminated(actor)", "2.2") override def isTerminated: Boolean = actorCell.isTerminated
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts the actor after initialization.
|
* Starts the actor after initialization.
|
||||||
|
|
@ -428,7 +434,7 @@ private[akka] trait MinimalActorRef extends InternalActorRef with LocalRef {
|
||||||
override def suspend(): Unit = ()
|
override def suspend(): Unit = ()
|
||||||
override def resume(causedByFailure: Throwable): Unit = ()
|
override def resume(causedByFailure: Throwable): Unit = ()
|
||||||
override def stop(): Unit = ()
|
override def stop(): Unit = ()
|
||||||
override def isTerminated = false
|
@deprecated("Use context.watch(actor) and receive Terminated(actor)", "2.2") override def isTerminated = false
|
||||||
|
|
||||||
override def !(message: Any)(implicit sender: ActorRef = Actor.noSender): Unit = ()
|
override def !(message: Any)(implicit sender: ActorRef = Actor.noSender): Unit = ()
|
||||||
|
|
||||||
|
|
@ -469,7 +475,7 @@ private[akka] class EmptyLocalActorRef(override val provider: ActorRefProvider,
|
||||||
override val path: ActorPath,
|
override val path: ActorPath,
|
||||||
val eventStream: EventStream) extends MinimalActorRef {
|
val eventStream: EventStream) extends MinimalActorRef {
|
||||||
|
|
||||||
override def isTerminated: Boolean = true
|
@deprecated("Use context.watch(actor) and receive Terminated(actor)", "2.2") override def isTerminated(): Boolean = true
|
||||||
|
|
||||||
override def sendSystemMessage(message: SystemMessage): Unit = {
|
override def sendSystemMessage(message: SystemMessage): Unit = {
|
||||||
if (Mailbox.debug) println(s"ELAR $path having enqueued $message")
|
if (Mailbox.debug) println(s"ELAR $path having enqueued $message")
|
||||||
|
|
|
||||||
|
|
@ -386,7 +386,7 @@ private[akka] class LocalActorRefProvider private[akka] (
|
||||||
def provider: ActorRefProvider = LocalActorRefProvider.this
|
def provider: ActorRefProvider = LocalActorRefProvider.this
|
||||||
|
|
||||||
override def stop(): Unit = stopped switchOn { terminationPromise.complete(causeOfTermination.map(Failure(_)).getOrElse(Success(()))) }
|
override def stop(): Unit = stopped switchOn { terminationPromise.complete(causeOfTermination.map(Failure(_)).getOrElse(Success(()))) }
|
||||||
override def isTerminated: Boolean = stopped.isOn
|
@deprecated("Use context.watch(actor) and receive Terminated(actor)", "2.2") override def isTerminated: Boolean = stopped.isOn
|
||||||
|
|
||||||
override def !(message: Any)(implicit sender: ActorRef = Actor.noSender): Unit = stopped.ifOff(message match {
|
override def !(message: Any)(implicit sender: ActorRef = Actor.noSender): Unit = stopped.ifOff(message match {
|
||||||
case null ⇒ throw new InvalidMessageException("Message is null")
|
case null ⇒ throw new InvalidMessageException("Message is null")
|
||||||
|
|
|
||||||
|
|
@ -553,12 +553,12 @@ trait FSM[S, D] extends Listeners with ActorLogging {
|
||||||
processMsg(msg, t)
|
processMsg(msg, t)
|
||||||
}
|
}
|
||||||
case SubscribeTransitionCallBack(actorRef) ⇒
|
case SubscribeTransitionCallBack(actorRef) ⇒
|
||||||
// TODO use DeathWatch to clean up list
|
// TODO Use context.watch(actor) and receive Terminated(actor) to clean up list
|
||||||
listeners.add(actorRef)
|
listeners.add(actorRef)
|
||||||
// send current state back as reference point
|
// send current state back as reference point
|
||||||
actorRef ! CurrentState(self, currentState.stateName)
|
actorRef ! CurrentState(self, currentState.stateName)
|
||||||
case Listen(actorRef) ⇒
|
case Listen(actorRef) ⇒
|
||||||
// TODO use DeathWatch to clean up list
|
// TODO Use context.watch(actor) and receive Terminated(actor) to clean up list
|
||||||
listeners.add(actorRef)
|
listeners.add(actorRef)
|
||||||
// send current state back as reference point
|
// send current state back as reference point
|
||||||
actorRef ! CurrentState(self, currentState.stateName)
|
actorRef ! CurrentState(self, currentState.stateName)
|
||||||
|
|
|
||||||
|
|
@ -129,7 +129,7 @@ private[akka] class RepointableActorRef(
|
||||||
case _ ⇒ true
|
case _ ⇒ true
|
||||||
}
|
}
|
||||||
|
|
||||||
def isTerminated: Boolean = underlying.isTerminated
|
@deprecated("Use context.watch(actor) and receive Terminated(actor)", "2.2") def isTerminated: Boolean = underlying.isTerminated
|
||||||
|
|
||||||
def provider: ActorRefProvider = system.provider
|
def provider: ActorRefProvider = system.provider
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -215,7 +215,7 @@ private[akka] final class PromiseActorRef private (val provider: ActorRefProvide
|
||||||
case _ ⇒
|
case _ ⇒
|
||||||
}
|
}
|
||||||
|
|
||||||
override def isTerminated: Boolean = state match {
|
@deprecated("Use context.watch(actor) and receive Terminated(actor)", "2.2") override def isTerminated: Boolean = state match {
|
||||||
case Stopped | _: StoppedWithPath ⇒ true
|
case Stopped | _: StoppedWithPath ⇒ true
|
||||||
case _ ⇒ false
|
case _ ⇒ false
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ import akka.event.LoggingAdapter;
|
||||||
//#imports-prio-mailbox
|
//#imports-prio-mailbox
|
||||||
import akka.dispatch.PriorityGenerator;
|
import akka.dispatch.PriorityGenerator;
|
||||||
import akka.dispatch.UnboundedPriorityMailbox;
|
import akka.dispatch.UnboundedPriorityMailbox;
|
||||||
|
import akka.testkit.JavaTestKit;
|
||||||
import com.typesafe.config.Config;
|
import com.typesafe.config.Config;
|
||||||
|
|
||||||
//#imports-prio-mailbox
|
//#imports-prio-mailbox
|
||||||
|
|
@ -83,6 +84,7 @@ public class DispatcherDocTestBase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void priorityDispatcher() throws Exception {
|
public void priorityDispatcher() throws Exception {
|
||||||
|
JavaTestKit probe = new JavaTestKit(system);
|
||||||
//#prio-dispatcher
|
//#prio-dispatcher
|
||||||
|
|
||||||
// We create a new Actor that just prints out what it processes
|
// We create a new Actor that just prints out what it processes
|
||||||
|
|
@ -93,14 +95,17 @@ public class DispatcherDocTestBase {
|
||||||
LoggingAdapter log =
|
LoggingAdapter log =
|
||||||
Logging.getLogger(getContext().system(), this);
|
Logging.getLogger(getContext().system(), this);
|
||||||
{
|
{
|
||||||
getSelf().tell("lowpriority", getSelf());
|
for(Object msg : new Object[] {
|
||||||
getSelf().tell("lowpriority", getSelf());
|
"lowpriority",
|
||||||
getSelf().tell("highpriority", getSelf());
|
"lowpriority",
|
||||||
getSelf().tell("pigdog", getSelf());
|
"highpriority",
|
||||||
getSelf().tell("pigdog2", getSelf());
|
"pigdog",
|
||||||
getSelf().tell("pigdog3", getSelf());
|
"pigdog2",
|
||||||
getSelf().tell("highpriority", getSelf());
|
"pigdog3",
|
||||||
getSelf().tell(PoisonPill.getInstance(), getSelf());
|
"highpriority",
|
||||||
|
PoisonPill.getInstance() }) {
|
||||||
|
getSelf().tell(msg, getSelf());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onReceive(Object message) {
|
public void onReceive(Object message) {
|
||||||
|
|
@ -122,11 +127,8 @@ public class DispatcherDocTestBase {
|
||||||
*/
|
*/
|
||||||
//#prio-dispatcher
|
//#prio-dispatcher
|
||||||
|
|
||||||
for (int i = 0; i < 10; i++) {
|
probe.watch(myActor);
|
||||||
if (myActor.isTerminated())
|
probe.expectMsgClass(Terminated.class);
|
||||||
break;
|
|
||||||
Thread.sleep(100);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
|
|
|
||||||
|
|
@ -3,12 +3,7 @@
|
||||||
*/
|
*/
|
||||||
package docs.jrouting;
|
package docs.jrouting;
|
||||||
|
|
||||||
import akka.actor.ActorRef;
|
import akka.actor.*;
|
||||||
import akka.actor.ActorSystem;
|
|
||||||
import akka.actor.Kill;
|
|
||||||
import akka.actor.PoisonPill;
|
|
||||||
import akka.actor.Props;
|
|
||||||
import akka.actor.UntypedActor;
|
|
||||||
import akka.remote.routing.RemoteRouterConfig;
|
import akka.remote.routing.RemoteRouterConfig;
|
||||||
import akka.routing.Broadcast;
|
import akka.routing.Broadcast;
|
||||||
import akka.routing.RoundRobinRouter;
|
import akka.routing.RoundRobinRouter;
|
||||||
|
|
@ -83,11 +78,11 @@ public class RouterViaProgramDocTestBase {
|
||||||
public void demonstratePoisonPill() {
|
public void demonstratePoisonPill() {
|
||||||
new JavaTestKitWithSelf(system) {{
|
new JavaTestKitWithSelf(system) {{
|
||||||
ActorRef router = system.actorOf(new Props(Echo.class).withRouter(new RoundRobinRouter(5)));
|
ActorRef router = system.actorOf(new Props(Echo.class).withRouter(new RoundRobinRouter(5)));
|
||||||
|
watch(router);
|
||||||
//#poisonPill
|
//#poisonPill
|
||||||
router.tell(PoisonPill.getInstance(), getSelf());
|
router.tell(PoisonPill.getInstance(), getSelf());
|
||||||
//#poisonPill
|
//#poisonPill
|
||||||
expectNoMsg(duration("1 seconds"));
|
expectMsgClass(Terminated.class);
|
||||||
Assert.assertTrue(router.isTerminated());
|
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -95,11 +90,11 @@ public class RouterViaProgramDocTestBase {
|
||||||
public void demonstrateBroadcastOfPoisonPill() {
|
public void demonstrateBroadcastOfPoisonPill() {
|
||||||
new JavaTestKitWithSelf(system) {{
|
new JavaTestKitWithSelf(system) {{
|
||||||
ActorRef router = system.actorOf(new Props(Echo.class).withRouter(new RoundRobinRouter(5)));
|
ActorRef router = system.actorOf(new Props(Echo.class).withRouter(new RoundRobinRouter(5)));
|
||||||
|
watch(router);
|
||||||
//#broadcastPoisonPill
|
//#broadcastPoisonPill
|
||||||
router.tell(new Broadcast(PoisonPill.getInstance()), getSelf());
|
router.tell(new Broadcast(PoisonPill.getInstance()), getSelf());
|
||||||
//#broadcastPoisonPill
|
//#broadcastPoisonPill
|
||||||
expectNoMsg(duration("1 seconds"));
|
expectMsgClass(Terminated.class);
|
||||||
Assert.assertTrue(router.isTerminated());
|
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -107,11 +102,11 @@ public class RouterViaProgramDocTestBase {
|
||||||
public void demonstrateKill() {
|
public void demonstrateKill() {
|
||||||
new JavaTestKitWithSelf(system) {{
|
new JavaTestKitWithSelf(system) {{
|
||||||
ActorRef router = system.actorOf(new Props(Echo.class).withRouter(new RoundRobinRouter(5)));
|
ActorRef router = system.actorOf(new Props(Echo.class).withRouter(new RoundRobinRouter(5)));
|
||||||
|
watch(router);
|
||||||
//#kill
|
//#kill
|
||||||
router.tell(Kill.getInstance(), getSelf());
|
router.tell(Kill.getInstance(), getSelf());
|
||||||
//#kill
|
//#kill
|
||||||
expectNoMsg(duration("1 seconds"));
|
expectMsgClass(Terminated.class);
|
||||||
Assert.assertTrue(router.isTerminated());
|
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -119,11 +114,11 @@ public class RouterViaProgramDocTestBase {
|
||||||
public void demonstrateBroadcastOfKill() {
|
public void demonstrateBroadcastOfKill() {
|
||||||
new JavaTestKitWithSelf(system) {{
|
new JavaTestKitWithSelf(system) {{
|
||||||
ActorRef router = system.actorOf(new Props(Echo.class).withRouter(new RoundRobinRouter(5)));
|
ActorRef router = system.actorOf(new Props(Echo.class).withRouter(new RoundRobinRouter(5)));
|
||||||
|
watch(router);
|
||||||
//#broadcastKill
|
//#broadcastKill
|
||||||
router.tell(new Broadcast(Kill.getInstance()), getSelf());
|
router.tell(new Broadcast(Kill.getInstance()), getSelf());
|
||||||
//#broadcastKill
|
//#broadcastKill
|
||||||
expectNoMsg(duration("1 seconds"));
|
expectMsgClass(Terminated.class);
|
||||||
Assert.assertTrue(router.isTerminated());
|
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -115,10 +115,7 @@ class FaultHandlingDocSpec extends AkkaSpec with ImplicitSender {
|
||||||
//#stop
|
//#stop
|
||||||
watch(child) // have testActor watch “child”
|
watch(child) // have testActor watch “child”
|
||||||
child ! new IllegalArgumentException // break it
|
child ! new IllegalArgumentException // break it
|
||||||
expectMsgPF() {
|
expectMsgPF() { case Terminated(`child`) ⇒ () }
|
||||||
case t @ Terminated(`child`) if t.existenceConfirmed ⇒ ()
|
|
||||||
}
|
|
||||||
child.isTerminated must be(true)
|
|
||||||
//#stop
|
//#stop
|
||||||
}
|
}
|
||||||
EventFilter[Exception]("CRASH", occurrences = 2) intercept {
|
EventFilter[Exception]("CRASH", occurrences = 2) intercept {
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ import akka.testkit.AkkaSpec
|
||||||
import akka.event.Logging
|
import akka.event.Logging
|
||||||
import akka.event.LoggingAdapter
|
import akka.event.LoggingAdapter
|
||||||
import scala.concurrent.duration._
|
import scala.concurrent.duration._
|
||||||
import akka.actor.{ Props, Actor, PoisonPill, ActorSystem }
|
import akka.actor._
|
||||||
|
|
||||||
object DispatcherDocSpec {
|
object DispatcherDocSpec {
|
||||||
val config = """
|
val config = """
|
||||||
|
|
@ -227,7 +227,8 @@ class DispatcherDocSpec extends AkkaSpec(DispatcherDocSpec.config) {
|
||||||
*/
|
*/
|
||||||
//#prio-dispatcher
|
//#prio-dispatcher
|
||||||
|
|
||||||
awaitCond(a.isTerminated, 5 seconds)
|
watch(a)
|
||||||
|
expectMsgPF() { case Terminated(`a`) ⇒ () }
|
||||||
}
|
}
|
||||||
|
|
||||||
"defining balancing dispatcher" in {
|
"defining balancing dispatcher" in {
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
*/
|
*/
|
||||||
package docs.routing
|
package docs.routing
|
||||||
|
|
||||||
import akka.actor.{ Actor, ActorRef, ActorSystem, Props, ActorLogging }
|
import akka.actor._
|
||||||
import akka.routing.ConsistentHashingRouter.ConsistentHashable
|
import akka.routing.ConsistentHashingRouter.ConsistentHashable
|
||||||
import akka.routing.FromConfig
|
import akka.routing.FromConfig
|
||||||
import akka.routing.RoundRobinRouter
|
import akka.routing.RoundRobinRouter
|
||||||
|
|
@ -37,8 +37,8 @@ class RouterViaProgramDocSpec extends AkkaSpec with ImplicitSender {
|
||||||
val actor2 = system.actorOf(Props[ExampleActor1], "actor2")
|
val actor2 = system.actorOf(Props[ExampleActor1], "actor2")
|
||||||
val actor3 = system.actorOf(Props[ExampleActor1], "actor3")
|
val actor3 = system.actorOf(Props[ExampleActor1], "actor3")
|
||||||
val routees = Vector[String]("/user/actor1", "/user/actor2", "/user/actor3")
|
val routees = Vector[String]("/user/actor1", "/user/actor2", "/user/actor3")
|
||||||
val router = system.actorOf(Props().withRouter(
|
val router = system.actorOf(
|
||||||
RoundRobinRouter(routees = routees)))
|
Props().withRouter(RoundRobinRouter(routees = routees)))
|
||||||
//#programmaticRoutingRouteePaths
|
//#programmaticRoutingRouteePaths
|
||||||
1 to 6 foreach { i ⇒ router ! Message1(i) }
|
1 to 6 foreach { i ⇒ router ! Message1(i) }
|
||||||
val received = receiveN(6, 5.seconds.dilated)
|
val received = receiveN(6, 5.seconds.dilated)
|
||||||
|
|
@ -59,45 +59,41 @@ class RouterViaProgramDocSpec extends AkkaSpec with ImplicitSender {
|
||||||
}
|
}
|
||||||
|
|
||||||
"demonstrate PoisonPill" in {
|
"demonstrate PoisonPill" in {
|
||||||
val router = system.actorOf(Props[Echo].withRouter(RoundRobinRouter(nrOfInstances = 5)))
|
val router = watch(system.actorOf(Props[Echo].withRouter(RoundRobinRouter(nrOfInstances = 5))))
|
||||||
//#poisonPill
|
//#poisonPill
|
||||||
import akka.actor.PoisonPill
|
import akka.actor.PoisonPill
|
||||||
router ! PoisonPill
|
router ! PoisonPill
|
||||||
//#poisonPill
|
//#poisonPill
|
||||||
expectNoMsg(1.seconds.dilated)
|
expectMsgPF() { case Terminated(`router`) ⇒ () }
|
||||||
router.isTerminated must be(true)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
"demonstrate broadcast of PoisonPill" in {
|
"demonstrate broadcast of PoisonPill" in {
|
||||||
val router = system.actorOf(Props[Echo].withRouter(RoundRobinRouter(nrOfInstances = 5)))
|
val router = watch(system.actorOf(Props[Echo].withRouter(RoundRobinRouter(nrOfInstances = 5))))
|
||||||
//#broadcastPoisonPill
|
//#broadcastPoisonPill
|
||||||
import akka.actor.PoisonPill
|
import akka.actor.PoisonPill
|
||||||
import akka.routing.Broadcast
|
import akka.routing.Broadcast
|
||||||
router ! Broadcast(PoisonPill)
|
router ! Broadcast(PoisonPill)
|
||||||
//#broadcastPoisonPill
|
//#broadcastPoisonPill
|
||||||
expectNoMsg(1.seconds.dilated)
|
expectMsgPF() { case Terminated(`router`) ⇒ () }
|
||||||
router.isTerminated must be(true)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
"demonstrate Kill" in {
|
"demonstrate Kill" in {
|
||||||
val router = system.actorOf(Props[Echo].withRouter(RoundRobinRouter(nrOfInstances = 5)))
|
val router = watch(system.actorOf(Props[Echo].withRouter(RoundRobinRouter(nrOfInstances = 5))))
|
||||||
//#kill
|
//#kill
|
||||||
import akka.actor.Kill
|
import akka.actor.Kill
|
||||||
router ! Kill
|
router ! Kill
|
||||||
//#kill
|
//#kill
|
||||||
expectNoMsg(1.seconds.dilated)
|
expectMsgPF() { case Terminated(`router`) ⇒ () }
|
||||||
router.isTerminated must be(true)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
"demonstrate broadcast of Kill" in {
|
"demonstrate broadcast of Kill" in {
|
||||||
val router = system.actorOf(Props[Echo].withRouter(RoundRobinRouter(nrOfInstances = 5)))
|
val router = watch(system.actorOf(Props[Echo].withRouter(RoundRobinRouter(nrOfInstances = 5))))
|
||||||
//#broadcastKill
|
//#broadcastKill
|
||||||
import akka.actor.Kill
|
import akka.actor.Kill
|
||||||
import akka.routing.Broadcast
|
import akka.routing.Broadcast
|
||||||
router ! Broadcast(Kill)
|
router ! Broadcast(Kill)
|
||||||
//#broadcastKill
|
//#broadcastKill
|
||||||
expectNoMsg(1.seconds.dilated)
|
expectMsgPF() { case Terminated(`router`) ⇒ () }
|
||||||
router.isTerminated must be(true)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -356,7 +356,7 @@ private[akka] class RemoteActorRef private[akka] (
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def isTerminated: Boolean = false
|
@deprecated("Use context.watch(actor) and receive Terminated(actor)", "2.2") override def isTerminated: Boolean = false
|
||||||
|
|
||||||
private def handleException: Catcher[Unit] = {
|
private def handleException: Catcher[Unit] = {
|
||||||
case e: InterruptedException ⇒
|
case e: InterruptedException ⇒
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue