Last active
August 29, 2015 14:21
-
-
Save mrbrdo/7ca653cd57a68b466d73 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// doesn't work | |
val receiveReplica: Receive = withPersistence { (sender, key, id) => sender ! SnapshotAck(key, id) } { | |
var expectedSeq = 0 | |
{ | |
case Get(key, id) => | |
sender ! GetResult(key, kv.get(key), id) | |
case OperationTimeout(seq) => | |
persisting.get(seq).foreach { | |
case PersistingValue(_, timer, _, _) => | |
timer.cancel() | |
persisting -= seq | |
} | |
case msg@Snapshot(key, _, seq) if seq < expectedSeq => | |
sender ! SnapshotAck(key, seq) | |
case msg@Snapshot(key, valueOption, seq) if seq == expectedSeq => | |
persist(key, valueOption, seq, Set.empty[ActorRef]) | |
setOperationTimeout(seq) | |
expectedSeq += 1 | |
if (valueOption.isDefined) | |
kv = kv.updated(key, valueOption.get) | |
else | |
kv -= key | |
} | |
} | |
// works | |
val receiveReplica: Receive = withPersistence { (sender, key, id) => sender ! SnapshotAck(key, id) } { | |
var expectedSeq = 0 | |
{ | |
case Get(key, id) => | |
sender ! GetResult(key, kv.get(key), id) | |
case OperationTimeout(seq) => | |
persisting.get(seq).foreach { | |
case PersistingValue(_, timer, _, _) => | |
timer.cancel() | |
persisting -= seq | |
} | |
case msg@Snapshot(key, _, seq) if seq < expectedSeq => | |
sender ! SnapshotAck(key, seq) | |
case msg@Snapshot(key, valueOption, seq) if seq == expectedSeq => | |
persist(key, valueOption, seq, Set.empty[ActorRef]) | |
setOperationTimeout(seq) | |
expectedSeq += 1 | |
if (valueOption.isDefined) | |
kv = kv.updated(key, valueOption.get) | |
else | |
kv -= key | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment