Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,7 @@ object ActionServiceSourceGenerator {
private[codegen] def abstractActionSource(service: ModelBuilder.ActionService): String = {

val packageName = service.fqn.parent.javaPackage
val imports = generateImports(
service.commandTypes,
packageName,
otherImports = Seq("com.akkaserverless.javasdk.action.Action") ++ streamImports(service.commands))
val imports = generateImports(service.commandTypes, packageName, otherImports = streamImports(service.commands))

val methods = service.commands.map { cmd =>
val methodName = cmd.name
Expand Down Expand Up @@ -195,7 +192,7 @@ object ActionServiceSourceGenerator {
|$managedComment
|
|/** An action. */
|public abstract class ${service.abstractActionName} extends Action {
|public abstract class ${service.abstractActionName} extends com.akkaserverless.javasdk.action.Action {
|
| ${Format.indent(methods, 2)}
|}""".stripMargin
Expand All @@ -221,7 +218,7 @@ object ActionServiceSourceGenerator {
val inputTypeFullName = cmd.inputType.fullName

s"""|case "$methodName":
| return (Source<Action.Effect<?>, NotUsed>)(Object) action()
| return (Source<Effect<?>, NotUsed>)(Object) action()
| .${lowerFirst(methodName)}(($inputTypeFullName) message.payload());
|""".stripMargin
}
Expand All @@ -241,7 +238,7 @@ object ActionServiceSourceGenerator {
val inputTypeFullName = cmd.inputType.fullName

s"""|case "$methodName":
| return (Source<Action.Effect<?>, NotUsed>)(Object) action()
| return (Source<Effect<?>, NotUsed>)(Object) action()
| .${lowerFirst(methodName)}(stream.map(el -> ($inputTypeFullName) el.payload()));
|""".stripMargin
}
Expand All @@ -252,7 +249,7 @@ object ActionServiceSourceGenerator {
otherImports = Seq(
"akka.NotUsed",
"akka.stream.javadsl.Source",
"com.akkaserverless.javasdk.action.Action",
"com.akkaserverless.javasdk.action.Action.Effect",
"com.akkaserverless.javasdk.action.MessageEnvelope",
"com.akkaserverless.javasdk.impl.action.ActionHandler"))

Expand All @@ -269,7 +266,7 @@ object ActionServiceSourceGenerator {
| }
|
| @Override
| public Action.Effect<?> handleUnary(String commandName, MessageEnvelope<Object> message) {
| public Effect<?> handleUnary(String commandName, MessageEnvelope<Object> message) {
| switch (commandName) {
| ${Format.indent(unaryCases, 6)}
| default:
Expand All @@ -279,7 +276,7 @@ object ActionServiceSourceGenerator {
|
| @Override
| @SuppressWarnings("unchecked")
| public Source<Action.Effect<?>, NotUsed> handleStreamedOut(String commandName, MessageEnvelope<Object> message) {
| public Source<Effect<?>, NotUsed> handleStreamedOut(String commandName, MessageEnvelope<Object> message) {
| switch (commandName) {
| ${Format.indent(streamOutCases, 6)}
| default:
Expand All @@ -288,7 +285,7 @@ object ActionServiceSourceGenerator {
| }
|
| @Override
| public Action.Effect<?> handleStreamedIn(String commandName, Source<MessageEnvelope<Object>, NotUsed> stream) {
| public Effect<?> handleStreamedIn(String commandName, Source<MessageEnvelope<Object>, NotUsed> stream) {
| switch (commandName) {
| ${Format.indent(streamInCases, 6)}
| default:
Expand All @@ -298,7 +295,7 @@ object ActionServiceSourceGenerator {
|
| @Override
| @SuppressWarnings("unchecked")
| public Source<Action.Effect<?>, NotUsed> handleStreamed(String commandName, Source<MessageEnvelope<Object>, NotUsed> stream) {
| public Source<Effect<?>, NotUsed> handleStreamed(String commandName, Source<MessageEnvelope<Object>, NotUsed> stream) {
| switch (commandName) {
| ${Format.indent(streamInOutCases, 6)}
| default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,14 @@ class ActionServiceSourceGeneratorSuite extends munit.FunSuite {
|
|import akka.NotUsed;
|import akka.stream.javadsl.Source;
|import com.akkaserverless.javasdk.action.Action;
|import com.external.Empty;
|
|// This code is managed by Akka Serverless tooling.
|// It will be re-generated to reflect any changes to your protobuf definitions.
|// DO NOT EDIT
|
|/** An action. */
|public abstract class AbstractMyServiceAction extends Action {
|public abstract class AbstractMyServiceAction extends com.akkaserverless.javasdk.action.Action {
|
| /** Handler for "SimpleMethod". */
| public abstract Effect<Empty> simpleMethod(ServiceOuterClass.MyRequest myRequest);
Expand Down Expand Up @@ -175,15 +174,14 @@ class ActionServiceSourceGeneratorSuite extends munit.FunSuite {
|
|import akka.NotUsed;
|import akka.stream.javadsl.Source;
|import com.akkaserverless.javasdk.action.Action;
|import com.external.Empty;
|
|// This code is managed by Akka Serverless tooling.
|// It will be re-generated to reflect any changes to your protobuf definitions.
|// DO NOT EDIT
|
|/** An action. */
|public abstract class AbstractMyServiceAction extends Action {
|public abstract class AbstractMyServiceAction extends com.akkaserverless.javasdk.action.Action {
|
| /** Handler for "SimpleMethod". */
| public abstract Effect<Empty> simpleMethod(ServiceOuterClass.MyRequest myRequest);
Expand Down Expand Up @@ -211,7 +209,7 @@ class ActionServiceSourceGeneratorSuite extends munit.FunSuite {
|
|import akka.NotUsed;
|import akka.stream.javadsl.Source;
|import com.akkaserverless.javasdk.action.Action;
|import com.akkaserverless.javasdk.action.Action.Effect;
|import com.akkaserverless.javasdk.action.MessageEnvelope;
|import com.akkaserverless.javasdk.impl.action.ActionHandler;
|import com.external.Empty;
Expand All @@ -227,7 +225,7 @@ class ActionServiceSourceGeneratorSuite extends munit.FunSuite {
| }
|
| @Override
| public Action.Effect<?> handleUnary(String commandName, MessageEnvelope<Object> message) {
| public Effect<?> handleUnary(String commandName, MessageEnvelope<Object> message) {
| switch (commandName) {
| case "SimpleMethod":
| return action()
Expand All @@ -239,18 +237,18 @@ class ActionServiceSourceGeneratorSuite extends munit.FunSuite {
|
| @Override
| @SuppressWarnings("unchecked")
| public Source<Action.Effect<?>, NotUsed> handleStreamedOut(String commandName, MessageEnvelope<Object> message) {
| public Source<Effect<?>, NotUsed> handleStreamedOut(String commandName, MessageEnvelope<Object> message) {
| switch (commandName) {
| case "StreamedOutputMethod":
| return (Source<Action.Effect<?>, NotUsed>)(Object) action()
| return (Source<Effect<?>, NotUsed>)(Object) action()
| .streamedOutputMethod((ServiceOuterClass.MyRequest) message.payload());
| default:
| throw new ActionHandler.HandlerNotFound(commandName);
| }
| }
|
| @Override
| public Action.Effect<?> handleStreamedIn(String commandName, Source<MessageEnvelope<Object>, NotUsed> stream) {
| public Effect<?> handleStreamedIn(String commandName, Source<MessageEnvelope<Object>, NotUsed> stream) {
| switch (commandName) {
| case "StreamedInputMethod":
| return action()
Expand All @@ -262,10 +260,10 @@ class ActionServiceSourceGeneratorSuite extends munit.FunSuite {
|
| @Override
| @SuppressWarnings("unchecked")
| public Source<Action.Effect<?>, NotUsed> handleStreamed(String commandName, Source<MessageEnvelope<Object>, NotUsed> stream) {
| public Source<Effect<?>, NotUsed> handleStreamed(String commandName, Source<MessageEnvelope<Object>, NotUsed> stream) {
| switch (commandName) {
| case "FullStreamedMethod":
| return (Source<Action.Effect<?>, NotUsed>)(Object) action()
| return (Source<Effect<?>, NotUsed>)(Object) action()
| .fullStreamedMethod(stream.map(el -> (ServiceOuterClass.MyRequest) el.payload()));
| default:
| throw new ActionHandler.HandlerNotFound(commandName);
Expand All @@ -288,7 +286,7 @@ class ActionServiceSourceGeneratorSuite extends munit.FunSuite {
|
|import akka.NotUsed;
|import akka.stream.javadsl.Source;
|import com.akkaserverless.javasdk.action.Action;
|import com.akkaserverless.javasdk.action.Action.Effect;
|import com.akkaserverless.javasdk.action.MessageEnvelope;
|import com.akkaserverless.javasdk.impl.action.ActionHandler;
|import com.external.Empty;
Expand All @@ -304,7 +302,7 @@ class ActionServiceSourceGeneratorSuite extends munit.FunSuite {
| }
|
| @Override
| public Action.Effect<?> handleUnary(String commandName, MessageEnvelope<Object> message) {
| public Effect<?> handleUnary(String commandName, MessageEnvelope<Object> message) {
| switch (commandName) {
| case "SimpleMethod":
| return action()
Expand All @@ -316,18 +314,18 @@ class ActionServiceSourceGeneratorSuite extends munit.FunSuite {
|
| @Override
| @SuppressWarnings("unchecked")
| public Source<Action.Effect<?>, NotUsed> handleStreamedOut(String commandName, MessageEnvelope<Object> message) {
| public Source<Effect<?>, NotUsed> handleStreamedOut(String commandName, MessageEnvelope<Object> message) {
| switch (commandName) {
| case "StreamedOutputMethod":
| return (Source<Action.Effect<?>, NotUsed>)(Object) action()
| return (Source<Effect<?>, NotUsed>)(Object) action()
| .streamedOutputMethod((ServiceOuterClass.MyRequest) message.payload());
| default:
| throw new ActionHandler.HandlerNotFound(commandName);
| }
| }
|
| @Override
| public Action.Effect<?> handleStreamedIn(String commandName, Source<MessageEnvelope<Object>, NotUsed> stream) {
| public Effect<?> handleStreamedIn(String commandName, Source<MessageEnvelope<Object>, NotUsed> stream) {
| switch (commandName) {
| case "StreamedInputMethod":
| return action()
Expand All @@ -339,10 +337,10 @@ class ActionServiceSourceGeneratorSuite extends munit.FunSuite {
|
| @Override
| @SuppressWarnings("unchecked")
| public Source<Action.Effect<?>, NotUsed> handleStreamed(String commandName, Source<MessageEnvelope<Object>, NotUsed> stream) {
| public Source<Effect<?>, NotUsed> handleStreamed(String commandName, Source<MessageEnvelope<Object>, NotUsed> stream) {
| switch (commandName) {
| case "FullStreamedMethod":
| return (Source<Action.Effect<?>, NotUsed>)(Object) action()
| return (Source<Effect<?>, NotUsed>)(Object) action()
| .fullStreamedMethod(stream.map(el -> (ServiceOuterClass.MyRequest) el.payload()));
| default:
| throw new ActionHandler.HandlerNotFound(commandName);
Expand Down