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
case class IncRollsCount(rolledNumber: Int) extends Command | |
case class RollsCountIncreased(rolledNumber: Int) extends Event | |
case object GetState extends Command | |
class StatsActor extends PersistentActor { | |
override val persistenceId = "rolls_stats" | |
var state: Stats = Stats(Map.empty) | |
def applyEvent(event: Event) = event match { | |
case RollsCountIncreased(rolledNumber) => | |
state = state.incRollsCount(rolledNumber) | |
} | |
override def receiveCommand = { | |
case IncRollsCount(rolledNumber) => | |
persist(RollsCountIncreased(rolledNumber))(applyEvent) | |
case GetState => | |
sender() ! state | |
} | |
override def receiveRecover = { | |
case ev: Event => applyEvent(ev) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment