Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EventSourcedEntityHandler generation and registration via provider #231

Merged
merged 8 commits into from
Aug 24, 2021

Conversation

patriknw
Copy link
Contributor

@patriknw patriknw commented Aug 23, 2021

  • codegen of EventSourcedEntityHandler (no reflection)
  • registration via EventSourcedEntityProvider
  • also split of java-customer-registry sampel into two;
    one for value entity and another for event sourced

Refs #52

* also split of java-customer-registry sampel into two;
  one for value entity and another for event sourced
@patriknw patriknw changed the title Registration of event sourced entity via provider Event sourced generation and registration via provider Aug 23, 2021
@patriknw patriknw marked this pull request as ready for review August 23, 2021 17:36
@patriknw patriknw changed the title Event sourced generation and registration via provider EventSourcedEntityHandler generation and registration via provider Aug 23, 2021
@patriknw patriknw mentioned this pull request Aug 24, 2021
20 tasks
Copy link
Contributor

@johanandren johanandren left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

import com.google.protobuf.Empty;
import customer.api.CustomerApi;

/** An event sourced entity. */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not necessarily for this PR but one thing that would be nice would be if we could include what protobuf it corresponds to here (like we have manually in some of the serverless framework test classes).

import com.akkaserverless.javasdk.impl.eventsourcedentity.EventSourcedEntityHandler;
import com.google.protobuf.Descriptors;

public interface EventSourcedEntityProvider<S, E extends EventSourcedEntityBase<S>> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add some "Not for user extension" here or do we consider it actual API for user extension as well as common (internal) interface for generated code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add a comment that the concrete implementation is generated, to start with.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question.

Let's be restrictive and eventually relax the rules if needed. We have all the interest in keep it 'private'.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can't make it completely internal because it's the parameter to register

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what I mean by 'private' is that it's not real private, but marked as "Not for user extension"

@patriknw
Copy link
Contributor Author

This is ready. I'll continue in a new PR by looking at the differences between event sourced and value entities and try to align. Part of that also look at the serialization second step in #150

Copy link
Member

@octonato octonato left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good.

I left some comments and suggestions. Don't need to be impl in this PR, so approving already. We can eventually add in follow-up PRs.

@@ -23,6 +23,7 @@ import org.bitbucket.inkytonik.kiama.output.PrettyPrinterTypes.Document

object ValueEntitySourceGenerator {
import SourceGenerator._
import EntityServiceSourceGenerator.generateImports
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why generateImports needed to move to EntityServiceSourceGenerator?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's used by both ValueEntitySourceGenerator and EntityServiceSourceGenerator, should probably be in some third utility class but EntityServiceSourceGenerator anyway looked like it wasn't only about EventSourced

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, the code for value entity and event sourced entity was previously in EntityServiceSourceGenerator and we started to split it into two different generators.

At some point, we spined-off ValueEntitySourceGenerator and EntityServiceSourceGenerator should have been renamed to EntitySourcedServiceSourceGenerator, but we had other PRs in the making and it was better to postpone the rename to avoid conflicts.

Comment on lines +117 to +122
generatedSourceDirectory.resolve(
"com/example/service/persistence/MyEntity1Handler.java"
),
generatedSourceDirectory.resolve(
"com/example/service/persistence/MyEntity1Provider.java"
),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! I missed this extra tests when introducing the handler and provider. Thanks.

@@ -316,7 +482,7 @@ object EntityServiceSourceGenerator {
className: String): Option[String] = {
entity match {
case eventSourcedEntity: ModelBuilder.EventSourcedEntity =>
None
Some(eventSourcedEntityProvider(service, eventSourcedEntity, packageName, className))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made it an option (here and above) because we didn't have a provider and a handler for ES.

We can remove the Option now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I'll remove that in next round

`class`("public", s"$className extends $interfaceClassName") {
"@SuppressWarnings" <> parens(dquotes("unused")) <> line <>
"private" <+> "final" <+> "String" <+> "entityId" <> semi <> line <>
line <>
constructor(
"public",
className,
List("@EntityId" <+> "String" <+> "entityId")
List("EventSourcedContext" <+> "context")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Value entity is only passing the String entityId. We need to align this.

The context is not so useful right now. It only has the entityId and the serviceCallFactory, but the serviceCallFactory is already available from the CommandContext.

We probably want to have something better than the exiting (untyped) ServiceCallFactory and then we want it to be injected in the constructor so users can instantiate clients at construction time (and not per command using the CommandContext).

So, passing the context is probably something we may need to keep (and introduce in VE), but not yet clear how we will really use it.

On the other hand, passing context make unit testing harder. It will be better to not have a mock context of any kind.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, there are more things that are different, I'll align them

import com.akkaserverless.javasdk.impl.eventsourcedentity.EventSourcedEntityHandler;
import com.google.protobuf.Descriptors;

public interface EventSourcedEntityProvider<S, E extends EventSourcedEntityBase<S>> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what I mean by 'private' is that it's not real private, but marked as "Not for user extension"

@patriknw patriknw merged commit aa9889a into sdk-codegen-dev Aug 24, 2021
@patriknw patriknw deleted the wip-es-provider-patriknw branch August 24, 2021 11:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants