How to get message causing restart in Akka Persistence
<p>I'm having <code>PersistenceActor</code> and I'd like to do something in it's <code>preRestart</code> method, basing on a message, which caused the restart. For regular actor that would be easy, as there is message passed to <code>preRestart</code> method:</p>

<pre><code>def preRestart(reason: Throwable, message: Option[Any])
</code></pre>

<p>However for <code>PersistentActor</code> that can't be done in that way, because each time <code>None</code> is passed as a message attribute. It is caused by that piece of code in <code>Eventsourced.scala</code>:</p>

<pre><code>override protected[akka] def aroundPreRestart(reason: Throwable, message: Option[Any]): Unit = {
try {
  internalStash.unstashAll()
  unstashAll(unstashFilterPredicate)
} finally {
  message match {
    case Some(WriteMessageSuccess(m, _)) ⇒
      flushJournalBatch()
      super.aroundPreRestart(reason, Some(m))
    case Some(LoopMessageSuccess(m, _)) ⇒
      flushJournalBatch()
      super.aroundPreRestart(reason, Some(m))
    case Some(ReplayedMessage(m)) ⇒
      flushJournalBatch()
      super.aroundPreRestart(reason, Some(m))
    case mo ⇒
      flushJournalBatch()
      super.aroundPreRestart(reason, None)
  }
}
}
</code></pre>

<p>Does anyone know why <code>None</code> is passed there, losing the original message?</p>