Skip to content

Commit 40fa39e

Browse files
committed
Fix. Timer Actions and channels
1 parent ba864a8 commit 40fa39e

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

src/main/java/io/eigr/spawn/Spawn.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import io.eigr.spawn.internal.client.OkHttpSpawnClient;
1212
import io.eigr.spawn.internal.client.SpawnClient;
1313
import io.eigr.spawn.internal.handlers.ActorServiceHandler;
14+
import org.slf4j.Logger;
15+
import org.slf4j.LoggerFactory;
1416

1517
import java.io.IOException;
1618
import java.net.InetSocketAddress;
@@ -23,6 +25,7 @@
2325
* Spawn SDK Entrypoint
2426
*/
2527
public final class Spawn {
28+
private static final Logger log = LoggerFactory.getLogger(Spawn.class);
2629

2730
private final SpawnClient client;
2831

@@ -102,6 +105,8 @@ private void registerActorSystem() throws Exception {
102105
.setServiceInfo(si)
103106
.setActorSystem(actorSystem)
104107
.build();
108+
109+
log.debug("Registering Actors on Proxy. Registry: {}", req);
105110
this.client.register(req);
106111
}
107112

@@ -136,6 +141,7 @@ private Map<String, ActorOuterClass.Actor> getActors(List<Entity> entities) {
136141

137142
Map<String, String> tags = new HashMap<>();
138143
ActorOuterClass.Metadata metadata = ActorOuterClass.Metadata.newBuilder()
144+
.setChannelGroup(actorEntity.getChannel())
139145
.putAllTags(tags)
140146
.build();
141147

@@ -170,7 +176,7 @@ private List<ActorOuterClass.Action> getCommands(Entity actorEntity) {
170176
}
171177

172178
private List<ActorOuterClass.FixedTimerAction> getTimerCommands(Entity actorEntity) {
173-
return actorEntity.getActions()
179+
List<ActorOuterClass.FixedTimerAction> timerActions = actorEntity.getTimerActions()
174180
.values()
175181
.stream()
176182
.filter(v -> Entity.EntityMethodType.TIMER.equals(v.getType()))
@@ -184,6 +190,9 @@ private List<ActorOuterClass.FixedTimerAction> getTimerCommands(Entity actorEnti
184190
.build()
185191
)
186192
.collect(Collectors.toList());
193+
194+
log.debug("Actor have TimeActions: {}", timerActions);
195+
return timerActions;
187196
}
188197

189198
public static final class SpawnSystem {

src/main/java/io/eigr/spawn/internal/Entity.java

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ public final class Entity {
3131
private int minPoolSize;
3232
private int maxPoolSize;
3333

34+
private String channel;
35+
3436
public Entity(
3537
String actorName,
3638
Class<?> actorType,
@@ -43,7 +45,8 @@ public Entity(
4345
Map<String, EntityMethod> actions,
4446
Map<String, EntityMethod> timerActions,
4547
int minPoolSize,
46-
int maxPoolSize) {
48+
int maxPoolSize,
49+
String channel) {
4750
this.actorName = actorName;
4851
this.actorType = actorType;
4952
this.kind = kind;
@@ -56,6 +59,7 @@ public Entity(
5659
this.timerActions = timerActions;
5760
this.minPoolSize = minPoolSize;
5861
this.maxPoolSize = maxPoolSize;
62+
this.channel = channel;
5963
}
6064

6165
public String getActorName() {
@@ -98,6 +102,10 @@ public Map<String, EntityMethod> getActions() {
98102
return actions;
99103
}
100104

105+
public Map<String, EntityMethod> getTimerActions() {
106+
return timerActions;
107+
}
108+
101109
public int getMinPoolSize() {
102110
return minPoolSize;
103111
}
@@ -106,6 +114,8 @@ public int getMaxPoolSize() {
106114
return maxPoolSize;
107115
}
108116

117+
public String getChannel(){ return channel; }
118+
109119
public enum EntityMethodType {
110120
DIRECT, TIMER
111121
}
@@ -184,6 +194,7 @@ public String toString() {
184194
sb.append(", timerActions=").append(timerActions);
185195
sb.append(", minPoolSize=").append(minPoolSize);
186196
sb.append(", maxPoolSize=").append(maxPoolSize);
197+
sb.append(", channel=").append(channel);
187198
sb.append('}');
188199
return sb.toString();
189200
}
@@ -204,6 +215,7 @@ public static Entity fromAnnotationToEntity(Class<?> entity, NamedActor actor) {
204215
final Class stateType = actor.stateType();
205216
final int minPoolSize = actor.minPoolSize();
206217
final int maxPoolSize = actor.maxPoolSize();
218+
final String channel = actor.channel();
207219

208220
final Map<String, Entity.EntityMethod> actions = buildActions(entity, Action.class);
209221
final Map<String, Entity.EntityMethod> timerActions = buildActions(entity, TimerAction.class);
@@ -220,7 +232,9 @@ public static Entity fromAnnotationToEntity(Class<?> entity, NamedActor actor) {
220232
actions,
221233
timerActions,
222234
minPoolSize,
223-
maxPoolSize);
235+
maxPoolSize,
236+
channel
237+
);
224238

225239
log.info("Registering NamedActor: {}", actorName);
226240
log.debug("Registering Entity -> {}", entityType);
@@ -243,6 +257,7 @@ public static Entity fromAnnotationToEntity(Class<?> entity, UnNamedActor actor)
243257
final Class stateType = actor.stateType();
244258
final int minPoolSize = actor.minPoolSize();
245259
final int maxPoolSize = actor.maxPoolSize();
260+
final String channel = actor.channel();
246261

247262
final Map<String, Entity.EntityMethod> actions = buildActions(entity, Action.class);
248263
final Map<String, Entity.EntityMethod> timerActions = buildActions(entity, TimerAction.class);
@@ -259,7 +274,8 @@ public static Entity fromAnnotationToEntity(Class<?> entity, UnNamedActor actor)
259274
actions,
260275
timerActions,
261276
minPoolSize,
262-
maxPoolSize);
277+
maxPoolSize,
278+
channel);
263279

264280
log.info("Registering UnNamedActor: {}", actorName);
265281
log.debug("Registering Entity -> {}", entityType);
@@ -283,6 +299,7 @@ public static Entity fromAnnotationToEntity(Class<?> entity, PooledActor actor)
283299
final Class stateType = actor.stateType();
284300
final int minPoolSize = actor.minPoolSize();
285301
final int maxPoolSize = actor.maxPoolSize();
302+
final String channel = actor.channel();
286303

287304
final Map<String, Entity.EntityMethod> actions = buildActions(entity, Action.class);
288305
final Map<String, Entity.EntityMethod> timerActions = buildActions(entity, TimerAction.class);
@@ -299,7 +316,8 @@ public static Entity fromAnnotationToEntity(Class<?> entity, PooledActor actor)
299316
actions,
300317
timerActions,
301318
minPoolSize,
302-
maxPoolSize);
319+
maxPoolSize,
320+
channel);
303321

304322
log.info("Registering PooledActor: {}", actorName);
305323
log.debug("Registering Entity -> {}", entityType);

0 commit comments

Comments
 (0)