Skip to content

Commit 306cd43

Browse files
authored
try to reduce confusion about signals in persistence implementations (#2585)
* try to reduce confusion about signals in persistence implementations * Update persistence.md
1 parent fd396a6 commit 306cd43

File tree

4 files changed

+11
-6
lines changed

4 files changed

+11
-6
lines changed

docs/src/main/paradox/typed/durable-state/persistence.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,13 @@ Scala
199199
Java
200200
: @@snip [PersistentActorCompileOnlyTest.java](/persistence-typed/src/test/java/org/apache/pekko/persistence/typed/javadsl/PersistentActorCompileOnlyTest.java) { #commonChainedEffects }
201201

202+
### DurableStateBehavior receiveSignal/signalHandler
203+
204+
DurableStateBehavior supports receiveSignal/signalHandler in a similar way to EventSourcedBehavior but the signal classes are in the `org.apache.pekko.persistence.typed.state` package not the `org.apache.pekko.persistence.typed` package. These are the only `DurableStateSignal` signals and note that the class names match equivalent `EventSourcedSignal` classes but you need to use these ones for DurableStateBehavior:
205+
206+
* @apidoc[pekko.persistence.typed.state.RecoveryCompleted] signal
207+
* @apidoc[pekko.persistence.typed.state.RecoveryFailed] signal
208+
202209
### Side effects ordering and guarantees
203210

204211
Any side effects are executed on an at-most-once basis and will not be executed if the persist fails.

docs/src/main/paradox/typed/persistence.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ pekko.persistence.max-concurrent-recoveries = 50
471471
The @ref:[event handler](#event-handler) is used for updating the state when replaying the journaled events.
472472

473473
It is strongly discouraged to perform side effects in the event handler, so side effects should be performed
474-
once recovery has completed as a reaction to the @apidoc[typed.RecoveryCompleted] signal @scala[in the @scaladoc[receiveSignal](pekko.persistence.typed.scaladsl.EventSourcedBehavior#receiveSignal(signalHandler:PartialFunction[(State,org.apache.pekko.actor.typed.Signal),Unit]):org.apache.pekko.persistence.typed.scaladsl.EventSourcedBehavior[Command,Event,State]) handler] @java[by overriding @javadoc[receiveSignal](pekko.persistence.typed.javadsl.SignalHandlerBuilder#onSignal(java.lang.Class,java.util.function.BiConsumer))]
474+
once recovery has completed as a reaction to the @apidoc[typed.RecoveryCompleted] signal @scala[in the @scaladoc[receiveSignal](pekko.persistence.typed.scaladsl.EventSourcedBehavior#receiveSignal(signalHandler:PartialFunction[(State,org.apache.pekko.actor.typed.Signal),Unit]):org.apache.pekko.persistence.typed.scaladsl.EventSourcedBehavior[Command,Event,State]) handler] @java[by overriding @javadoc[signalHandler](pekko.persistence.typed.javadsl.SignalHandlerBuilder#onSignal(java.lang.Class,java.util.function.BiConsumer))]
475475

476476
Scala
477477
: @@snip [BasicPersistentBehaviorCompileOnly.scala](/persistence-typed/src/test/scala/docs/org/apache/pekko/persistence/typed/BasicPersistentBehaviorCompileOnly.scala) { #recovery }
@@ -481,7 +481,7 @@ Java
481481

482482
The `RecoveryCompleted` contains the current `State`.
483483

484-
The actor will always receive a `RecoveryCompleted` signal, even if there are no events
484+
The actor will always receive a @apidoc[typed.RecoveryCompleted] signal, even if there are no events
485485
in the journal and the snapshot store is empty, or if it's a new persistent actor with a previously
486486
unused `PersistenceId`.
487487

persistence-typed/src/test/java/jdocs/org/apache/pekko/persistence/typed/BasicPersistentBehaviorTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import org.apache.pekko.actor.typed.javadsl.Behaviors;
2121
import org.apache.pekko.persistence.typed.DeleteEventsFailed;
2222
import org.apache.pekko.persistence.typed.DeleteSnapshotsFailed;
23-
import org.apache.pekko.persistence.typed.RecoveryCompleted;
2423
import org.apache.pekko.persistence.typed.SnapshotFailed;
2524
import org.apache.pekko.persistence.typed.SnapshotSelectionCriteria;
2625
import org.apache.pekko.persistence.typed.javadsl.CommandHandler;
@@ -347,7 +346,7 @@ public EventHandler<State, Event> eventHandler() {
347346
public SignalHandler<State> signalHandler() {
348347
return newSignalHandlerBuilder()
349348
.onSignal(
350-
RecoveryCompleted.instance(),
349+
org.apache.pekko.persistence.typed.RecoveryCompleted.instance(),
351350
state -> {
352351
throw new RuntimeException("TODO: add some end-of-recovery side-effect here");
353352
})

persistence-typed/src/test/scala/docs/org/apache/pekko/persistence/typed/BasicPersistentBehaviorCompileOnly.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ import pekko.persistence.typed.PersistenceId
3535
//#behavior
3636
//#structure
3737
import org.apache.pekko
38-
import pekko.persistence.typed.RecoveryCompleted
3938
import pekko.persistence.typed.SnapshotFailed
4039
import scala.annotation.nowarn
4140

@@ -128,7 +127,7 @@ object BasicPersistentBehaviorCompileOnly {
128127
commandHandler = (state, cmd) => throw new NotImplementedError("TODO: process the command & return an Effect"),
129128
eventHandler = (state, evt) => throw new NotImplementedError("TODO: process the event return the next state"))
130129
.receiveSignal {
131-
case (state, RecoveryCompleted) =>
130+
case (state, pekko.persistence.typed.RecoveryCompleted) =>
132131
throw new NotImplementedError("TODO: add some end-of-recovery side-effect here")
133132
}
134133
// #recovery

0 commit comments

Comments
 (0)