55import io .eigr .functions .protocol .actors .ActorOuterClass ;
66import io .eigr .spawn .api .actors .ActorFactory ;
77import io .eigr .spawn .api .actors .ActorRef ;
8- import io .eigr .spawn .api .actors .annotations .NamedActor ;
9- import io .eigr .spawn .api .actors .annotations .PooledActor ;
10- import io .eigr .spawn .api .actors .annotations .UnNamedActor ;
8+ import io .eigr .spawn .api .actors .annotations .stateful .StatefulNamedActor ;
9+ import io .eigr .spawn .api .actors .annotations .stateful .StatefulPooledActor ;
10+ import io .eigr .spawn .api .actors .annotations .stateful .StatefulUnNamedActor ;
11+ import io .eigr .spawn .api .actors .annotations .stateless .StatelessNamedActor ;
12+ import io .eigr .spawn .api .actors .annotations .stateless .StatelessPooledActor ;
13+ import io .eigr .spawn .api .actors .annotations .stateless .StatelessUnNamedActor ;
1114import io .eigr .spawn .internal .Entity ;
1215import io .eigr .spawn .internal .client .OkHttpSpawnClient ;
1316import io .eigr .spawn .internal .client .SpawnClient ;
@@ -33,14 +36,11 @@ public final class Spawn {
3336 private final SpawnClient client ;
3437
3538 private final int port ;
36-
37- private String host ;
38-
3939 private final String proxyHost ;
4040 private final int proxyPort ;
4141 private final String system ;
4242 private final List <Entity > entities ;
43-
43+ private String host ;
4444 private Optional <Executor > optionalExecutor ;
4545
4646
@@ -124,14 +124,20 @@ private void registerActorSystem() throws Exception {
124124
125125 private Map <String , ActorOuterClass .Actor > getActors (List <Entity > entities ) {
126126 return entities .stream ().map (actorEntity -> {
127- ActorOuterClass .ActorSnapshotStrategy snapshotStrategy =
128- ActorOuterClass .ActorSnapshotStrategy .newBuilder ()
129- .setTimeout (
130- ActorOuterClass .TimeoutStrategy .newBuilder ()
131- .setTimeout (actorEntity .getSnapshotTimeout ())
132- .build ()
133- )
134- .build ();
127+ ActorOuterClass .ActorSnapshotStrategy snapshotStrategy ;
128+ if (actorEntity .isStateful ()) {
129+ snapshotStrategy =
130+ ActorOuterClass .ActorSnapshotStrategy .newBuilder ()
131+ .setTimeout (
132+ ActorOuterClass .TimeoutStrategy .newBuilder ()
133+ .setTimeout (actorEntity .getSnapshotTimeout ())
134+ .build ()
135+ )
136+ .build ();
137+ } else {
138+ snapshotStrategy = ActorOuterClass .ActorSnapshotStrategy .newBuilder ().build ();
139+ }
140+
135141
136142 ActorOuterClass .ActorDeactivationStrategy deactivateStrategy =
137143 ActorOuterClass .ActorDeactivationStrategy .newBuilder ()
@@ -220,8 +226,8 @@ public String toString() {
220226
221227 public static final class SpawnSystem {
222228
223- private SpawnClient client ;
224229 private final List <Entity > entities = new ArrayList <>();
230+ private SpawnClient client ;
225231 private int port = 8091 ;
226232 private String host = "127.0.0.1" ;
227233 private String proxyHost = "127.0.0.1" ;
@@ -282,38 +288,68 @@ public Spawn build() {
282288 }
283289
284290 private Optional <Entity > getEntity (Class <?> actorKlass ) {
285- if (Objects .nonNull (actorKlass .getAnnotation (NamedActor .class ))) {
291+ Optional <Entity > maybeEntity = getStatefulEntity (actorKlass , null , null );
292+
293+ if (maybeEntity .isPresent ()) {
294+ return maybeEntity ;
295+ }
296+
297+ maybeEntity = getStatelessEntity (actorKlass , null , null );
298+ if (maybeEntity .isPresent ()) {
299+ return maybeEntity ;
300+ }
301+
302+ return Optional .empty ();
303+ }
304+
305+ private Optional <Entity > getEntity (Class <?> actorKlass , Object arg , ActorFactory factory ) {
306+ Optional <Entity > maybeEntity = getStatefulEntity (actorKlass , arg , factory );
307+
308+ if (maybeEntity .isPresent ()) {
309+ return maybeEntity ;
310+ }
311+
312+ maybeEntity = getStatelessEntity (actorKlass , arg , factory );
313+ if (maybeEntity .isPresent ()) {
314+ return maybeEntity ;
315+ }
316+
317+ return Optional .empty ();
318+ }
319+
320+ private Optional <Entity > getStatefulEntity (Class <?> actorKlass , Object arg , ActorFactory factory ) {
321+ if (Objects .nonNull (actorKlass .getAnnotation (StatefulNamedActor .class ))) {
286322 return Optional .of (Entity .fromAnnotationToEntity (
287- actorKlass , actorKlass .getAnnotation (NamedActor .class ), null , null ));
323+ actorKlass , actorKlass .getAnnotation (StatefulNamedActor .class ), arg , factory ));
288324 }
289325
290- if (Objects .nonNull (actorKlass .getAnnotation (UnNamedActor .class ))) {
326+ if (Objects .nonNull (actorKlass .getAnnotation (StatefulUnNamedActor .class ))) {
291327 return Optional .of (Entity .fromAnnotationToEntity (
292- actorKlass , actorKlass .getAnnotation (UnNamedActor .class ), null , null ));
328+ actorKlass , actorKlass .getAnnotation (StatefulUnNamedActor .class ), arg , factory ));
293329 }
294330
295- if (Objects .nonNull (actorKlass .getAnnotation (PooledActor .class ))) {
331+ if (Objects .nonNull (actorKlass .getAnnotation (StatefulPooledActor .class ))) {
296332 return Optional .of (Entity .fromAnnotationToEntity (
297- actorKlass , actorKlass .getAnnotation (PooledActor .class ), null , null ));
333+ actorKlass , actorKlass .getAnnotation (StatefulPooledActor .class ), arg , factory ));
298334 }
299335
300336 return Optional .empty ();
301337 }
302338
303- private Optional <Entity > getEntity (Class <?> actorType , Object arg , ActorFactory factory ) {
304- if (Objects .nonNull (actorType .getAnnotation (NamedActor .class ))) {
305- NamedActor annotation = actorType . getAnnotation ( NamedActor . class );
306- return Optional . of ( Entity . fromAnnotationToEntity ( actorType , annotation , arg , factory ));
339+ private Optional <Entity > getStatelessEntity (Class <?> actorKlass , Object arg , ActorFactory factory ) {
340+ if (Objects .nonNull (actorKlass .getAnnotation (StatelessNamedActor .class ))) {
341+ return Optional . of ( Entity . fromAnnotationToEntity (
342+ actorKlass , actorKlass . getAnnotation ( StatelessNamedActor . class ) , arg , factory ));
307343 }
308344
309- if (Objects .nonNull (actorType .getAnnotation (UnNamedActor .class ))) {
310- UnNamedActor annotation = actorType . getAnnotation ( UnNamedActor . class );
311- return Optional . of ( Entity . fromAnnotationToEntity ( actorType , annotation , arg , factory ));
345+ if (Objects .nonNull (actorKlass .getAnnotation (StatelessUnNamedActor .class ))) {
346+ return Optional . of ( Entity . fromAnnotationToEntity (
347+ actorKlass , actorKlass . getAnnotation ( StatelessUnNamedActor . class ) , arg , factory ));
312348 }
313349
314- if (Objects .nonNull (actorType .getAnnotation (PooledActor .class ))) {
315- PooledActor annotation = actorType . getAnnotation ( PooledActor . class );
316- return Optional . of ( Entity . fromAnnotationToEntity ( actorType , annotation , arg , factory ));
350+ if (Objects .nonNull (actorKlass .getAnnotation (StatelessPooledActor .class ))) {
351+ return Optional . of ( Entity . fromAnnotationToEntity (
352+ actorKlass , actorKlass . getAnnotation ( StatelessPooledActor . class ) , arg , factory ));
317353 }
318354
319355 return Optional .empty ();
0 commit comments