Cleaning up some of the Java samples and adding sender to the UnhandledMessage
This commit is contained in:
parent
2adb042bf7
commit
634147d090
5 changed files with 8 additions and 8 deletions
|
|
@ -106,7 +106,7 @@ case class UnhandledMessageException(msg: Any, ref: ActorRef = null) extends Run
|
|||
/**
|
||||
* This message is published to the EventStream whenever an Actor receives a message it doesn't understand
|
||||
*/
|
||||
case class UnhandledMessage(@BeanProperty message: Any, @BeanProperty recipient: ActorRef)
|
||||
case class UnhandledMessage(@BeanProperty message: Any, @BeanProperty sender: ActorRef, @BeanProperty recipient: ActorRef)
|
||||
|
||||
/**
|
||||
* Classes for passing status back to the sender.
|
||||
|
|
@ -271,13 +271,13 @@ trait Actor {
|
|||
* <p/>
|
||||
* Is called when a message isn't handled by the current behavior of the actor
|
||||
* by default it fails with either a [[akka.actor.DeathPactException]] (in
|
||||
* case of an unhandled [[akka.actor.Terminated]] message) or a
|
||||
* [[akka.actor.UnhandledMessageException]].
|
||||
* case of an unhandled [[akka.actor.Terminated]] message) or publishes an [[akka.actor.UnhandledMessage]]
|
||||
* to the actor's system's [[akka.event.EventStream]]
|
||||
*/
|
||||
def unhandled(message: Any) {
|
||||
message match {
|
||||
case Terminated(dead) ⇒ throw new DeathPactException(dead)
|
||||
case _ ⇒ context.system.eventStream.publish(UnhandledMessage(message, self))
|
||||
case _ ⇒ context.system.eventStream.publish(UnhandledMessage(message, sender, self))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ public class MyReceivedTimeoutUntypedActor extends UntypedActor {
|
|||
} else if (message == Actors.receiveTimeout()) {
|
||||
throw new RuntimeException("received timeout");
|
||||
} else {
|
||||
throw new UnhandledMessageException(message, getSelf());
|
||||
unhandled(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ public class MyUntypedActor extends UntypedActor {
|
|||
if (message instanceof String)
|
||||
log.info("Received String message: {}", message);
|
||||
else
|
||||
throw new UnhandledMessageException(message, getSelf());
|
||||
unhandled(message);
|
||||
}
|
||||
}
|
||||
//#my-untyped-actor
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ public class UntypedActorSwapper {
|
|||
}
|
||||
});
|
||||
} else {
|
||||
throw new UnhandledMessageException(message, getSelf());
|
||||
unhandled(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -142,7 +142,7 @@ The :class:`Actor` trait defines only one abstract method, the above mentioned
|
|||
:meth:`receive`, which implements the behavior of the actor.
|
||||
|
||||
If the current actor behavior does not match a received message, :meth:`unhandled`
|
||||
is called, which by default throws an :class:`UnhandledMessageException`.
|
||||
is called, which by default publishes an ``akka.actor.UnhandledMessage(message, sender, recipient)``
|
||||
|
||||
In addition, it offers:
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue