-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17490 from akka/wip-17010-logger-mailbox-patriknw
=act #17010 Drain log messages on system shutdown
- Loading branch information
Showing
6 changed files
with
106 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* Copyright (C) 2015 Typesafe Inc. <http://www.typesafe.com> | ||
*/ | ||
package akka.event | ||
|
||
import akka.dispatch.MessageQueue | ||
import akka.dispatch.MailboxType | ||
import akka.dispatch.UnboundedMailbox | ||
import com.typesafe.config.Config | ||
import akka.actor.ActorSystem | ||
import akka.actor.ActorRef | ||
import akka.dispatch.ProducesMessageQueue | ||
|
||
trait LoggerMessageQueueSemantics | ||
|
||
/** | ||
* INTERNAL API | ||
*/ | ||
private[akka] class LoggerMailboxType(settings: ActorSystem.Settings, config: Config) extends MailboxType | ||
with ProducesMessageQueue[LoggerMailbox] { | ||
|
||
override def create(owner: Option[ActorRef], system: Option[ActorSystem]) = (owner, system) match { | ||
case (Some(o), Some(s)) ⇒ new LoggerMailbox(o, s) | ||
case _ ⇒ throw new IllegalArgumentException("no mailbox owner or system given") | ||
} | ||
} | ||
|
||
/** | ||
* INTERNAL API | ||
*/ | ||
private[akka] class LoggerMailbox(owner: ActorRef, system: ActorSystem) | ||
extends UnboundedMailbox.MessageQueue with LoggerMessageQueueSemantics { | ||
|
||
override def cleanUp(owner: ActorRef, deadLetters: MessageQueue): Unit = { | ||
if (hasMessages) { | ||
var envelope = dequeue | ||
// Drain all remaining messages to the StandardOutLogger. | ||
// cleanUp is called after switching out the mailbox, which is why | ||
// this kind of look works without a limit. | ||
while (envelope ne null) { | ||
// Logging.StandardOutLogger is a MinimalActorRef, i.e. not a "real" actor | ||
Logging.StandardOutLogger.tell(envelope.message, envelope.sender) | ||
envelope = dequeue | ||
} | ||
} | ||
super.cleanUp(owner, deadLetters) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters