Merge pull request #1780 from drewhk/wip-3637-friendlier-asktimeout-message-drewhk

!act #3637: Add information about target in AskTimeout
This commit is contained in:
drewhk 2013-12-11 06:54:54 -08:00
commit f5a42b53da
4 changed files with 17 additions and 6 deletions

View file

@ -67,6 +67,15 @@ class AskSpec extends AkkaSpec {
}.getMessage must be === expectedMsg
}
"include target information in AskTimeout" in {
implicit val timeout = Timeout(0.5 seconds)
val silentOne = system.actorOf(Props.empty, "silent")
val f = silentOne ? "noreply"
intercept[AskTimeoutException] {
Await.result(f, remaining)
}.getMessage.contains("/user/silent") must be(true)
}
"work for ActorSelection" in {
implicit val timeout = Timeout(5 seconds)
import system.dispatcher

View file

@ -136,7 +136,7 @@ final class AskableActorRef(val actorRef: ActorRef) extends AnyVal {
if (timeout.duration.length <= 0)
Future.failed[Any](new IllegalArgumentException(s"Timeout length must not be negative, question not sent to [$actorRef]"))
else {
val a = PromiseActorRef(ref.provider, timeout)
val a = PromiseActorRef(ref.provider, timeout, targetName = actorRef.toString)
actorRef.tell(message, a)
a.result.future
}
@ -157,7 +157,7 @@ final class AskableActorSelection(val actorSel: ActorSelection) extends AnyVal {
Future.failed[Any](
new IllegalArgumentException(s"Timeout length must not be negative, question not sent to [$actorSel]"))
else {
val a = PromiseActorRef(ref.provider, timeout)
val a = PromiseActorRef(ref.provider, timeout, targetName = actorSel.toString)
actorSel.tell(message, a)
a.result.future
}
@ -326,12 +326,14 @@ private[akka] object PromiseActorRef {
private case object Stopped
private case class StoppedWithPath(path: ActorPath)
def apply(provider: ActorRefProvider, timeout: Timeout): PromiseActorRef = {
def apply(provider: ActorRefProvider, timeout: Timeout, targetName: String): PromiseActorRef = {
val result = Promise[Any]()
val scheduler = provider.guardian.underlying.system.scheduler
val a = new PromiseActorRef(provider, result)
implicit val ec = a.internalCallingThreadExecutionContext
val f = scheduler.scheduleOnce(timeout.duration) { result tryComplete Failure(new AskTimeoutException("Timed out")) }
val f = scheduler.scheduleOnce(timeout.duration) {
result tryComplete Failure(new AskTimeoutException(s"Ask timed out on [$targetName]"))
}
result.future onComplete { _ try a.stop() finally f.cancel() }
a
}

View file

@ -49,7 +49,7 @@ trait GracefulStopSupport {
if (target.isTerminated) Future successful true
else {
val internalTarget = target.asInstanceOf[InternalActorRef]
val ref = PromiseActorRef(internalTarget.provider, Timeout(timeout))
val ref = PromiseActorRef(internalTarget.provider, Timeout(timeout), targetName = target.toString)
internalTarget.sendSystemMessage(Watch(internalTarget, ref))
target.tell(stopMessage, Actor.noSender)
ref.result.future.transform(

View file

@ -284,7 +284,7 @@ private[transport] class ThrottlerManager(wrappedTransport: Transport) extends A
if (target.isTerminated) Future successful SetThrottleAck
else {
val internalTarget = target.asInstanceOf[InternalActorRef]
val ref = PromiseActorRef(internalTarget.provider, timeout)
val ref = PromiseActorRef(internalTarget.provider, timeout, target.toString)
internalTarget.sendSystemMessage(Watch(internalTarget, ref))
target.tell(mode, ref)
ref.result.future.transform({