I play with akka persistence, trying to implement a service where my condition is potentially a very large (well, let it be said that this will not fit in RAM) list of some objects. Suppose a user wants the whole story to be accessible to all entities. Can I do it with the stubbornness of an aka?
Now my state of the actor looks like this.
case class System(var processes: Map[Long, Process] = Map()) {
def updated(event: Event): System = event match {
case ProcessDetectedEvent(time, activitySets, id, processType) =>
val process = Process(activitySets.coordinates, time, activitySets.channels, id, processType, false)
copy(processes = processes + (id -> process))
case ProcessMovedEvent(id, activitySets, time) =>
val process = Process(activitySets.coordinates, time, activitySets.channels, id, processes(id).processType, false)
copy(processes = processes + (id -> process))
case ProcessClosedEvent(time, id) =>
val currentProcess = processes(id)
val process = Process(currentProcess.coordinates, time, currentProcess.channels, id, currentProcess.processType, true)
copy(processes = processes + (id -> process))
case _ => this
}
}
As you can see, the process map is stored in memory, so the application can end without memory if the number of processes is large.
source
share