Within my actor I have to create a class which sends a message to another actor. The other actor should reply back to actor A
class A extends Actor {
val b = new B
b.start
val i = new DefaultHandler() {
override def fun(a: String) = {
b ! payload
}
}
someotherclass.registerHandler(i)
def act = {
loop {
react {
case reply => //do something
}
class B extends Actor {
def act = {
loop {
react {
case msg => sender ! reply
}
}
The problem now is that while sending from the inner class I'm not within the actor itself anymore and as a result actor B does not get a correct reference to actor B. One way to fix this would be to pass a reference to A via the message but this seems quite ugly to me.
val ref = self
val i = new DefaultClass() {
override def fun(a: String) = {
b ! message(payload, ref)
}
}
Is there a more elegant way to solve this?