You could call system.eventStream
to unsubscribe MyActor
. For example:
import akka.event.Logging._
case object UnsubscribeFromLogging
class MyActor extends Actor {
def receive = {
case InitializeLogger(_) => sender() ! LoggerInitialized
case Error(cause, logSource, logClass, message) => // ...
case Warning(logSource, logClass, message) => // ...
case Info(logSource, logClass, message) => // ...
case Debug(logSource, logClass, message) => // ...
case UnsubscribeFromLogging => context.system.eventStream.unsubscribe(self)
}
}
The above example uses a custom UnsubscribeFromLogging
message:
val myActor: ActorRef = ??? // reference to MyActor
myActor ! UnsubscribeFromLogging
You could pass the reference to MyActor
to the unsubscribe
method from another actor:
val myActor: ActorRef = ??? // reference to MyActor
context.system.eventStream.unsubscribe(myActor)
Either way, you need a reference to MyActor
. You can obtain this by determining MyActor
's path (for example, have MyActor
print self.path
) and passing this path to context.actorSelection
.