2020import java .time .Duration ;
2121import java .time .Instant ;
2222import java .util .ArrayList ;
23- import java .util .Date ;
2423import java .util .List ;
2524import java .util .Map ;
2625import java .util .NoSuchElementException ;
3231 */
3332public class ActorStateManager {
3433
34+ private static final StateChangeMetadata REMOVE_STATE_CHANGE_METADATA =
35+ new StateChangeMetadata (ActorStateChangeKind .REMOVE , null , null );
36+
3537 /**
3638 * Provides states using a state store.
3739 */
@@ -206,9 +208,10 @@ public <T> Mono<Void> set(String stateName, T value, Duration ttl) {
206208 .switchIfEmpty (this .stateProvider .contains (this .actorTypeName , this .actorId , stateName )
207209 .map (exists -> {
208210 var expiration = buildExpiration (ttl );
211+ ActorStateChangeKind changeKind = exists ? ActorStateChangeKind .UPDATE : ActorStateChangeKind .ADD ;
209212 this .stateChangeTracker .put (stateName ,
210213 new StateChangeMetadata (
211- exists ? ActorStateChangeKind . UPDATE : ActorStateChangeKind . ADD , value , expiration ));
214+ changeKind , value , expiration ));
212215 return exists ;
213216 }))
214217 .then ();
@@ -238,7 +241,7 @@ public Mono<Void> remove(String stateName) {
238241 return true ;
239242 }
240243
241- this .stateChangeTracker .put (stateName , new StateChangeMetadata ( ActorStateChangeKind . REMOVE , null , null ) );
244+ this .stateChangeTracker .put (stateName , REMOVE_STATE_CHANGE_METADATA );
242245 return true ;
243246 }
244247
@@ -248,7 +251,7 @@ public Mono<Void> remove(String stateName) {
248251 .switchIfEmpty (this .stateProvider .contains (this .actorTypeName , this .actorId , stateName ))
249252 .filter (exists -> exists )
250253 .map (exists -> {
251- this .stateChangeTracker .put (stateName , new StateChangeMetadata ( ActorStateChangeKind . REMOVE , null , null ) );
254+ this .stateChangeTracker .put (stateName , REMOVE_STATE_CHANGE_METADATA );
252255 return exists ;
253256 })
254257 .then ();
0 commit comments