+per #13944 Send RecoveryComplete message at end of recovery

Fixes #13944

Conflicts:
	akka-docs/rst/scala/code/docs/persistence/PersistenceDocSpec.scala
	akka-persistence/src/main/scala/akka/persistence/Processor.scala
	project/AkkaBuild.scala
This commit is contained in:
Björn Antonsson 2014-06-05 14:07:17 +02:00
parent 3c9483520a
commit 9bcaeff87d
14 changed files with 223 additions and 81 deletions

View file

@ -19,6 +19,8 @@ import static java.util.Arrays.asList;
public class PersistenceDocTest {
public interface SomeOtherMessage {}
public interface ProcessorMethods {
//#processor-id
public String processorId();
@ -49,9 +51,12 @@ public class PersistenceDocTest {
Long sequenceNr = failure.sequenceNr();
Throwable cause = failure.cause();
// ...
} else {
} else if (message instanceof SomeOtherMessage) {
// message not written to journal
}
else {
unhandled(message);
}
}
}
//#definition
@ -127,21 +132,12 @@ public class PersistenceDocTest {
class MyProcessor5 extends UntypedProcessor {
//#recovery-completed
@Override
public void preStart() throws Exception {
super.preStart();
self().tell("FIRST", self());
}
public void onReceive(Object message) throws Exception {
if (message.equals("FIRST")) {
if (message instanceof RecoveryCompleted) {
recoveryCompleted();
getContext().become(active);
unstashAll();
} else if (recoveryFinished()) {
stash();
} else {
active.apply(message);
unhandled(message);
}
}
@ -156,6 +152,9 @@ public class PersistenceDocTest {
if (message instanceof Persistent) {
// ...
}
else {
unhandled(message);
}
}
};
//#recovery-completed

View file

@ -124,9 +124,11 @@ A processor can query its own recovery status via the methods
Sometimes there is a need for performing additional initialization when the
recovery has completed, before processing any other message sent to the processor.
The processor can send itself a message from ``preStart``. It will be stashed and received
after recovery. The mailbox may contain other messages that are queued in front of
that message and therefore you need to stash until you receive that message.
The processor will receive a special :class:`RecoveryCompleted` message right after recovery
and before any other received messages. If there is a problem with recovering the state of
the actor from the journal, the actor will be sent a :class:`RecoveryFailure` message that
it can choose to handle. If the actor doesn't handle the :class:`RecoveryFailure` message it
will be stopped.
.. includecode:: ../../../akka-samples/akka-sample-persistence-java-lambda/src/main/java/doc/LambdaPersistenceDocTest.java#recovery-completed

View file

@ -143,9 +143,11 @@ A processor can query its own recovery status via the methods
Sometimes there is a need for performing additional initialization when the
recovery has completed, before processing any other message sent to the processor.
The processor can send itself a message from ``preStart``. It will be stashed and received
after recovery. The mailbox may contain other messages that are queued in front of
that message and therefore you need to stash until you receive that message.
The processor will receive a special :class:`RecoveryCompleted` message right after recovery
and before any other received messages. If there is a problem with recovering the state of
the actor from the journal, the actor will be sent a :class:`RecoveryFailure` message that
it can choose to handle. If the actor doesn't handle the :class:`RecoveryFailure` message it
will be stopped.
.. includecode:: code/docs/persistence/PersistenceDocTest.java#recovery-completed

View file

@ -21,6 +21,8 @@ trait PersistenceDocSpec {
//#auto-update
"""
trait SomeOtherMessage
val system: ActorSystem
import system._
@ -35,7 +37,7 @@ trait PersistenceDocSpec {
// message successfully written to journal
case PersistenceFailure(payload, sequenceNr, cause) =>
// message failed to be written to journal
case other =>
case m: SomeOtherMessage =>
// message not written to journal
}
}
@ -87,20 +89,12 @@ trait PersistenceDocSpec {
class MyProcessor4 extends Processor {
//#recovery-completed
override def preStart(): Unit = {
super.preStart()
self ! "FIRST"
}
def receive = initializing.orElse(active)
def receive = initializing
def initializing: Receive = {
case "FIRST" =>
case RecoveryCompleted =>
recoveryCompleted()
context.become(active)
unstashAll()
case other if recoveryFinished =>
stash()
}
def recoveryCompleted(): Unit = {

View file

@ -132,9 +132,11 @@ A processor can query its own recovery status via the methods
Sometimes there is a need for performing additional initialization when the
recovery has completed, before processing any other message sent to the processor.
The processor can send itself a message from ``preStart``. It will be stashed and received
after recovery. The mailbox may contain other messages that are queued in front of
that message and therefore you need to stash until you receive that message.
The processor will receive a special :class:`RecoveryCompleted` message right after recovery
and before any other received messages. If there is a problem with recovering the state of
the actor from the journal, the actor will be sent a :class:`RecoveryFailure` message that
it can choose to handle. If the actor doesn't handle the :class:`RecoveryFailure` message it
will be stopped.
.. includecode:: code/docs/persistence/PersistenceDocSpec.scala#recovery-completed