@@ -17,7 +17,8 @@ JVM User Language Support for [Spawn](https://github.com/eigr/spawn).
17174 . [ Using Actors] ( #using-actors )
1818 - [ Call Named Actors] ( #call-named-actors )
1919 - [ Call Unnamed Actors] ( #call-unnamed-actors )
20- - [ Async and other options] ( #async-calls-and-other-options )
20+ - [ Async] ( #async )
21+ - [ Timeouts] ( #timeouts )
21225 . [ Deploy] ( #deploy )
2223 - [ Defining an ActorSystem] ( #defining-an-actorsytem )
2324 - [ Defining an ActorHost] ( #defining-an-actorhost )
@@ -92,7 +93,7 @@ The second thing we have to do is add the spawn dependency to the project.
9293<dependency >
9394 <groupId >com.github.eigr</groupId >
9495 <artifactId >spawn-java-std-sdk</artifactId >
95- <version >v0.6.2 </version >
96+ <version >v0.6.5 </version >
9697</dependency >
9798```
9899We're also going to configure a few things for our application build to work, including compiling the protobuf files.
@@ -126,7 +127,7 @@ See below a full example of the pom.xml file:
126127 <dependency >
127128 <groupId >com.github.eigr</groupId >
128129 <artifactId >spawn-java-std-sdk</artifactId >
129- <version >v0.6.2 </version >
130+ <version >v0.6.5 </version >
130131 </dependency >
131132 <dependency >
132133 <groupId >ch.qos.logback</groupId >
@@ -837,8 +838,8 @@ Domain.Request msg = Domain.Request.newBuilder()
837838 .setLanguage(" erlang" )
838839 .build();
839840
840- Optional<Object > maybeResponse = joeActor. invoke(" setLanguage" , msg, Domain . Reply . class);
841- Domain . Reply reply = ( Domain . Reply ) maybeResponse. get();
841+ Optional<Domain . Reply > maybeResponse = joeActor. invoke(" setLanguage" , msg, Domain . Reply . class);
842+ Domain . Reply reply = maybeResponse. get();
842843```
843844
844845More detailed in complete main class:
@@ -874,7 +875,7 @@ public class App {
874875 .build();
875876
876877 Optional<Object > maybeResponse = joeActor. invoke(" setLanguage" , msg, Domain . Reply . class);
877- Domain . Reply reply = ( Domain . Reply ) maybeResponse. get();
878+ Domain . Reply reply = maybeResponse. get();
878879 }
879880}
880881```
@@ -920,8 +921,8 @@ Domain.Request msg = Domain.Request.newBuilder()
920921 .setLanguage(" erlang" )
921922 .build();
922923
923- Optional<Object > maybeResponse = mike. invoke(" setLanguage" , msg, Domain . Reply . class);
924- Domain . Reply reply = ( Domain . Reply ) maybeResponse. get();
924+ Optional<Domain . Reply > maybeResponse = mike. invoke(" setLanguage" , msg, Domain . Reply . class);
925+ Domain . Reply reply = maybeResponse. get();
925926```
926927
927928The important part of the code above is the following snippet:
@@ -934,7 +935,7 @@ These tells Spawn that this actor will actually be named at runtime. The name pa
934935in this case is just a reference to "abs_actor" Actor that will be used later
935936so that we can actually create an instance of the real Actor.
936937
937- ### Async calls and other options
938+ ### Async
938939
939940Basically Spawn can perform actor functions in two ways. Synchronously, where the callee waits for a response,
940941or asynchronously, where the callee doesn't care about the return value of the call.
@@ -947,6 +948,45 @@ Therefore, to call an actor's function asynchronously, just use the invokeAsync
947948mike. invokeAsync(" setLanguage" , msg);
948949```
949950
951+ ### Timeouts
952+
953+ It is possible to change the request waiting timeout using the invocation options as below:
954+
955+ ``` Java
956+ package io.eigr.spawn.java.demo ;
957+
958+ import io.eigr.spawn.api.ActorRef ;
959+ import io.eigr.spawn.api.InvocationOpts ;
960+ import io.eigr.spawn.api.Spawn ;
961+ import io.eigr.spawn.api.TransportOpts ;
962+ import io.eigr.spawn.java.demo.domain.Domain ;
963+
964+ import java.util.Optional ;
965+
966+ public class App {
967+ public static void main (String [] args ) throws Exception {
968+ Spawn spawnSystem = new Spawn .SpawnSystem ()
969+ .create(" spawn-system" )
970+ .withActor(Joe . class)
971+ .build();
972+
973+ spawnSystem. start();
974+
975+ ActorRef joeActor = spawnSystem. createActorRef(" spawn-system" , " joe" );
976+
977+ Domain . Request msg = Domain . Request . newBuilder()
978+ .setLanguage(" erlang" )
979+ .build();
980+
981+ InvocationOpts opts = InvocationOpts . builder()
982+ .timeoutSeconds(Duration . ofSeconds(30 ))
983+ .build();
984+
985+ Optional<Domain . Reply > maybeResponse = joeActor. invoke(" setLanguage" , msg, Domain . Reply . class, opts);
986+ }
987+ }
988+ ```
989+
950990## Deploy
951991
952992See [ Getting Started] ( https://github.com/eigr/spawn#getting-started ) section from the main Spawn repository for more
0 commit comments