Hi,
The PersistentActor API documentation states that it is safe to close
over actor state in a persist or persistAsync, and that sender() is the
one from the original command (which allows to reply to the incoming
command).
I've read the code (and I won't pretend I understood it correctly), but
I don't see how sender() is kept correct.
The reason I'm asking this question is that I have a kind of around
receive wrapper that extracts from the currently processed message some
metadata (like a request id or it's originator allowing to trace the
request flow back to it's source).
This works like this pseudo-code:
trait RequestContextActor extends PersistentActor {
final def receiveCommand = derivedReceiveWrapper(derivedReceive)
private var currentRequestcontext: RequestContext = RequestContext.unknown
implicit def request: RequestContext = currentRequestcontext
def derivedReceive: Receive
def derivedReceiveWrapper(wrapped: Receive): Receive = {
case x: RequestContextHolder if wrapped.isDefinedAt(x) =>
currentRequestcontext = x.request
wrapped(x)
currentRequestcontext = RequestContext.unknown
case message if wrapped.isDefinedAt(message) =>
currentRequestcontext = RequestContext.unknown
wrapped(message)
currentRequestcontext = RequestContext.unknown
}
}
class MyActor extends RequestContextActor {
def derivedReceive = {
case m => {
// here request is correct
persist(Event()) {
// here request is 'unknown'
}
}
}
}
During persist/persistAsync handlers the currentRequestcontext is at the
value "unknown", while processing the message it is set to the incoming
request.
Any idea how I could do like sender(), and keep my request context
available during persist and persistAsync handlers?
Thanks
--
Brice Figureau
My Blog: http://www.masterzen.fr/
--
>>>>>>>>>> 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.