This repository has been archived by the owner on Mar 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from cloudstateio/wip-kotlin-factory
Add pure Kotlin EventSourcedEntityFactory, EntityHandler and ResolvedEntityFactory implementations
- Loading branch information
Showing
45 changed files
with
1,111 additions
and
625 deletions.
There are no files selected for viewing
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
18 changes: 18 additions & 0 deletions
18
...dstate-kotlin-support/src/main/java/io/cloudstate/kotlinsupport/annotations/EntityId.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,18 @@ | ||
package io.cloudstate.kotlinsupport.annotations; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* Annotation used to indicate that the annotated parameter accepts an entity id. | ||
* | ||
* <p>This parameter may appear on handler methods and constructors for any class that provides | ||
* behavior for stateful service entity. | ||
* | ||
* <p>The type of the parameter must be {@link String}. | ||
*/ | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target({ElementType.PARAMETER, ElementType.FIELD}) | ||
public @interface EntityId {} |
39 changes: 39 additions & 0 deletions
39
...in-support/src/main/java/io/cloudstate/kotlinsupport/annotations/crdt/CommandHandler.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,39 @@ | ||
package io.cloudstate.kotlinsupport.annotations.crdt; | ||
|
||
import io.cloudstate.javasupport.crdt.CommandContext; | ||
import io.cloudstate.javasupport.impl.CloudStateAnnotation; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* Marks a method as a command handler. | ||
* | ||
* <p>This method will be invoked whenever the service call with name that matches this command | ||
* handlers name is invoked. | ||
* | ||
* <p>The method may take the command object as a parameter, its type must match the gRPC service | ||
* input type. | ||
* | ||
* <p>The return type of the method must match the gRPC services output type. | ||
* | ||
* <p>The method may also take a {@link CommandContext}, and/or a {@link | ||
* io.cloudstate.javasupport.EntityId} annotated {@link String} parameter. | ||
*/ | ||
@CloudStateAnnotation | ||
@Target(ElementType.METHOD) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface CommandHandler { | ||
|
||
/** | ||
* The name of the command to handle. | ||
* | ||
* <p>If not specified, the name of the method will be used as the command name, with the first | ||
* letter capitalized to match the gRPC convention of capitalizing rpc method names. | ||
* | ||
* @return The command name. | ||
*/ | ||
String name() default ""; | ||
} |
31 changes: 31 additions & 0 deletions
31
...kotlin-support/src/main/java/io/cloudstate/kotlinsupport/annotations/crdt/CrdtEntity.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,31 @@ | ||
package io.cloudstate.kotlinsupport.annotations.crdt; | ||
|
||
import io.cloudstate.javasupport.crdt.CommandHandler; | ||
import io.cloudstate.javasupport.crdt.Crdt; | ||
import io.cloudstate.javasupport.crdt.CrdtContext; | ||
import io.cloudstate.javasupport.crdt.CrdtFactory; | ||
import io.cloudstate.javasupport.impl.CloudStateAnnotation; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* A CRDT backed entity. | ||
* | ||
* <p>CRDT entities store their state in a subclass {@link Crdt}. These may be created using a | ||
* {@link CrdtFactory}, which can be injected into the constructor or as a parameter to any {@link | ||
* CommandHandler} annotated method. | ||
* | ||
* <p>Only one CRDT may be created, it is important that before creating a CRDT, the entity should | ||
* check whether the CRDT has already been created, for example, it may have been created on another | ||
* node and replicated to this node. To check, either use the {@link CrdtContext#state(Class)} | ||
* method, which can be injected into the constructor or any {@link CommandHandler} method, or have | ||
* an instance of the CRDT wrapped in {@link java.util.Optional} injected into the constructor or | ||
* command handler methods. | ||
*/ | ||
@CloudStateAnnotation | ||
@Target(ElementType.TYPE) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface CrdtEntity {} |
37 changes: 37 additions & 0 deletions
37
...rt/src/main/java/io/cloudstate/kotlinsupport/annotations/eventsourced/CommandHandler.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,37 @@ | ||
package io.cloudstate.kotlinsupport.annotations.eventsourced; | ||
|
||
import io.cloudstate.javasupport.eventsourced.CommandContext; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* Marks a method as a command handler. | ||
* | ||
* <p>This method will be invoked whenever the service call with name that matches this command | ||
* handlers name is invoked. | ||
* | ||
* <p>The method may take the command object as a parameter, its type must match the gRPC service | ||
* input type. | ||
* | ||
* <p>The return type of the method must match the gRPC services output type. | ||
* | ||
* <p>The method may also take a {@link CommandContext}, and/or a {@link | ||
* io.cloudstate.javasupport.EntityId} annotated {@link String} parameter. | ||
*/ | ||
@Target(ElementType.METHOD) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface CommandHandler { | ||
|
||
/** | ||
* The name of the command to handle. | ||
* | ||
* <p>If not specified, the name of the method will be used as the command name, with the first | ||
* letter capitalized to match the gRPC convention of capitalizing rpc method names. | ||
* | ||
* @return The command name. | ||
*/ | ||
String name() default ""; | ||
} |
30 changes: 30 additions & 0 deletions
30
...port/src/main/java/io/cloudstate/kotlinsupport/annotations/eventsourced/EventHandler.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,30 @@ | ||
package io.cloudstate.kotlinsupport.annotations.eventsourced; | ||
|
||
import io.cloudstate.javasupport.eventsourced.EventContext; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* Marks a method as an event handler. | ||
* | ||
* <p>This method will be invoked whenever an event matching this event handlers event class is | ||
* either replayed on entity recovery, by a command handler. | ||
* | ||
* <p>The method may take the event object as a parameter. | ||
* | ||
* <p>Methods annotated with this may take an {@link EventContext}. | ||
*/ | ||
@Target(ElementType.METHOD) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface EventHandler { | ||
/** | ||
* The event class. Generally, this will be determined by looking at the parameter of the event | ||
* handler method, however if the event doesn't need to be passed to the method (for example, | ||
* perhaps it contains no data), then this can be used to indicate which event this handler | ||
* handles. | ||
*/ | ||
Class<?> eventClass() default Object.class; | ||
} |
26 changes: 26 additions & 0 deletions
26
...rc/main/java/io/cloudstate/kotlinsupport/annotations/eventsourced/EventSourcedEntity.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,26 @@ | ||
package io.cloudstate.kotlinsupport.annotations.eventsourced; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** An event sourced entity. */ | ||
@Target(ElementType.TYPE) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface EventSourcedEntity { | ||
/** | ||
* The name of the persistence id. | ||
* | ||
* <p>If not specifed, defaults to the entities unqualified classname. It's strongly recommended | ||
* that you specify it explicitly. | ||
*/ | ||
String persistenceId() default ""; | ||
|
||
/** | ||
* Specifies how snapshots of the entity state should be made: Zero means use default from | ||
* configuration file. (Default) Any negative value means never snapshot. Any positive value means | ||
* snapshot at-or-after that number of events. | ||
*/ | ||
int snapshotEvery() default 0; | ||
} |
23 changes: 23 additions & 0 deletions
23
...-support/src/main/java/io/cloudstate/kotlinsupport/annotations/eventsourced/Snapshot.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,23 @@ | ||
package io.cloudstate.kotlinsupport.annotations.eventsourced; | ||
|
||
import io.cloudstate.javasupport.eventsourced.SnapshotContext; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* Marks a method as a snapshot method. | ||
* | ||
* <p>An event sourced behavior may have at most one of these. When provided, it will be | ||
* periodically (every <em>n</em> events emitted) be invoked to retrieve a snapshot of the current | ||
* state, to be persisted, so that the event log can be loaded without replaying the entire history. | ||
* | ||
* <p>The method must return the current state of the entity. | ||
* | ||
* <p>The method may accept a {@link SnapshotContext} parameter. | ||
*/ | ||
@Target(ElementType.METHOD) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface Snapshot {} |
25 changes: 25 additions & 0 deletions
25
...t/src/main/java/io/cloudstate/kotlinsupport/annotations/eventsourced/SnapshotHandler.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,25 @@ | ||
package io.cloudstate.kotlinsupport.annotations.eventsourced; | ||
|
||
import io.cloudstate.javasupport.eventsourced.SnapshotContext; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* Marks a method as a snapshot handler. | ||
* | ||
* <p>If, when recovering an entity, that entity has a snapshot, the snapshot will be passed to a | ||
* corresponding snapshot handler method whose argument matches its type. The entity must set its | ||
* current state to that snapshot. | ||
* | ||
* <p>An entity may declare more than one snapshot handler if it wants different handling for | ||
* different types. | ||
* | ||
* <p>The snapshot handler method may additionally accept a {@link SnapshotContext} parameter, | ||
* allowing it to access context for the snapshot, if required. | ||
*/ | ||
@Target(ElementType.METHOD) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface SnapshotHandler {} |
11 changes: 0 additions & 11 deletions
11
...te-kotlin-support/src/main/java/io/cloudstate/kotlinsupport/transcoding/EntityIdImpl.java
This file was deleted.
Oops, something went wrong.
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
23 changes: 0 additions & 23 deletions
23
...rc/main/java/io/cloudstate/kotlinsupport/transcoding/eventsourced/CommandHandlerImpl.java
This file was deleted.
Oops, something went wrong.
17 changes: 0 additions & 17 deletions
17
.../src/main/java/io/cloudstate/kotlinsupport/transcoding/eventsourced/EventHandlerImpl.java
This file was deleted.
Oops, something went wrong.
30 changes: 0 additions & 30 deletions
30
...ain/java/io/cloudstate/kotlinsupport/transcoding/eventsourced/EventSourcedEntityImpl.java
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
...c/main/java/io/cloudstate/kotlinsupport/transcoding/eventsourced/SnapshotHandlerImpl.java
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
...port/src/main/java/io/cloudstate/kotlinsupport/transcoding/eventsourced/SnapshotImpl.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.