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 @@ -26,8 +26,6 @@ import com.akkaserverless.javasdk.eventsourcedentity.EventSourcedEntityContext
*/
final class TestKitEventSourcedEntityContext(override val entityId: String) extends EventSourcedEntityContext {
override def serviceCallFactory: ServiceCallFactory = TestKitServiceCallFactory
override def getGrpcClient[T](clientClass: Class[T], service: String): T =
throw new UnsupportedOperationException("Testing logic using a gRPC client is not possible with the testkit")
override def materializer(): Materializer = throw new UnsupportedOperationException(
"Accessing the materializer from testkit not supported yet")
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ import com.akkaserverless.javasdk.valueentity.ValueEntityContext
*/
final class TestKitValueEntityContext(override val entityId: String) extends ValueEntityContext {
override def serviceCallFactory: ServiceCallFactory = TestKitServiceCallFactory
override def getGrpcClient[T](clientClass: Class[T], service: String): T =
throw new UnsupportedOperationException("Testing logic using a gRPC client is not possible with the testkit")
override def materializer(): Materializer = throw new UnsupportedOperationException(
"Accessing the materializer from testkit not supported yet")
}
13 changes: 0 additions & 13 deletions sdk/java-sdk/src/main/java/com/akkaserverless/javasdk/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,6 @@ public interface Context {
/** Get the service call factory for this stateful service. */
ServiceCallFactory serviceCallFactory();

/**
* Get an Akka gRPC client for the given service name. The same client instance is shared across
* components in the application. The lifecycle of the client is managed by the SDK and it should
* not be stopped by user code.
*
* @param <T> The "service" interface generated for the service by Akka gRPC
* @param clientClass The class of a gRPC service generated by Akka gRPC
* @param service The name of the service to connect to, either a name of another Akka Serverless
* service or an external service where connection details are configured under
* `akka.grpc.client.[service-name]` in `application.conf`.
*/
<T> T getGrpcClient(Class<T> clientClass, String service);

/**
* An Akka Stream materializer to use for running streams. Needed for example in a command handler
* which accepts streaming elements but returns a single async reply once all streamed elements
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,17 @@ public interface ActionContext extends MetadataContext {
* emitted from an entity.
*/
Optional<String> eventSubject();

/**
* Get an Akka gRPC client for the given service name. The same client instance is shared across
* components in the application. The lifecycle of the client is managed by the SDK and it should
* not be stopped by user code.
*
* @param <T> The "service" interface generated for the service by Akka gRPC
* @param clientClass The class of a gRPC service generated by Akka gRPC
* @param service The name of the service to connect to, either a name of another Akka Serverless
* service or an external service where connection details are configured under
* `akka.grpc.client.[service-name]` in `application.conf`.
*/
<T> T getGrpcClient(Class<T> clientClass, String service);
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,17 @@
*
* <p>This may be accepted as an argument to the constructor of an Action.
*/
public interface ActionCreationContext extends Context {}
public interface ActionCreationContext extends Context {
/**
* Get an Akka gRPC client for the given service name. The same client instance is shared across
* components in the application. The lifecycle of the client is managed by the SDK and it should
* not be stopped by user code.
*
* @param <T> The "service" interface generated for the service by Akka gRPC
* @param clientClass The class of a gRPC service generated by Akka gRPC
* @param service The name of the service to connect to, either a name of another Akka Serverless
* service or an external service where connection details are configured under
* `akka.grpc.client.[service-name]` in `application.conf`.
*/
<T> T getGrpcClient(Class<T> clientClass, String service);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

might not be needed in the ActionCreationContext, but doesn't hurt if someone prefer to grab it in the constructor

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ private[javasdk] abstract class AbstractContext(
override val serviceCallFactory: ServiceCallFactory,
system: ActorSystem)
extends Context {
override def getGrpcClient[T](clientClass: Class[T], service: String): T =
GrpcClients(system).getGrpcClient(clientClass, service)

override def materializer(): Materializer =
SystemMaterializer(system).materializer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ private[javasdk] final class ActionsImpl(

private object creationContext
extends AbstractContext(rootContext.serviceCallFactory(), system)
with ActionCreationContext
with ActionCreationContext {
override def getGrpcClient[T](clientClass: Class[T], service: String): T =
GrpcClients(system).getGrpcClient(clientClass, service)
}

private def toJavaPbAny(any: Option[ScalaPbAny]) =
any.fold(JavaPbAny.getDefaultInstance)(ScalaPbAny.toJavaProto)
Expand Down Expand Up @@ -329,7 +332,11 @@ private[javasdk] final class ActionsImpl(
metadata.asCloudEvent().subject()
else
Optional.empty()

override def getGrpcClient[T](clientClass: Class[T], service: String): T =
GrpcClients(system).getGrpcClient(clientClass, service)
}

}

case class MessageEnvelopeImpl[T](payload: T, metadata: Metadata) extends MessageEnvelope[T]
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ import com.akkaserverless.scalasdk.eventsourcedentity.EventSourcedEntityContext
*/
final class TestKitEventSourcedEntityContext(override val entityId: String) extends EventSourcedEntityContext {
override def serviceCallFactory: ServiceCallFactory = TestKitServiceCallFactory
override def getGrpcClient[T](clientClass: Class[T], service: String): T =
throw new UnsupportedOperationException("Testing logic using a gRPC client is not possible with the testkit")
override def materializer(): Materializer = throw new UnsupportedOperationException(
"Accessing the materializer from testkit not supported yet")
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ import com.akkaserverless.scalasdk.valueentity.ValueEntityContext
*/
final class TestKitValueEntityContext(override val entityId: String) extends ValueEntityContext {
override def serviceCallFactory: ServiceCallFactory = TestKitServiceCallFactory
override def getGrpcClient[T](clientClass: Class[T], service: String): T =
throw new UnsupportedOperationException("Testing logic using a gRPC client is not possible with the testkit")
override def materializer(): Materializer = throw new UnsupportedOperationException(
"Accessing the materializer from testkit not supported yet")
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,6 @@ trait Context {
/** Get the service call factory for this stateful service. */
def serviceCallFactory: ServiceCallFactory

/**
* Get an Akka gRPC client for the given service name. The same client instance is shared across components in the
* application. The lifecycle of the client is managed by the SDK and it should not be stopped by user code.
*
* @tparam T
* The "service" interface generated for the service by Akka gRPC
* @param clientClass
* The class of a gRPC service generated by Akka gRPC
* @param service
* The name of the service to connect to, either a name of another Akka Serverless service or an external service
* where connection details are configured under `akka.grpc.client.[service-name]` in `application.conf`.
*/
def getGrpcClient[T](clientClass: Class[T], service: String): T

/**
* An Akka Stream materializer to use for running streams. Needed for example in a command handler which accepts
* streaming elements but returns a single async reply once all streamed elements has been consumed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,18 @@ trait ActionContext extends MetadataContext {
* The origin subject of the {{{CloudEvent}}}. For example, the entity key when the event was emitted from an entity.
*/
def eventSubject: Option[String]

/**
* Get an Akka gRPC client for the given service name. The same client instance is shared across components in the
* application. The lifecycle of the client is managed by the SDK and it should not be stopped by user code.
*
* @tparam T
* The "service" interface generated for the service by Akka gRPC
* @param clientClass
* The class of a gRPC service generated by Akka gRPC
* @param service
* The name of the service to connect to, either a name of another Akka Serverless service or an external service
* where connection details are configured under `akka.grpc.client.[service-name]` in `application.conf`.
*/
def getGrpcClient[T](clientClass: Class[T], service: String): T
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,19 @@ package com.akkaserverless.scalasdk.action

import com.akkaserverless.scalasdk.Context

trait ActionCreationContext extends Context {}
trait ActionCreationContext extends Context {

/**
* Get an Akka gRPC client for the given service name. The same client instance is shared across components in the
* application. The lifecycle of the client is managed by the SDK and it should not be stopped by user code.
*
* @tparam T
* The "service" interface generated for the service by Akka gRPC
* @param clientClass
* The class of a gRPC service generated by Akka gRPC
* @param service
* The name of the service to connect to, either a name of another Akka Serverless service or an external service
* where connection details are configured under `akka.grpc.client.[service-name]` in `application.conf`.
*/
def getGrpcClient[T](clientClass: Class[T], service: String): T
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package com.akkaserverless.scalasdk.impl.eventsourcedentity

import java.util.Optional
import scala.collection.immutable
import scala.compat.java8.DurationConverters._
import scala.jdk.CollectionConverters.SetHasAsJava
import scala.jdk.CollectionConverters.SetHasAsScala
import scala.jdk.OptionConverters._
Expand All @@ -39,9 +38,7 @@ import com.akkaserverless.scalasdk.eventsourcedentity.EventSourcedEntity
import com.akkaserverless.scalasdk.eventsourcedentity.EventSourcedEntityOptions
import com.akkaserverless.scalasdk.eventsourcedentity.EventSourcedEntityContext
import com.akkaserverless.scalasdk.eventsourcedentity.EventSourcedEntityProvider
import com.akkaserverless.scalasdk.PassivationStrategy
import com.akkaserverless.scalasdk.ServiceCallFactory
import com.akkaserverless.scalasdk.impl.MetadataImpl
import com.akkaserverless.scalasdk.impl.MetadataConverters
import com.akkaserverless.scalasdk.impl.PassivationStrategyConverters
import com.akkaserverless.scalasdk.impl.ScalaServiceCallFactoryAdapter
Expand Down Expand Up @@ -131,9 +128,6 @@ private[scalasdk] final class ScalaEventSourcedEntityContextAdapter(javasdkConte

def entityId: String = javasdkContext.entityId()

override def getGrpcClient[T](clientClass: Class[T], service: String): T =
javasdkContext.getGrpcClient(clientClass, service)

override def serviceCallFactory: ServiceCallFactory =
ScalaServiceCallFactoryAdapter(javasdkContext.serviceCallFactory())

Expand All @@ -143,15 +137,12 @@ private[scalasdk] final class ScalaEventSourcedEntityContextAdapter(javasdkConte
private[scalasdk] final class JavaCommandContextAdapter(val javasdkContext: JavaSdkCommandContext)
extends CommandContext {

override def sequenceNumber = javasdkContext.sequenceNumber()
override def sequenceNumber: Long = javasdkContext.sequenceNumber()

override def commandName: String = javasdkContext.commandName()

override def commandId: Long = javasdkContext.commandId()

override def getGrpcClient[T](clientClass: Class[T], service: String): T =
javasdkContext.getGrpcClient(clientClass, service)

override def serviceCallFactory: ServiceCallFactory =
ScalaServiceCallFactoryAdapter(javasdkContext.serviceCallFactory())

Expand All @@ -164,10 +155,7 @@ private[scalasdk] final class JavaCommandContextAdapter(val javasdkContext: Java
}

private[scalasdk] final class JavaEventContextAdapter(val javasdkContext: JavaSdkEventContext) extends EventContext {
override def sequenceNumber = javasdkContext.sequenceNumber()

override def getGrpcClient[T](clientClass: Class[T], service: String): T =
javasdkContext.getGrpcClient(clientClass, service)
override def sequenceNumber: Long = javasdkContext.sequenceNumber()

override def serviceCallFactory: ServiceCallFactory =
ScalaServiceCallFactoryAdapter(javasdkContext.serviceCallFactory())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import akka.stream.Materializer
import com.akkaserverless.javasdk
import com.akkaserverless.scalasdk.ServiceCallFactory
import com.akkaserverless.scalasdk.impl.MetadataConverters
import com.akkaserverless.scalasdk.impl.MetadataImpl
import com.akkaserverless.scalasdk.impl.PassivationStrategyConverters
import com.akkaserverless.scalasdk.impl.ScalaServiceCallFactoryAdapter
import com.akkaserverless.scalasdk.valueentity.CommandContext
Expand Down Expand Up @@ -112,9 +111,6 @@ private[scalasdk] final class ScalaCommandContextAdapter(val javaSdkContext: jav

override def commandId: Long = javaSdkContext.commandId()

override def getGrpcClient[T](clientClass: Class[T], service: String): T =
javaSdkContext.getGrpcClient(clientClass, service)

override def serviceCallFactory: ServiceCallFactory =
ScalaServiceCallFactoryAdapter(javaSdkContext.serviceCallFactory())

Expand All @@ -131,9 +127,6 @@ private[scalasdk] final class ScalaValueEntityContextAdapter(javaSdkContext: jav

def entityId: String = javaSdkContext.entityId()

override def getGrpcClient[T](clientClass: Class[T], service: String): T =
javaSdkContext.getGrpcClient(clientClass, service)

override def serviceCallFactory: ServiceCallFactory =
ScalaServiceCallFactoryAdapter(javaSdkContext.serviceCallFactory())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import com.akkaserverless.javasdk.view.ViewOptions
import com.akkaserverless.scalasdk.Metadata
import com.akkaserverless.scalasdk.ServiceCallFactory
import com.akkaserverless.scalasdk.impl.MetadataConverters
import com.akkaserverless.scalasdk.impl.MetadataImpl
import com.akkaserverless.scalasdk.impl.ScalaServiceCallFactoryAdapter
import com.akkaserverless.scalasdk.view.UpdateContext
import com.akkaserverless.scalasdk.view.View
Expand Down Expand Up @@ -85,9 +84,6 @@ private[scalasdk] final class ScalaViewCreationContextAdapter(javaSdkContext: ja
override def serviceCallFactory: ServiceCallFactory =
ScalaServiceCallFactoryAdapter(javaSdkContext.serviceCallFactory())

override def getGrpcClient[T](clientClass: Class[T], service: String): T =
javaSdkContext.getGrpcClient(clientClass, service)

override def materializer(): Materializer = javaSdkContext.materializer()
}

Expand All @@ -108,8 +104,5 @@ private[scalasdk] final class ScalaUpdateContextAdapter(val javaSdkContext: java
override def viewId: String =
javaSdkContext.viewId()

override def getGrpcClient[T](clientClass: Class[T], service: String): T =
javaSdkContext.getGrpcClient(clientClass, service)

override def materializer(): Materializer = javaSdkContext.materializer()
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,6 @@ private[scalasdk] final case class ScalaCommandContextAdapter(javaSdkCommandCont
override def serviceCallFactory: ServiceCallFactory =
ScalaServiceCallFactoryAdapter(javaSdkCommandContext.serviceCallFactory())

override def getGrpcClient[T](clientClass: Class[T], service: String): T =
javaSdkCommandContext.getGrpcClient(clientClass, service)

override def materializer(): Materializer =
javaSdkCommandContext.materializer()

Expand All @@ -157,9 +154,6 @@ private[scalasdk] final case class ScalaReplicatedEntityContextAdapter(javaSdkCo
override def serviceCallFactory: ServiceCallFactory = ScalaServiceCallFactoryAdapter(
javaSdkContext.serviceCallFactory())

override def getGrpcClient[T](clientClass: Class[T], service: String): T =
javaSdkContext.getGrpcClient(clientClass, service)

override def materializer(): Materializer =
javaSdkContext.materializer()
}
Expand Down