Hi there -
Somewhat regularly I have a need to access the current message in an actor
method outside of the receive. It's usually some case where I want to do
something generic with it, like logging.
There are two general approaches that I've used. The first approach is
pass the message down to where ever it's needed, for example:
def receive = {
case f @ Foo(a, b) =>
handleFoo(f, a, b)
case b @ Bar(x, y, z) =>
handleBar(b, x, y, z)
many other cases...
}
Somewhere down the call chain everything calls a generic method that is
passed the current message.
The other approach is to create a Receive wrapper (a la LoggingReceive)
that captures the message in isDefinedAt and makes it available as a
variable.
For example:
class MyActor extends CurrentMessageActor {
def receive = CaptureCurrentMessage {
case Foo(a, b) =>
...
def genericMethod() {
println(currentMessage)
}
Neither approach is very satisfactory because of the boilerplate. I'm
wondering, if we have access to the sender, why not the current message?
Is this something that would be useful for other people? Is there a reason
why we wouldn't want to expose this in the regular Akka API?
Thanks,
--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ:
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.