no.nextgentel.oss.akkatools.aggregate.GeneralAggregateView.scala Maven / Gradle / Ivy
package no.nextgentel.oss.akkatools.aggregate
import no.nextgentel.oss.akkatools.persistence.{EnhancedPersistentView, GetState}
import scala.reflect.ClassTag
class GeneralAggregateView[E:ClassTag, S <: AggregateStateBase[E, S]:ClassTag]
(
persistenceIdBase:String,
id:String,
initialState:S,
collectHistory:Boolean = true
) extends EnhancedPersistentView[E, S](persistenceIdBase, id, collectHistory) {
var state:S = initialState
override def currentState():S = state
override def applyEventToState(event: E): Unit = {
state = state.transitionState(event).newState
}
override val onCmd: PartialFunction[AnyRef, Unit] = {
case x:GetState =>
sender ! state
}
}