@@ -54,24 +54,56 @@ public static ActorRef of(SpawnClient client, String system, String name, String
5454 return new ActorRef (client , system , name , parent );
5555 }
5656
57- public <T extends GeneratedMessageV3 > Object invoke (String cmd , Class <T > outputType ) throws Exception {
58- Object res = invokeActor (cmd , Empty .getDefaultInstance (), outputType , Optional .empty ());
59- return outputType .cast (res );
57+ public <T extends GeneratedMessageV3 > Optional <Object > invoke (String cmd , Class <T > outputType ) throws Exception {
58+ Optional <Object > res = invokeActor (cmd , Empty .getDefaultInstance (), outputType , Optional .empty ());
59+ if (res .isPresent () ){
60+ return Optional .of (outputType .cast (res .get ()));
61+ }
62+
63+ return res ;
64+ }
65+
66+ public <T extends GeneratedMessageV3 > Optional <Object > invoke (String cmd , Class <T > outputType , InvocationOpts opts ) throws Exception {
67+ Optional <Object > res = invokeActor (cmd , Empty .getDefaultInstance (), outputType , Optional .ofNullable (opts ));
68+ if (res .isPresent () ){
69+ return Optional .of (outputType .cast (res .get ()));
70+ }
71+
72+ return res ;
73+ }
74+
75+ public <T extends GeneratedMessageV3 , S extends GeneratedMessageV3 > Optional <Object > invoke (String cmd , S value , Class <T > outputType ) throws Exception {
76+ Optional <Object > res = invokeActor (cmd , value , outputType , Optional .empty ());
77+ if (res .isPresent () ){
78+ return Optional .of (outputType .cast (res .get ()));
79+ }
80+
81+ return res ;
82+ }
83+
84+ public <T extends GeneratedMessageV3 , S extends GeneratedMessageV3 > Optional <Object > invoke (String cmd , S value , Class <T > outputType , InvocationOpts opts ) throws Exception {
85+ Optional <Object > res = invokeActor (cmd , value , outputType , Optional .ofNullable (opts ));
86+ if (res .isPresent () ){
87+ return Optional .of (outputType .cast (res .get ()));
88+ }
89+
90+ return res ;
91+ }
92+
93+ public <T extends GeneratedMessageV3 > void invokeAsync (String cmd , Class <T > outputType ) throws Exception {
94+ invokeActor (cmd , Empty .getDefaultInstance (), outputType , Optional .empty ());
6095 }
6196
62- public <T extends GeneratedMessageV3 > Object invoke (String cmd , Class <T > outputType , Optional <InvocationOpts > opts ) throws Exception {
63- Object res = invokeActor (cmd , Empty .getDefaultInstance (), outputType , opts );
64- return outputType .cast (res );
97+ public <T extends GeneratedMessageV3 > void invokeAsync (String cmd , Class <T > outputType , InvocationOpts opts ) throws Exception {
98+ invokeActor (cmd , Empty .getDefaultInstance (), outputType , Optional .ofNullable (opts ));
6599 }
66100
67- public <T extends GeneratedMessageV3 , S extends GeneratedMessageV3 > Object invoke (String cmd , S value , Class <T > outputType ) throws Exception {
68- Object res = invokeActor (cmd , value , outputType , Optional .empty ());
69- return outputType .cast (res );
101+ public <T extends GeneratedMessageV3 , S extends GeneratedMessageV3 > void invokeAsync (String cmd , S value , Class <T > outputType ) throws Exception {
102+ invokeActor (cmd , value , outputType , Optional .empty ());
70103 }
71104
72- public <T extends GeneratedMessageV3 , S extends GeneratedMessageV3 > Object invoke (String cmd , S value , Class <T > outputType , Optional <InvocationOpts > opts ) throws Exception {
73- Object res = invokeActor (cmd , value , outputType , opts );
74- return outputType .cast (res );
105+ public <T extends GeneratedMessageV3 , S extends GeneratedMessageV3 > void invokeAsync (String cmd , S value , Class <T > outputType , InvocationOpts opts ) throws Exception {
106+ invokeActor (cmd , value , outputType , Optional .ofNullable (opts ));
75107 }
76108
77109 public String getActorSystem () {
@@ -113,7 +145,7 @@ private void spawnActor() throws Exception {
113145 this .client .spawn (req );
114146 }
115147
116- private <T extends GeneratedMessageV3 , S extends GeneratedMessageV3 > Object invokeActor (
148+ private <T extends GeneratedMessageV3 , S extends GeneratedMessageV3 > Optional < Object > invokeActor (
117149 String cmd , S argument , Class <T > outputType , Optional <InvocationOpts > options ) throws Exception {
118150 Protocol .InvocationRequest .Builder invocationRequestBuilder = Protocol .InvocationRequest .newBuilder ();
119151
@@ -153,11 +185,11 @@ private <T extends GeneratedMessageV3, S extends GeneratedMessageV3> Object invo
153185 throw new ActorNotFoundException ();
154186 case OK :
155187 if (resp .hasValue ()) {
156- return resp .getValue ().unpack (outputType );
188+ return Optional . of ( resp .getValue ().unpack (outputType ) );
157189 }
158- return null ;
190+ return Optional . empty () ;
159191 }
160192
161- throw new ActorNotFoundException ();
193+ return Optional . empty ();
162194 }
163195}
0 commit comments