Skip to content

Commit

Permalink
chore: Populate ComponentDescriptor once, in SdkRunner (#81)
Browse files Browse the repository at this point in the history
* once per class instead of for each entity instance
* used for the command handler lookup
  • Loading branch information
patriknw authored Dec 11, 2024
1 parent cf7fae3 commit 83b6ce3
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 11 deletions.
6 changes: 3 additions & 3 deletions akka-javasdk/src/main/scala/akka/javasdk/impl/SdkRunner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,8 @@ private final class Sdk(
logger.debug(s"Registering Workflow [${clz.getName}]")
new WorkflowImpl[S, W](
factoryContext.workflowId,
clz,
serializer,
ComponentDescriptor.descriptorFor(clz, serializer),
timerClient = runtimeComponentClients.timerClient,
sdkExecutionContext,
sdkTracerFactory,
Expand Down Expand Up @@ -435,9 +435,9 @@ private final class Sdk(
sdkSettings,
sdkTracerFactory,
componentId,
clz,
factoryContext.entityId,
serializer,
ComponentDescriptor.descriptorFor(clz, serializer),
context =>
wiredInstance(clz.asInstanceOf[Class[EventSourcedEntity[AnyRef, AnyRef]]]) {
// remember to update component type API doc and docs if changing the set of injectables
Expand All @@ -457,9 +457,9 @@ private final class Sdk(
sdkSettings,
sdkTracerFactory,
componentId,
clz,
factoryContext.entityId,
serializer,
ComponentDescriptor.descriptorFor(clz, serializer),
context =>
wiredInstance(clz.asInstanceOf[Class[KeyValueEntity[AnyRef]]]) {
// remember to update component type API doc and docs if changing the set of injectables
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,16 @@ private[impl] final class EventSourcedEntityImpl[S, E, ES <: EventSourcedEntity[
configuration: Settings,
tracerFactory: () => Tracer,
componentId: String,
componentClass: Class[_],
entityId: String,
serializer: JsonSerializer,
componentDescriptor: ComponentDescriptor,
factory: EventSourcedEntityContext => ES)
extends SpiEventSourcedEntity {
import EventSourcedEntityImpl._

// FIXME
// private val traceInstrumentation = new TraceInstrumentation(componentId, EventSourcedEntityCategory, tracerFactory)

private val componentDescriptor = ComponentDescriptor.descriptorFor(componentClass, serializer)

private val router: ReflectiveEventSourcedEntityRouter[AnyRef, AnyRef, EventSourcedEntity[AnyRef, AnyRef]] = {
val context = new EventSourcedEntityContextImpl(entityId)
new ReflectiveEventSourcedEntityRouter[S, E, ES](factory(context), componentDescriptor.commandHandlers, serializer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ private[impl] final class KeyValueEntityImpl[S, KV <: KeyValueEntity[S]](
configuration: Settings,
tracerFactory: () => Tracer,
componentId: String,
componentClass: Class[_],
entityId: String,
serializer: JsonSerializer,
componentDescriptor: ComponentDescriptor,
factory: KeyValueEntityContext => KV)
extends SpiEventSourcedEntity {
import KeyValueEntityEffectImpl._
Expand All @@ -87,8 +87,6 @@ private[impl] final class KeyValueEntityImpl[S, KV <: KeyValueEntity[S]](
// FIXME
// private val traceInstrumentation = new TraceInstrumentation(componentId, EventSourcedEntityCategory, tracerFactory)

private val componentDescriptor = ComponentDescriptor.descriptorFor(componentClass, serializer)

private val router: ReflectiveKeyValueEntityRouter[AnyRef, KeyValueEntity[AnyRef]] = {
val context = new KeyValueEntityContextImpl(entityId)
new ReflectiveKeyValueEntityRouter[S, KV](factory(context), componentDescriptor.commandHandlers, serializer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,14 @@ import kalix.protocol.workflow_entity.WorkflowEntities
@InternalApi
class WorkflowImpl[S, W <: Workflow[S]](
workflowId: String,
componentClass: Class[_],
serializer: JsonSerializer,
componentDescriptor: ComponentDescriptor,
timerClient: TimerClient,
sdkExecutionContext: ExecutionContext,
tracerFactory: () => Tracer,
instanceFactory: Function[WorkflowContext, W])
extends SpiWorkflow {

private val componentDescriptor = ComponentDescriptor.descriptorFor(componentClass, serializer)
private val context = new WorkflowContextImpl(workflowId)

private val router =
Expand Down

0 comments on commit 83b6ce3

Please sign in to comment.