Here is an example of how you could store stuff in a list using a
persistent actor.
class Example(id: String) extends EventsourcedProcessor {
import Example._
override val processorId = id
var messages = Vector[String]()
def receiveCommand: Receive = {
case RegisterMsg(msg) ⇒
// validation and serious stuff
val evt = MsgRegistered(msg)
persist(evt) { pe ⇒
// here event pe is persisted
apply(pe)
}
}
def receiveRecover: Receive = {
case e: Evt ⇒ apply(e)
}
private def apply(e: Evt) = {
case MsgRegistered(msg) ⇒
messages = msg +: messages
}
}
object Example {
sealed trait Cmd
sealed trait Evt
case class RegisterMsg(msg: String) extends Cmd
case class MsgRegistered(msg: String) extends Evt
def props(id: String): Props =
Props(classOf[Example], id)
}
On Wednesday, June 25, 2014 11:19:17 AM UTC+1, [email protected] wrote:
>
> Hi all
> how to implement persistence actor?
>
> I have an arraylist in actor. all message will be restored in the list.
> I just wonder if the actor restart. How to recover the arraylist's data?
>
--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ:
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.