+per #15424 Added PersistentView, deprecated View
A PersistentView works the same way as View did previously, except: * it requires an `peristenceId` (no default is provided) * messages given to `receive` are NOT wrapped in Persistent() akka-streams not touched, will update them afterwards on different branch Also solves #15436 by making persistentId in PersistentView abstract. (cherry picked from commit dcafaf788236fe6d018388dd55d5bf9650ded696) Conflicts: akka-docs/rst/java/lambda-persistence.rst akka-docs/rst/java/persistence.rst akka-docs/rst/scala/persistence.rst akka-persistence/src/main/scala/akka/persistence/Persistent.scala akka-persistence/src/main/scala/akka/persistence/View.scala
This commit is contained in:
parent
2203968adb
commit
3fd240384c
22 changed files with 847 additions and 192 deletions
|
|
@ -485,18 +485,21 @@ public class PersistenceDocTest {
|
|||
|
||||
static Object o11 = new Object() {
|
||||
//#view
|
||||
class MyView extends UntypedView {
|
||||
@Override
|
||||
public String persistenceId() {
|
||||
return "some-persistence-id";
|
||||
}
|
||||
class MyView extends UntypedPersistentView {
|
||||
@Override public String viewId() { return "some-persistence-id-view"; }
|
||||
@Override public String persistenceId() { return "some-persistence-id"; }
|
||||
|
||||
@Override
|
||||
public void onReceive(Object message) throws Exception {
|
||||
if (message instanceof Persistent) {
|
||||
// ...
|
||||
if (isPersistent()) {
|
||||
// handle message from Journal...
|
||||
} else if (message instanceof String) {
|
||||
// handle message from user...
|
||||
} else {
|
||||
unhandled(message);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
//#view
|
||||
|
||||
|
|
|
|||
|
|
@ -26,6 +26,17 @@ Akka persistence is inspired by the `eventsourced`_ library. It follows the same
|
|||
|
||||
.. _eventsourced: https://github.com/eligosource/eventsourced
|
||||
|
||||
Changes in Akka 2.3.4
|
||||
=====================
|
||||
|
||||
In Akka 2.3.4 several of the concepts of the earlier versions were collapsed and simplified.
|
||||
In essence; ``Processor`` and ``EventsourcedProcessor`` are replaced by ``PersistentActor``. ``Channel``
|
||||
and ``PersistentChannel`` are replaced by ``AtLeastOnceDelivery``. ``View`` is replaced by ``PersistentView``.
|
||||
|
||||
See full details of the changes in the :ref:`migration-guide-persistence-experimental-2.3.x-2.4.x`.
|
||||
The old classes are still included, and deprecated, for a while to make the transition smooth.
|
||||
In case you need the old documentation it is located `here <http://doc.akka.io/docs/akka/2.3.3/java/lambda-persistence.html#persistence-lambda-java>`_.
|
||||
|
||||
Dependencies
|
||||
============
|
||||
|
||||
|
|
@ -45,7 +56,7 @@ Architecture
|
|||
When a persistent actor is started or restarted, journaled messages are replayed to that actor, so that it can
|
||||
recover internal state from these messages.
|
||||
|
||||
* *View*: A view is a persistent, stateful actor that receives journaled messages that have been written by another
|
||||
* *AbstractPersistentView*: A view is a persistent, stateful actor that receives journaled messages that have been written by another
|
||||
persistent actor. A view itself does not journal new messages, instead, it updates internal state only from a persistent actor's
|
||||
replicated message stream.
|
||||
|
||||
|
|
@ -260,12 +271,12 @@ to Akka persistence will allow to replay messages that have been marked as delet
|
|||
purposes, for example. To delete all messages (journaled by a single persistent actor) up to a specified sequence number,
|
||||
persistent actors should call the ``deleteMessages`` method.
|
||||
|
||||
.. _views-java-lambda:
|
||||
.. _persistent-views-java-lambda:
|
||||
|
||||
Views
|
||||
=====
|
||||
|
||||
Views can be implemented by extending the ``AbstractView`` abstract class, implement the ``persistenceId`` method
|
||||
Persistent views can be implemented by extending the ``AbstractView`` abstract class, implement the ``persistenceId`` method
|
||||
and setting the “initial behavior” in the constructor by calling the :meth:`receive` method.
|
||||
|
||||
.. includecode:: ../../../akka-samples/akka-sample-persistence-java-lambda/src/main/java/doc/LambdaPersistenceDocTest.java#view
|
||||
|
|
@ -275,14 +286,18 @@ the referenced persistent actor is actually running. Views read messages from a
|
|||
persistent actor is started later and begins to write new messages, the corresponding view is updated automatically, by
|
||||
default.
|
||||
|
||||
It is possible to determine if a message was sent from the Journal or from another actor in user-land by calling the ``isPersistent``
|
||||
method. Having that said, very often you don't need this information at all and can simply apply the same logic to both cases
|
||||
(skip the ``if isPersistent`` check).
|
||||
|
||||
Updates
|
||||
-------
|
||||
|
||||
The default update interval of all views of an actor system is configurable:
|
||||
The default update interval of all persistent views of an actor system is configurable:
|
||||
|
||||
.. includecode:: ../scala/code/docs/persistence/PersistenceDocSpec.scala#auto-update-interval
|
||||
|
||||
``View`` implementation classes may also override the ``autoUpdateInterval`` method to return a custom update
|
||||
``AbstractPersistentView`` implementation classes may also override the ``autoUpdateInterval`` method to return a custom update
|
||||
interval for a specific view class or view instance. Applications may also trigger additional updates at
|
||||
any time by sending a view an ``Update`` message.
|
||||
|
||||
|
|
@ -293,7 +308,7 @@ incremental message replay, triggered by that update request, completed. If set
|
|||
following the update request may interleave with the replayed message stream. Automated updates always run with
|
||||
``await = false``.
|
||||
|
||||
Automated updates of all views of an actor system can be turned off by configuration:
|
||||
Automated updates of all persistent views of an actor system can be turned off by configuration:
|
||||
|
||||
.. includecode:: ../scala/code/docs/persistence/PersistenceDocSpec.scala#auto-update
|
||||
|
||||
|
|
@ -305,20 +320,20 @@ of replayed messages for manual updates can be limited with the ``replayMax`` pa
|
|||
Recovery
|
||||
--------
|
||||
|
||||
Initial recovery of views works in the very same way as for a persistent actor (i.e. by sending a ``Recover`` message
|
||||
Initial recovery of persistent views works in the very same way as for a persistent actor (i.e. by sending a ``Recover`` message
|
||||
to self). The maximum number of replayed messages during initial recovery is determined by ``autoUpdateReplayMax``.
|
||||
Further possibilities to customize initial recovery are explained in section :ref:`recovery-java-lambda`.
|
||||
Further possibilities to customize initial recovery are explained in section :ref:`recovery-java`.
|
||||
|
||||
.. _persistence-identifiers-java-lambda:
|
||||
|
||||
Identifiers
|
||||
-----------
|
||||
|
||||
A view must have an identifier that doesn't change across different actor incarnations. It defaults to the
|
||||
A persistent view must have an identifier that doesn't change across different actor incarnations. It defaults to the
|
||||
``String`` representation of the actor path without the address part and can be obtained via the ``viewId``
|
||||
method.
|
||||
|
||||
Applications can customize a view's id by specifying an actor name during view creation. This changes that view's
|
||||
Applications can customize a view's id by specifying an actor name during view creation. This changes that persistent view's
|
||||
name in its actor hierarchy and hence influences only part of the view id. To fully customize a view's id, the
|
||||
``viewId`` method must be overridden. Overriding ``viewId`` is the recommended way to generate stable identifiers.
|
||||
|
||||
|
|
@ -338,7 +353,7 @@ Snapshots
|
|||
=========
|
||||
|
||||
Snapshots can dramatically reduce recovery times of persistent actors and views. The following discusses snapshots
|
||||
in context of persistent actors but this is also applicable to views.
|
||||
in context of persistent actors but this is also applicable to persistent views.
|
||||
|
||||
Persistent actor can save snapshots of internal state by calling the ``saveSnapshot`` method. If saving of a snapshot
|
||||
succeeds, the persistent actor receives a ``SaveSnapshotSuccess`` message, otherwise a ``SaveSnapshotFailure`` message
|
||||
|
|
|
|||
|
|
@ -31,6 +31,17 @@ concepts and architecture of `eventsourced`_ but significantly differs on API an
|
|||
|
||||
.. _eventsourced: https://github.com/eligosource/eventsourced
|
||||
|
||||
Changes in Akka 2.3.4
|
||||
=====================
|
||||
|
||||
In Akka 2.3.4 several of the concepts of the earlier versions were collapsed and simplified.
|
||||
In essence; ``Processor`` and ``EventsourcedProcessor`` are replaced by ``PersistentActor``. ``Channel``
|
||||
and ``PersistentChannel`` are replaced by ``AtLeastOnceDelivery``. ``View`` is replaced by ``PersistentView``.
|
||||
|
||||
See full details of the changes in the :ref:`migration-guide-persistence-experimental-2.3.x-2.4.x`.
|
||||
The old classes are still included, and deprecated, for a while to make the transition smooth.
|
||||
In case you need the old documentation it is located `here <http://doc.akka.io/docs/akka/2.3.3/java/persistence.html>`_.
|
||||
|
||||
Dependencies
|
||||
============
|
||||
|
||||
|
|
@ -50,7 +61,7 @@ Architecture
|
|||
When a persistent actor is started or restarted, journaled messages are replayed to that actor, so that it can
|
||||
recover internal state from these messages.
|
||||
|
||||
* *View*: A view is a persistent, stateful actor that receives journaled messages that have been written by another
|
||||
* *UntypedPersistentView*: A view is a persistent, stateful actor that receives journaled messages that have been written by another
|
||||
persistent actor. A view itself does not journal new messages, instead, it updates internal state only from a persistent actor's
|
||||
replicated message stream.
|
||||
|
||||
|
|
@ -265,13 +276,13 @@ to Akka persistence will allow to replay messages that have been marked as delet
|
|||
purposes, for example. To delete all messages (journaled by a single persistent actor) up to a specified sequence number,
|
||||
persistent actors should call the ``deleteMessages`` method.
|
||||
|
||||
.. _views-java:
|
||||
.. _persistent-views-java:
|
||||
|
||||
Views
|
||||
=====
|
||||
Persistent Views
|
||||
================
|
||||
|
||||
Views can be implemented by extending the ``UntypedView`` trait and implementing the ``onReceive`` and the ``persistenceId``
|
||||
methods.
|
||||
Persistent views can be implemented by extending the ``UntypedPersistentView`` trait and implementing the ``onReceive``
|
||||
and the ``persistenceId`` methods.
|
||||
|
||||
.. includecode:: code/docs/persistence/PersistenceDocTest.java#view
|
||||
|
||||
|
|
@ -280,14 +291,18 @@ the referenced persistent actor is actually running. Views read messages from a
|
|||
persistent actor is started later and begins to write new messages, the corresponding view is updated automatically, by
|
||||
default.
|
||||
|
||||
It is possible to determine if a message was sent from the Journal or from another actor in user-land by calling the ``isPersistent``
|
||||
method. Having that said, very often you don't need this information at all and can simply apply the same logic to both cases
|
||||
(skip the ``if isPersistent`` check).
|
||||
|
||||
Updates
|
||||
-------
|
||||
|
||||
The default update interval of all views of an actor system is configurable:
|
||||
The default update interval of all persistent views of an actor system is configurable:
|
||||
|
||||
.. includecode:: ../scala/code/docs/persistence/PersistenceDocSpec.scala#auto-update-interval
|
||||
|
||||
``View`` implementation classes may also override the ``autoUpdateInterval`` method to return a custom update
|
||||
``UntypedPersistentView`` implementation classes may also override the ``autoUpdateInterval`` method to return a custom update
|
||||
interval for a specific view class or view instance. Applications may also trigger additional updates at
|
||||
any time by sending a view an ``Update`` message.
|
||||
|
||||
|
|
@ -298,7 +313,7 @@ incremental message replay, triggered by that update request, completed. If set
|
|||
following the update request may interleave with the replayed message stream. Automated updates always run with
|
||||
``await = false``.
|
||||
|
||||
Automated updates of all views of an actor system can be turned off by configuration:
|
||||
Automated updates of all persistent views of an actor system can be turned off by configuration:
|
||||
|
||||
.. includecode:: ../scala/code/docs/persistence/PersistenceDocSpec.scala#auto-update
|
||||
|
||||
|
|
@ -310,7 +325,7 @@ of replayed messages for manual updates can be limited with the ``replayMax`` pa
|
|||
Recovery
|
||||
--------
|
||||
|
||||
Initial recovery of views works in the very same way as for a persistent actor (i.e. by sending a ``Recover`` message
|
||||
Initial recovery of persistent views works in the very same way as for a persistent actor (i.e. by sending a ``Recover`` message
|
||||
to self). The maximum number of replayed messages during initial recovery is determined by ``autoUpdateReplayMax``.
|
||||
Further possibilities to customize initial recovery are explained in section :ref:`recovery-java`.
|
||||
|
||||
|
|
@ -319,11 +334,11 @@ Further possibilities to customize initial recovery are explained in section :re
|
|||
Identifiers
|
||||
-----------
|
||||
|
||||
A view must have an identifier that doesn't change across different actor incarnations. It defaults to the
|
||||
A persistent view must have an identifier that doesn't change across different actor incarnations. It defaults to the
|
||||
``String`` representation of the actor path without the address part and can be obtained via the ``viewId``
|
||||
method.
|
||||
|
||||
Applications can customize a view's id by specifying an actor name during view creation. This changes that view's
|
||||
Applications can customize a view's id by specifying an actor name during view creation. This changes that persistent view's
|
||||
name in its actor hierarchy and hence influences only part of the view id. To fully customize a view's id, the
|
||||
``viewId`` method must be overridden. Overriding ``viewId`` is the recommended way to generate stable identifiers.
|
||||
|
||||
|
|
@ -343,7 +358,7 @@ Snapshots
|
|||
=========
|
||||
|
||||
Snapshots can dramatically reduce recovery times of persistent actor and views. The following discusses snapshots
|
||||
in context of persistent actor but this is also applicable to views.
|
||||
in context of persistent actor but this is also applicable to persistent views.
|
||||
|
||||
Persistent actor can save snapshots of internal state by calling the ``saveSnapshot`` method. If saving of a snapshot
|
||||
succeeds, the persistent actor receives a ``SaveSnapshotSuccess`` message, otherwise a ``SaveSnapshotFailure`` message
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue