per #15423 Remove deprecated features from akka-persistence
* remove channels * remove View * remove Processor * collapse the complicated internal state management that was spread out between Processor, Eventsourced and Recovery * remove Recovery trait, this caused some duplication between Eventsourced and PersistentView, but but the enhanced PersistentView will not be based on recovery infrastructure, and therefore PersistentView code will be replaced anyway * remove PersistentBatch * remove LoopMessage * remove deleteMessages of individual messages * remove Persistent, PersistentRepr and PersistentImpl are kept * remove processorId * update doc sample code * note in migration guide about persistenceId * rename Resequencable to PersistentEnvelope
This commit is contained in:
parent
86a5b3d9d7
commit
c566d5a106
84 changed files with 2162 additions and 9560 deletions
|
|
@ -24,7 +24,7 @@ public class PersistenceDocTest {
|
|||
|
||||
public interface SomeOtherMessage {}
|
||||
|
||||
public interface ProcessorMethods {
|
||||
public interface PersistentActorMethods {
|
||||
//#persistence-id
|
||||
public String persistenceId();
|
||||
//#persistence-id
|
||||
|
|
@ -32,64 +32,25 @@ public class PersistenceDocTest {
|
|||
public boolean recoveryRunning();
|
||||
public boolean recoveryFinished();
|
||||
//#recovery-status
|
||||
//#current-message
|
||||
public Persistent getCurrentPersistentMessage();
|
||||
//#current-message
|
||||
}
|
||||
|
||||
static Object o1 = new Object() {
|
||||
//#definition
|
||||
class MyProcessor extends UntypedProcessor {
|
||||
public void onReceive(Object message) throws Exception {
|
||||
if (message instanceof Persistent) {
|
||||
// message successfully written to journal
|
||||
Persistent persistent = (Persistent)message;
|
||||
Object payload = persistent.payload();
|
||||
Long sequenceNr = persistent.sequenceNr();
|
||||
// ...
|
||||
} else if (message instanceof PersistenceFailure) {
|
||||
// message failed to be written to journal
|
||||
PersistenceFailure failure = (PersistenceFailure)message;
|
||||
Object payload = failure.payload();
|
||||
Long sequenceNr = failure.sequenceNr();
|
||||
Throwable cause = failure.cause();
|
||||
// ...
|
||||
} else if (message instanceof SomeOtherMessage) {
|
||||
// message not written to journal
|
||||
}
|
||||
else {
|
||||
unhandled(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
//#definition
|
||||
|
||||
class MyActor extends UntypedActor {
|
||||
ActorRef processor;
|
||||
|
||||
public MyActor() {
|
||||
//#usage
|
||||
processor = getContext().actorOf(Props.create(MyProcessor.class), "myProcessor");
|
||||
|
||||
processor.tell(Persistent.create("foo"), getSelf());
|
||||
processor.tell("bar", getSelf());
|
||||
//#usage
|
||||
}
|
||||
ActorRef persistentActor;
|
||||
|
||||
public void onReceive(Object message) throws Exception {
|
||||
// ...
|
||||
}
|
||||
|
||||
private void recover() {
|
||||
//#recover-explicit
|
||||
processor.tell(Recover.create(), getSelf());
|
||||
persistentActor.tell(Recover.create(), getSelf());
|
||||
//#recover-explicit
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
static Object o2 = new Object() {
|
||||
abstract class MyProcessor1 extends UntypedPersistentActor {
|
||||
abstract class MyPersistentActor1 extends UntypedPersistentActor {
|
||||
//#recover-on-start-disabled
|
||||
@Override
|
||||
public void preStart() {}
|
||||
|
|
@ -101,7 +62,7 @@ public class PersistenceDocTest {
|
|||
//#recover-on-restart-disabled
|
||||
}
|
||||
|
||||
abstract class MyProcessor2 extends UntypedPersistentActor {
|
||||
abstract class MyPersistentActor2 extends UntypedPersistentActor {
|
||||
//#recover-on-start-custom
|
||||
@Override
|
||||
public void preStart() {
|
||||
|
|
@ -110,19 +71,7 @@ public class PersistenceDocTest {
|
|||
//#recover-on-start-custom
|
||||
}
|
||||
|
||||
abstract class MyProcessor3 extends UntypedPersistentActor {
|
||||
//#deletion
|
||||
@Override
|
||||
public void preRestart(Throwable reason, Option<Object> message) {
|
||||
if (message.isDefined() && message.get() instanceof Persistent) {
|
||||
deleteMessage(((Persistent) message.get()).sequenceNr());
|
||||
}
|
||||
super.preRestart(reason, message);
|
||||
}
|
||||
//#deletion
|
||||
}
|
||||
|
||||
class MyProcessor4 extends UntypedPersistentActor implements ProcessorMethods {
|
||||
class MyPersistentActor4 extends UntypedPersistentActor implements PersistentActorMethods {
|
||||
//#persistence-id-override
|
||||
@Override
|
||||
public String persistenceId() {
|
||||
|
|
@ -135,40 +84,34 @@ public class PersistenceDocTest {
|
|||
public void onReceiveCommand(Object message) throws Exception {}
|
||||
}
|
||||
|
||||
class MyProcessor5 extends UntypedPersistentActor {
|
||||
@Override
|
||||
public String persistenceId() { return "persistence-id"; }
|
||||
|
||||
//#recovery-completed
|
||||
|
||||
@Override
|
||||
public void onReceiveRecover(Object message) {
|
||||
if (message instanceof RecoveryCompleted) {
|
||||
recoveryCompleted();
|
||||
}
|
||||
class MyPersistentActor5 extends UntypedPersistentActor {
|
||||
@Override
|
||||
public String persistenceId() {
|
||||
return "persistence-id";
|
||||
}
|
||||
|
||||
//#recovery-completed
|
||||
@Override
|
||||
public void onReceiveRecover(Object message) {
|
||||
if (message instanceof RecoveryCompleted) {
|
||||
// perform init after recovery, before any other messages
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceiveCommand(Object message) throws Exception {
|
||||
if (message instanceof String) {
|
||||
// ...
|
||||
} else {
|
||||
unhandled(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceiveCommand(Object message) throws Exception {
|
||||
if (message instanceof String) {
|
||||
// ...
|
||||
} else {
|
||||
unhandled(message);
|
||||
}
|
||||
}
|
||||
|
||||
private void recoveryCompleted() {
|
||||
// perform init after recovery, before any other messages
|
||||
// ...
|
||||
}
|
||||
|
||||
//#recovery-completed
|
||||
}
|
||||
//#recovery-completed
|
||||
}
|
||||
};
|
||||
|
||||
static Object fullyDisabledRecoveyExample = new Object() {
|
||||
abstract class MyProcessor1 extends UntypedPersistentActor {
|
||||
static Object fullyDisabledRecoveryExample = new Object() {
|
||||
abstract class MyPersistentActor1 extends UntypedPersistentActor {
|
||||
//#recover-fully-disabled
|
||||
@Override
|
||||
public void preStart() { getSelf().tell(Recover.create(0L), getSelf()); }
|
||||
|
|
@ -215,11 +158,15 @@ public class PersistenceDocTest {
|
|||
|
||||
class MyPersistentActor extends UntypedPersistentActorWithAtLeastOnceDelivery {
|
||||
private final ActorPath destination;
|
||||
|
||||
@Override
|
||||
public String persistenceId() { return "persistence-id"; }
|
||||
|
||||
public MyPersistentActor(ActorPath destination) {
|
||||
this.destination = destination;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceiveCommand(Object message) {
|
||||
if (message instanceof String) {
|
||||
String s = (String) message;
|
||||
|
|
@ -240,6 +187,7 @@ public class PersistenceDocTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceiveRecover(Object event) {
|
||||
updateState(event);
|
||||
}
|
||||
|
|
@ -273,97 +221,16 @@ public class PersistenceDocTest {
|
|||
//#at-least-once-example
|
||||
};
|
||||
|
||||
static Object o3 = new Object() {
|
||||
//#channel-example
|
||||
class MyProcessor extends UntypedProcessor {
|
||||
private final ActorRef destination;
|
||||
private final ActorRef channel;
|
||||
|
||||
public MyProcessor() {
|
||||
this.destination = getContext().actorOf(Props.create(MyDestination.class));
|
||||
this.channel = getContext().actorOf(Channel.props(), "myChannel");
|
||||
}
|
||||
|
||||
public void onReceive(Object message) throws Exception {
|
||||
if (message instanceof Persistent) {
|
||||
Persistent p = (Persistent)message;
|
||||
Persistent out = p.withPayload("done " + p.payload());
|
||||
channel.tell(Deliver.create(out, destination.path()), getSelf());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class MyDestination extends UntypedActor {
|
||||
public void onReceive(Object message) throws Exception {
|
||||
if (message instanceof ConfirmablePersistent) {
|
||||
ConfirmablePersistent p = (ConfirmablePersistent)message;
|
||||
Object payload = p.payload();
|
||||
Long sequenceNr = p.sequenceNr();
|
||||
int redeliveries = p.redeliveries();
|
||||
// ...
|
||||
p.confirm();
|
||||
}
|
||||
}
|
||||
}
|
||||
//#channel-example
|
||||
|
||||
class MyProcessor2 extends UntypedProcessor {
|
||||
private final ActorRef destination;
|
||||
private final ActorRef channel;
|
||||
|
||||
public MyProcessor2(ActorRef destination) {
|
||||
this.destination = getContext().actorOf(Props.create(MyDestination.class));
|
||||
//#channel-id-override
|
||||
this.channel = getContext().actorOf(Channel.props("my-stable-channel-id"));
|
||||
//#channel-id-override
|
||||
|
||||
//#channel-custom-settings
|
||||
getContext().actorOf(Channel.props(
|
||||
ChannelSettings.create()
|
||||
.withRedeliverInterval(Duration.create(30, TimeUnit.SECONDS))
|
||||
.withRedeliverMax(15)));
|
||||
//#channel-custom-settings
|
||||
|
||||
//#channel-custom-listener
|
||||
class MyListener extends UntypedActor {
|
||||
@Override
|
||||
public void onReceive(Object message) throws Exception {
|
||||
if (message instanceof RedeliverFailure) {
|
||||
Iterable<ConfirmablePersistent> messages =
|
||||
((RedeliverFailure)message).getMessages();
|
||||
// ...
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final ActorRef myListener = getContext().actorOf(Props.create(MyListener.class));
|
||||
getContext().actorOf(Channel.props(
|
||||
ChannelSettings.create().withRedeliverFailureListener(null)));
|
||||
//#channel-custom-listener
|
||||
|
||||
}
|
||||
|
||||
public void onReceive(Object message) throws Exception {
|
||||
if (message instanceof Persistent) {
|
||||
Persistent p = (Persistent)message;
|
||||
Persistent out = p.withPayload("done " + p.payload());
|
||||
channel.tell(Deliver.create(out, destination.path()), getSelf());
|
||||
|
||||
//#channel-example-reply
|
||||
channel.tell(Deliver.create(out, getSender().path()), getSelf());
|
||||
//#channel-example-reply
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
static Object o4 = new Object() {
|
||||
//#save-snapshot
|
||||
class MyProcessor extends UntypedProcessor {
|
||||
class MyPersistentActor extends UntypedPersistentActor {
|
||||
@Override
|
||||
public String persistenceId() { return "persistence-id"; }
|
||||
|
||||
//#save-snapshot
|
||||
private Object state;
|
||||
|
||||
@Override
|
||||
public void onReceive(Object message) throws Exception {
|
||||
public void onReceiveCommand(Object message) {
|
||||
if (message.equals("snap")) {
|
||||
saveSnapshot(state);
|
||||
} else if (message instanceof SaveSnapshotSuccess) {
|
||||
|
|
@ -374,32 +241,46 @@ public class PersistenceDocTest {
|
|||
// ...
|
||||
}
|
||||
}
|
||||
//#save-snapshot
|
||||
|
||||
@Override
|
||||
public void onReceiveRecover(Object event) {
|
||||
}
|
||||
}
|
||||
//#save-snapshot
|
||||
|
||||
};
|
||||
|
||||
static Object o5 = new Object() {
|
||||
//#snapshot-offer
|
||||
class MyProcessor extends UntypedProcessor {
|
||||
class MyPersistentActor extends UntypedPersistentActor {
|
||||
@Override
|
||||
public String persistenceId() { return "persistence-id"; }
|
||||
|
||||
//#snapshot-offer
|
||||
private Object state;
|
||||
|
||||
@Override
|
||||
public void onReceive(Object message) throws Exception {
|
||||
public void onReceiveRecover(Object message) {
|
||||
if (message instanceof SnapshotOffer) {
|
||||
state = ((SnapshotOffer)message).snapshot();
|
||||
// ...
|
||||
} else if (message instanceof Persistent) {
|
||||
} else if (message instanceof RecoveryCompleted) {
|
||||
// ...
|
||||
} else {
|
||||
// ...
|
||||
}
|
||||
}
|
||||
//#snapshot-offer
|
||||
|
||||
@Override
|
||||
public void onReceiveCommand(Object message) {
|
||||
}
|
||||
}
|
||||
//#snapshot-offer
|
||||
|
||||
class MyActor extends UntypedActor {
|
||||
ActorRef processor;
|
||||
ActorRef persistentActor;
|
||||
|
||||
public MyActor() {
|
||||
processor = getContext().actorOf(Props.create(MyProcessor.class));
|
||||
persistentActor = getContext().actorOf(Props.create(MyPersistentActor.class));
|
||||
}
|
||||
|
||||
public void onReceive(Object message) throws Exception {
|
||||
|
|
@ -408,105 +289,13 @@ public class PersistenceDocTest {
|
|||
|
||||
private void recover() {
|
||||
//#snapshot-criteria
|
||||
processor.tell(Recover.create(SnapshotSelectionCriteria.create(457L, System.currentTimeMillis())), null);
|
||||
persistentActor.tell(Recover.create(SnapshotSelectionCriteria.create(457L,
|
||||
System.currentTimeMillis())), null);
|
||||
//#snapshot-criteria
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
static Object o6 = new Object() {
|
||||
//#batch-write
|
||||
class MyProcessor extends UntypedProcessor {
|
||||
public void onReceive(Object message) throws Exception {
|
||||
if (message instanceof Persistent) {
|
||||
Persistent p = (Persistent)message;
|
||||
if (p.payload().equals("a")) { /* ... */ }
|
||||
if (p.payload().equals("b")) { /* ... */ }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Example {
|
||||
final ActorSystem system = ActorSystem.create("example");
|
||||
final ActorRef processor = system.actorOf(Props.create(MyProcessor.class));
|
||||
|
||||
public void batchWrite() {
|
||||
processor.tell(PersistentBatch.create(asList(
|
||||
Persistent.create("a"),
|
||||
Persistent.create("b"))), null);
|
||||
}
|
||||
|
||||
// ...
|
||||
}
|
||||
//#batch-write
|
||||
};
|
||||
|
||||
static Object o7 = new Object() {
|
||||
abstract class MyProcessor extends UntypedProcessor {
|
||||
ActorRef destination;
|
||||
|
||||
public void foo() {
|
||||
//#persistent-channel-example
|
||||
final ActorRef channel = getContext().actorOf(PersistentChannel.props(
|
||||
PersistentChannelSettings.create()
|
||||
.withRedeliverInterval(Duration.create(30, TimeUnit.SECONDS))
|
||||
.withRedeliverMax(15)), "myPersistentChannel");
|
||||
|
||||
channel.tell(Deliver.create(Persistent.create("example"), destination.path()), getSelf());
|
||||
//#persistent-channel-example
|
||||
//#persistent-channel-watermarks
|
||||
PersistentChannelSettings.create()
|
||||
.withPendingConfirmationsMax(10000)
|
||||
.withPendingConfirmationsMin(2000);
|
||||
//#persistent-channel-watermarks
|
||||
//#persistent-channel-reply
|
||||
PersistentChannelSettings.create().withReplyPersistent(true);
|
||||
//#persistent-channel-reply
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
static Object o8 = new Object() {
|
||||
//#reliable-event-delivery
|
||||
class MyPersistentActor extends UntypedPersistentActor {
|
||||
@Override
|
||||
public String persistenceId() { return "some-persistence-id"; }
|
||||
|
||||
private ActorRef destination;
|
||||
private ActorRef channel;
|
||||
|
||||
public MyPersistentActor(ActorRef destination) {
|
||||
this.destination = destination;
|
||||
this.channel = getContext().actorOf(Channel.props(), "channel");
|
||||
}
|
||||
|
||||
private void handleEvent(String event) {
|
||||
// update state
|
||||
// ...
|
||||
// reliably deliver events
|
||||
channel.tell(Deliver.create(Persistent.create(
|
||||
event, getCurrentPersistentMessage()), destination.path()), getSelf());
|
||||
}
|
||||
|
||||
public void onReceiveRecover(Object msg) {
|
||||
if (msg instanceof String) {
|
||||
handleEvent((String)msg);
|
||||
}
|
||||
}
|
||||
|
||||
public void onReceiveCommand(Object msg) {
|
||||
if (msg.equals("cmd")) {
|
||||
persist("evt", new Procedure<String>() {
|
||||
public void apply(String event) {
|
||||
handleEvent(event);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
//#reliable-event-delivery
|
||||
};
|
||||
|
||||
static Object o9 = new Object() {
|
||||
//#persist-async
|
||||
class MyPersistentActor extends UntypedPersistentActor {
|
||||
|
|
@ -541,9 +330,9 @@ public class PersistenceDocTest {
|
|||
public void usage() {
|
||||
final ActorSystem system = ActorSystem.create("example");
|
||||
//#persist-async-usage
|
||||
final ActorRef processor = system.actorOf(Props.create(MyPersistentActor.class));
|
||||
processor.tell("a", null);
|
||||
processor.tell("b", null);
|
||||
final ActorRef persistentActor = system.actorOf(Props.create(MyPersistentActor.class));
|
||||
persistentActor.tell("a", null);
|
||||
persistentActor.tell("b", null);
|
||||
|
||||
// possible order of received messages:
|
||||
// a
|
||||
|
|
@ -586,9 +375,9 @@ public class PersistenceDocTest {
|
|||
public void usage() {
|
||||
final ActorSystem system = ActorSystem.create("example");
|
||||
//#defer-caller
|
||||
final ActorRef processor = system.actorOf(Props.create(MyPersistentActor.class));
|
||||
processor.tell("a", null);
|
||||
processor.tell("b", null);
|
||||
final ActorRef persistentActor = system.actorOf(Props.create(MyPersistentActor.class));
|
||||
persistentActor.tell("a", null);
|
||||
persistentActor.tell("b", null);
|
||||
|
||||
// order of received messages:
|
||||
// a
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue