2016-11-09 46 views
2

我有PersistenceActor,我想在preRestart方法中根據消息執行某些操作,從而導致重新啓動。對於普通的演員,這將是容易的,因爲有消息傳遞給preRestart方法:如何獲取導致在Akka持續時間重新啓動的消息

def preRestart(reason: Throwable, message: Option[Any]) 

但是對於PersistentActor不能以這種方式來完成,因爲每次None被作爲消息傳遞的屬性。它是由Eventsourced.scala這段代碼造成的:

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) 
    } 
} 
} 

有誰知道爲什麼None傳遞那裏,失去了原有的信息?

回答

相關問題