Fix #16364 - Doc - Persistent actor - clarification of the recovery customization

This commit is contained in:
Marek Prochera 2014-11-21 16:59:21 +01:00
parent f2487d73f4
commit b43f3639d6
4 changed files with 44 additions and 11 deletions

View file

@ -71,8 +71,8 @@ public class PersistenceDocTest {
//#usage //#usage
processor = getContext().actorOf(Props.create(MyProcessor.class), "myProcessor"); processor = getContext().actorOf(Props.create(MyProcessor.class), "myProcessor");
processor.tell(Persistent.create("foo"), null); processor.tell(Persistent.create("foo"), getSelf());
processor.tell("bar", null); processor.tell("bar", getSelf());
//#usage //#usage
} }
@ -82,7 +82,7 @@ public class PersistenceDocTest {
private void recover() { private void recover() {
//#recover-explicit //#recover-explicit
processor.tell(Recover.create(), null); processor.tell(Recover.create(), getSelf());
//#recover-explicit //#recover-explicit
} }
} }
@ -105,7 +105,7 @@ public class PersistenceDocTest {
//#recover-on-start-custom //#recover-on-start-custom
@Override @Override
public void preStart() { public void preStart() {
getSelf().tell(Recover.create(457L), null); getSelf().tell(Recover.create(457L), getSelf());
} }
//#recover-on-start-custom //#recover-on-start-custom
} }
@ -166,6 +166,15 @@ public class PersistenceDocTest {
//#recovery-completed //#recovery-completed
} }
}; };
static Object fullyDisabledRecoveyExample = new Object() {
abstract class MyProcessor1 extends UntypedPersistentActor {
//#recover-fully-disabled
@Override
public void preStart() { getSelf().tell(Recover.create(0L), getSelf()); }
//#recover-fully-disabled
}
};
static Object atLeastOnceExample = new Object() { static Object atLeastOnceExample = new Object() {
//#at-least-once-example //#at-least-once-example
@ -563,7 +572,7 @@ public class PersistenceDocTest {
final Procedure<String> replyToSender = new Procedure<String>() { final Procedure<String> replyToSender = new Procedure<String>() {
@Override @Override
public void apply(String event) throws Exception { public void apply(String event) throws Exception {
sender().tell(event, self()); sender().tell(event, getSelf());
} }
}; };

View file

@ -148,13 +148,13 @@ Recovery
-------- --------
By default, a persistent actor is automatically recovered on start and on restart by replaying journaled messages. By default, a persistent actor is automatically recovered on start and on restart by replaying journaled messages.
New messages sent to a persistent actor during recovery do not interfere with replayed messages. New messages will New messages sent to a persistent actor during recovery do not interfere with replayed messages.
only be received by a persistent actor after recovery completes. They are cached and received by a persistent actor after recovery phase completes.
Recovery customization Recovery customization
^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^
Automated recovery on start can be disabled by overriding ``preStart`` with an empty implementation. Automated recovery on start can be disabled by overriding ``preStart`` with an empty or custom implementation.
.. includecode:: code/docs/persistence/PersistenceDocTest.java#recover-on-start-disabled .. includecode:: code/docs/persistence/PersistenceDocTest.java#recover-on-start-disabled
@ -162,6 +162,14 @@ In this case, a persistent actor must be recovered explicitly by sending it a ``
.. includecode:: code/docs/persistence/PersistenceDocTest.java#recover-explicit .. includecode:: code/docs/persistence/PersistenceDocTest.java#recover-explicit
.. warning::
If ``preStart`` is overriden by an empty implementation, incoming commands will not be processed by the
``PersistentActor`` until it receives a ``Recover`` and finishes recovery.
In order to completely skip recovery, you can signal it with ``Recover.create(0L)``
.. includecode:: code/docs/persistence/PersistenceDocTest.java#recover-fully-disabled
If not overridden, ``preStart`` sends a ``Recover`` message to ``getSelf()``. Applications may also override If not overridden, ``preStart`` sends a ``Recover`` message to ``getSelf()``. Applications may also override
``preStart`` to define further ``Recover`` parameters such as an upper sequence number bound, for example. ``preStart`` to define further ``Recover`` parameters such as an upper sequence number bound, for example.

View file

@ -110,6 +110,14 @@ trait PersistenceDocSpec {
} }
} }
new AnyRef {
trait MyProcessor1 extends PersistentActor {
//#recover-fully-disabled
override def preStart() = self ! Recover(toSequenceNr = 0L)
//#recover-fully-disabled
}
}
new AnyRef { new AnyRef {
trait ProcessorMethods { trait ProcessorMethods {
//#persistence-id //#persistence-id

View file

@ -139,13 +139,13 @@ Recovery
-------- --------
By default, a persistent actor is automatically recovered on start and on restart by replaying journaled messages. By default, a persistent actor is automatically recovered on start and on restart by replaying journaled messages.
New messages sent to a persistent actor during recovery do not interfere with replayed messages. New messages will New messages sent to a persistent actor during recovery do not interfere with replayed messages.
only be received by a persistent actor after recovery completes. They are cached and received by a persistent actor after recovery phase completes.
Recovery customization Recovery customization
^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^
Automated recovery on start can be disabled by overriding ``preStart`` with an empty implementation. Automated recovery on start can be disabled by overriding ``preStart`` with an empty or custom implementation.
.. includecode:: code/docs/persistence/PersistenceDocSpec.scala#recover-on-start-disabled .. includecode:: code/docs/persistence/PersistenceDocSpec.scala#recover-on-start-disabled
@ -153,6 +153,14 @@ In this case, a persistent actor must be recovered explicitly by sending it a ``
.. includecode:: code/docs/persistence/PersistenceDocSpec.scala#recover-explicit .. includecode:: code/docs/persistence/PersistenceDocSpec.scala#recover-explicit
.. warning::
If ``preStart`` is overriden by an empty implementation, incoming commands will not be processed by the
``PersistentActor`` until it receives a ``Recover`` and finishes recovery.
In order to completely skip recovery, you can signal it with ``Recover(toSequenceNr = OL)``
.. includecode:: code/docs/persistence/PersistenceDocSpec.scala#recover-fully-disabled
If not overridden, ``preStart`` sends a ``Recover()`` message to ``self``. Applications may also override If not overridden, ``preStart`` sends a ``Recover()`` message to ``self``. Applications may also override
``preStart`` to define further ``Recover()`` parameters such as an upper sequence number bound, for example. ``preStart`` to define further ``Recover()`` parameters such as an upper sequence number bound, for example.