-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ChangeEvent from Durable State (akka#32254)
* by storing additional change events when Durable State is updated and deleted we make it possible to use all nice event sourced Projection capabilities with Durable State, including Projections over gRPC * otherwise we would have to duplicate many many things to use the existing DurableStateChange and the queries based on that * we might even deprecate the existing DurableStateChange if this works out, but that can be a later decision * ApiMayChange * reference docs for plugin api * note about mutable state
- Loading branch information
Showing
22 changed files
with
827 additions
and
36 deletions.
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
akka-docs/src/main/java/docs/persistence/state/MyChangeEventJavaStateStore.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Copyright (C) 2023 Lightbend Inc. <https://www.lightbend.com> | ||
*/ | ||
|
||
package docs.persistence.state; | ||
|
||
// #plugin-imports | ||
|
||
import akka.Done; | ||
import akka.actor.ExtendedActorSystem; | ||
import akka.persistence.state.javadsl.DurableStateUpdateWithChangeEventStore; | ||
import akka.persistence.state.javadsl.GetObjectResult; | ||
import com.typesafe.config.Config; | ||
import java.util.concurrent.CompletionStage; | ||
|
||
// #plugin-imports | ||
|
||
// #state-store-plugin-api | ||
class MyChangeEventJavaStateStore<A> implements DurableStateUpdateWithChangeEventStore<A> { | ||
|
||
private ExtendedActorSystem system; | ||
private Config config; | ||
private String cfgPath; | ||
|
||
public MyChangeEventJavaStateStore(ExtendedActorSystem system, Config config, String cfgPath) { | ||
this.system = system; | ||
this.config = config; | ||
this.cfgPath = cfgPath; | ||
} | ||
|
||
/** | ||
* Will delete the state by setting it to the empty state and the revision number will be | ||
* incremented by 1. | ||
*/ | ||
@Override | ||
public CompletionStage<Done> deleteObject(String persistenceId, long revision) { | ||
// implement deleteObject here | ||
return null; | ||
} | ||
|
||
@Override | ||
public CompletionStage<Done> deleteObject( | ||
String persistenceId, long revision, Object changeEvent) { | ||
// implement deleteObject here | ||
return null; | ||
} | ||
|
||
/** Returns the current state for the given persistence id. */ | ||
@Override | ||
public CompletionStage<GetObjectResult<A>> getObject(String persistenceId) { | ||
// implement getObject here | ||
return null; | ||
} | ||
|
||
/** | ||
* Will persist the latest state. If it’s a new persistence id, the record will be inserted. | ||
* | ||
* <p>In case of an existing persistence id, the record will be updated only if the revision | ||
* number of the incoming record is 1 more than the already existing record. Otherwise persist | ||
* will fail. | ||
*/ | ||
@Override | ||
public CompletionStage<Done> upsertObject( | ||
String persistenceId, long revision, Object value, String tag) { | ||
// implement upsertObject here | ||
return null; | ||
} | ||
|
||
/** Deprecated. Use the deleteObject overload with revision instead. */ | ||
@Override | ||
public CompletionStage<Done> deleteObject(String persistenceId) { | ||
return deleteObject(persistenceId, 0); | ||
} | ||
|
||
@Override | ||
public CompletionStage<Done> upsertObject( | ||
String persistenceId, long revision, A value, String tag, Object changeEvent) { | ||
// implement deleteObject here | ||
return null; | ||
} | ||
} | ||
// #state-store-plugin-api |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.