@@ -45,7 +45,7 @@ protected static ActorRef of(SpawnClient client, Cache<ActorOuterClass.ActorId,
4545 if (identity .isParent ()) {
4646 actorId = buildActorId (identity .getSystem (), identity .getName (), identity .getParent ());
4747
48- spawnActor (actorId , client );
48+ // spawnActor(actorId, client);
4949 } else {
5050 actorId = buildActorId (identity .getSystem (), identity .getName ());
5151 }
@@ -207,9 +207,9 @@ public <T extends GeneratedMessageV3> void invokeAsync(String action, Invocation
207207 * @param value the action argument object.
208208 * @since 0.0.1
209209 */
210- public <T extends GeneratedMessageV3 , S extends GeneratedMessageV3 > void invokeAsync (String action , S value ) throws ActorInvocationException {
210+ public <T extends GeneratedMessageV3 > void invokeAsync (String action , T value ) throws ActorInvocationException {
211211 InvocationOpts opts = InvocationOpts .builder ().async (true ).build ();
212- invokeActor (action , value , null , Optional .of (opts ));
212+ invokeActorAsync (action , value , Optional .of (opts ));
213213 }
214214
215215 /**
@@ -223,15 +223,15 @@ public <T extends GeneratedMessageV3, S extends GeneratedMessageV3> void invokeA
223223 * Please see the {@link io.eigr.spawn.api.InvocationOpts} class for more information
224224 * @since 0.0.1
225225 */
226- public <T extends GeneratedMessageV3 , S extends GeneratedMessageV3 > void invokeAsync (String action , S value , InvocationOpts opts ) throws ActorInvocationException {
226+ public <T extends GeneratedMessageV3 > void invokeAsync (String action , T value , InvocationOpts opts ) throws ActorInvocationException {
227227 InvocationOpts mergedOpts = InvocationOpts .builder ()
228228 .async (true )
229229 .delaySeconds (opts .getDelaySeconds ())
230230 .scheduledTo (opts .getScheduledTo ())
231231 .timeoutSeconds (opts .getTimeoutSeconds ())
232232 .build ();
233233
234- invokeActor (action , value , null , Optional .of (mergedOpts ));
234+ invokeActorAsync (action , value , Optional .of (mergedOpts ));
235235 }
236236
237237 public String getActorSystem () {
@@ -264,6 +264,10 @@ private <T extends GeneratedMessageV3, S extends GeneratedMessageV3> Optional<T>
264264
265265 Protocol .InvocationRequest .Builder invocationRequestBuilder = Protocol .InvocationRequest .newBuilder ();
266266
267+ if (Objects .nonNull (this .actorId .getParent ()) && !this .actorId .getParent ().isEmpty ()) {
268+ invocationRequestBuilder .setRegisterRef (this .actorId .getParent ());
269+ }
270+
267271 Map <String , String > metadata = new HashMap <>();
268272 options .ifPresent (opts -> {
269273 invocationRequestBuilder .setAsync (opts .isAsync ());
@@ -285,6 +289,7 @@ private <T extends GeneratedMessageV3, S extends GeneratedMessageV3> Optional<T>
285289 .setActor (actorRef )
286290 .setActionName (cmd )
287291 .setValue (commandArg )
292+
288293 .putAllMetadata (metadata )
289294 .build ();
290295
@@ -312,4 +317,36 @@ private <T extends GeneratedMessageV3, S extends GeneratedMessageV3> Optional<T>
312317
313318 return Optional .empty ();
314319 }
320+
321+ private <T extends GeneratedMessageV3 , S extends GeneratedMessageV3 > void invokeActorAsync (
322+ String cmd , S argument , Optional <InvocationOpts > options ) {
323+ Objects .requireNonNull (this .actorId , "ActorId cannot be null" );
324+
325+ Protocol .InvocationRequest .Builder invocationRequestBuilder = Protocol .InvocationRequest .newBuilder ();
326+
327+ Map <String , String > metadata = new HashMap <>();
328+ options .ifPresent (opts -> {
329+ invocationRequestBuilder .setAsync (true );
330+ opts .getDelaySeconds ().ifPresent (invocationRequestBuilder ::setScheduledTo );
331+ // 'scheduledTo' override 'delay' if both is set.
332+ opts .getScheduledTo ()
333+ .ifPresent (scheduleTo -> invocationRequestBuilder .setScheduledTo (opts .getScheduleTimeInLong ()));
334+ });
335+
336+ final ActorOuterClass .Actor actorRef = ActorOuterClass .Actor .newBuilder ()
337+ .setId (this .actorId )
338+ .build ();
339+
340+ Any commandArg = Any .pack (argument );
341+
342+ invocationRequestBuilder
343+ .setSystem (ActorOuterClass .ActorSystem .newBuilder ().setName (this .actorId .getSystem ()).build ())
344+ .setActor (actorRef )
345+ .setActionName (cmd )
346+ .setValue (commandArg )
347+ .putAllMetadata (metadata )
348+ .build ();
349+
350+ this .client .invokeAsync (invocationRequestBuilder .build ());
351+ }
315352}
0 commit comments