Merge pull request #26519 from akka/wip-26273-persistence-javadsl-patriknw
add missing API in javadsl.EventSourcedBehavior, #26273
This commit is contained in:
commit
875170d2cf
2 changed files with 68 additions and 2 deletions
|
|
@ -14,6 +14,7 @@ import akka.actor.typed.Behavior.DeferredBehavior
|
|||
import akka.actor.typed.javadsl.ActorContext
|
||||
import akka.annotation.ApiMayChange
|
||||
import akka.annotation.InternalApi
|
||||
import akka.persistence.SnapshotSelectionCriteria
|
||||
import akka.persistence.typed.EventAdapter
|
||||
import akka.persistence.typed._
|
||||
import akka.persistence.typed.internal._
|
||||
|
|
@ -121,6 +122,26 @@ abstract class EventSourcedBehavior[Command, Event, State >: Null] private[akka]
|
|||
*/
|
||||
def shouldSnapshot(state: State, event: Event, sequenceNr: Long): Boolean = false
|
||||
|
||||
/**
|
||||
* Override and define the journal plugin id that this actor should use instead of the default.
|
||||
*/
|
||||
def journalPluginId: String = ""
|
||||
|
||||
/**
|
||||
* Override and define the snapshot store plugin id that this actor should use instead of the default.
|
||||
*/
|
||||
def snapshotPluginId: String = ""
|
||||
|
||||
/**
|
||||
* Override and define the snapshot selection criteria used by this actor instead of the default.
|
||||
* By default the most recent snapshot is used, and the remaining state updates are recovered by replaying events
|
||||
* from the sequence number up until which the snapshot reached.
|
||||
*
|
||||
* You may configure the behavior to skip replaying snapshots completely, in which case the recovery will be
|
||||
* performed by replaying all events -- which may take a long time.
|
||||
*/
|
||||
def snapshotSelectionCriteria: SnapshotSelectionCriteria = SnapshotSelectionCriteria.Latest
|
||||
|
||||
/**
|
||||
* The `tagger` function should give event tags, which will be used in persistence query
|
||||
*/
|
||||
|
|
@ -154,7 +175,13 @@ abstract class EventSourcedBehavior[Command, Event, State >: Null] private[akka]
|
|||
emptyState,
|
||||
(state, cmd) => commandHandler()(state, cmd).asInstanceOf[EffectImpl[Event, State]],
|
||||
eventHandler()(_, _),
|
||||
getClass).snapshotWhen(snapshotWhen).withTagger(tagger).eventAdapter(eventAdapter())
|
||||
getClass)
|
||||
.snapshotWhen(snapshotWhen)
|
||||
.withTagger(tagger)
|
||||
.eventAdapter(eventAdapter())
|
||||
.withJournalPluginId(journalPluginId)
|
||||
.withSnapshotPluginId(snapshotPluginId)
|
||||
.withSnapshotSelectionCriteria(snapshotSelectionCriteria)
|
||||
|
||||
val handler = signalHandler()
|
||||
val behaviorWithSignalHandler =
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import akka.actor.typed.Behavior;
|
|||
import akka.actor.typed.javadsl.ActorContext;
|
||||
import akka.actor.typed.ActorRef;
|
||||
import akka.actor.typed.javadsl.Behaviors;
|
||||
import akka.persistence.SnapshotSelectionCriteria;
|
||||
import akka.persistence.typed.EventAdapter;
|
||||
import akka.actor.testkit.typed.javadsl.TestInbox;
|
||||
import akka.persistence.typed.PersistenceId;
|
||||
|
|
@ -100,7 +101,7 @@ public class PersistentActorCompileOnlyTest {
|
|||
|
||||
@Override
|
||||
public EventHandler<SimpleState, SimpleEvent> eventHandler() {
|
||||
return (state, event) -> state.addEvent(event);
|
||||
return SimpleState::addEvent;
|
||||
}
|
||||
|
||||
// #install-event-adapter
|
||||
|
|
@ -110,6 +111,44 @@ public class PersistentActorCompileOnlyTest {
|
|||
}
|
||||
// #install-event-adapter
|
||||
};
|
||||
|
||||
static class AdditionalSettings
|
||||
extends EventSourcedBehavior<SimpleCommand, SimpleEvent, SimpleState> {
|
||||
|
||||
public AdditionalSettings(PersistenceId persistenceId) {
|
||||
super(new PersistenceId("p1"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public SimpleState emptyState() {
|
||||
return new SimpleState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandHandler<SimpleCommand, SimpleEvent, SimpleState> commandHandler() {
|
||||
return (state, cmd) -> Effect().persist(new SimpleEvent(cmd.data));
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventHandler<SimpleState, SimpleEvent> eventHandler() {
|
||||
return SimpleState::addEvent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SnapshotSelectionCriteria snapshotSelectionCriteria() {
|
||||
return SnapshotSelectionCriteria.none();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String journalPluginId() {
|
||||
return "other.journal";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String snapshotPluginId() {
|
||||
return "other.snapshot-store";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
abstract static class WithAck {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue