32
32
import org .springframework .beans .factory .ListableBeanFactory ;
33
33
import org .springframework .core .annotation .AnnotationUtils ;
34
34
import org .springframework .statemachine .StateContext ;
35
+ import org .springframework .statemachine .StateMachineSystemConstants ;
35
36
import org .springframework .statemachine .annotation .OnEventNotAccepted ;
36
37
import org .springframework .statemachine .annotation .OnExtendedStateChanged ;
37
38
import org .springframework .statemachine .annotation .OnStateChanged ;
@@ -92,10 +93,10 @@ public void afterPropertiesSet() throws Exception {
92
93
// don't check name if id is set as name defaults to
93
94
// 'stateMachine' and would cause additional cache entry
94
95
if (StringUtils .hasText (withStateMachine .id ())) {
95
- updateCache (metaAnnotation .annotationType ().getName () + withStateMachine .id (),
96
+ updateCache (metaAnnotation .annotationType ().getName () +"_" + withStateMachine .id (),
96
97
new CacheEntry (handler , annotation , metaAnnotation ));
97
98
} else if (StringUtils .hasText (withStateMachine .name ())) {
98
- updateCache (metaAnnotation .annotationType ().getName () + withStateMachine .name (),
99
+ updateCache (metaAnnotation .annotationType ().getName () +"_" + withStateMachine .name (),
99
100
new CacheEntry (handler , annotation , metaAnnotation ));
100
101
}
101
102
}
@@ -118,7 +119,7 @@ public void callOnStateChanged(String stateMachineId, StateContext<S, E> stateCo
118
119
return ;
119
120
}
120
121
List <StateMachineHandler <? extends Annotation , S , E >> handlersList = new ArrayList <StateMachineHandler <? extends Annotation , S , E >>();
121
- String cacheKey = OnStateChanged .class .getName () + stateMachineId ;
122
+ String cacheKey = OnStateChanged .class .getName () +"_" + stateMachineId ;
122
123
List <CacheEntry > list = getCacheEntries (cacheKey );
123
124
if (list == null ) {
124
125
return ;
@@ -138,7 +139,7 @@ public void callOnStateEntry(String stateMachineId, StateContext<S, E> stateCont
138
139
return ;
139
140
}
140
141
List <StateMachineHandler <? extends Annotation , S , E >> handlersList = new ArrayList <StateMachineHandler <? extends Annotation , S , E >>();
141
- String cacheKey = OnStateEntry .class .getName () + stateMachineId ;
142
+ String cacheKey = OnStateEntry .class .getName () +"_" + stateMachineId ;
142
143
List <CacheEntry > list = getCacheEntries (cacheKey );
143
144
if (list == null ) {
144
145
return ;
@@ -158,7 +159,7 @@ public void callOnStateExit(String stateMachineId, StateContext<S, E> stateConte
158
159
return ;
159
160
}
160
161
List <StateMachineHandler <? extends Annotation , S , E >> handlersList = new ArrayList <StateMachineHandler <? extends Annotation , S , E >>();
161
- String cacheKey = OnStateExit .class .getName () + stateMachineId ;
162
+ String cacheKey = OnStateExit .class .getName () +"_" + stateMachineId ;
162
163
List <CacheEntry > list = getCacheEntries (cacheKey );
163
164
if (list == null ) {
164
165
return ;
@@ -178,7 +179,7 @@ public void callOnEventNotAccepted(String stateMachineId, StateContext<S, E> sta
178
179
return ;
179
180
}
180
181
List <StateMachineHandler <? extends Annotation , S , E >> handlersList = new ArrayList <StateMachineHandler <? extends Annotation , S , E >>();
181
- String cacheKey = OnEventNotAccepted .class .getName () + stateMachineId ;
182
+ String cacheKey = OnEventNotAccepted .class .getName () +"_" + stateMachineId ;
182
183
List <CacheEntry > list = getCacheEntries (cacheKey );
183
184
if (list == null ) {
184
185
return ;
@@ -202,7 +203,7 @@ public void callOnTransitionStart(String stateMachineId, StateContext<S, E> stat
202
203
return ;
203
204
}
204
205
List <StateMachineHandler <? extends Annotation , S , E >> handlersList = new ArrayList <StateMachineHandler <? extends Annotation , S , E >>();
205
- String cacheKey = OnTransitionStart .class .getName () + stateMachineId ;
206
+ String cacheKey = OnTransitionStart .class .getName () +"_" + stateMachineId ;
206
207
List <CacheEntry > list = getCacheEntries (cacheKey );
207
208
if (list == null ) {
208
209
return ;
@@ -222,7 +223,7 @@ public void callOnTransition(String stateMachineId, StateContext<S, E> stateCont
222
223
return ;
223
224
}
224
225
List <StateMachineHandler <? extends Annotation , S , E >> handlersList = new ArrayList <StateMachineHandler <? extends Annotation , S , E >>();
225
- String cacheKey = OnTransition .class .getName () + stateMachineId ;
226
+ String cacheKey = OnTransition .class .getName () +"_" + stateMachineId ;
226
227
List <CacheEntry > list = getCacheEntries (cacheKey );
227
228
if (list == null ) {
228
229
return ;
@@ -242,7 +243,7 @@ public void callOnTransitionEnd(String stateMachineId, StateContext<S, E> stateC
242
243
return ;
243
244
}
244
245
List <StateMachineHandler <? extends Annotation , S , E >> handlersList = new ArrayList <StateMachineHandler <? extends Annotation , S , E >>();
245
- String cacheKey = OnTransitionEnd .class .getName () + stateMachineId ;
246
+ String cacheKey = OnTransitionEnd .class .getName () +"_" + stateMachineId ;
246
247
List <CacheEntry > list = getCacheEntries (cacheKey );
247
248
if (list == null ) {
248
249
return ;
@@ -262,7 +263,7 @@ public void callOnStateMachineStart(String stateMachineId, StateContext<S, E> st
262
263
return ;
263
264
}
264
265
List <StateMachineHandler <? extends Annotation , S , E >> handlersList = new ArrayList <StateMachineHandler <? extends Annotation , S , E >>();
265
- String cacheKey = OnStateMachineStart .class .getName () + stateMachineId ;
266
+ String cacheKey = OnStateMachineStart .class .getName () +"_" + stateMachineId ;
266
267
List <CacheEntry > list = getCacheEntries (cacheKey );
267
268
if (list == null ) {
268
269
return ;
@@ -278,7 +279,7 @@ public void callOnStateMachineStop(String stateMachineId, StateContext<S, E> sta
278
279
return ;
279
280
}
280
281
List <StateMachineHandler <? extends Annotation , S , E >> handlersList = new ArrayList <StateMachineHandler <? extends Annotation , S , E >>();
281
- String cacheKey = OnStateMachineStop .class .getName () + stateMachineId ;
282
+ String cacheKey = OnStateMachineStop .class .getName () +"_" + stateMachineId ;
282
283
List <CacheEntry > list = getCacheEntries (cacheKey );
283
284
if (list == null ) {
284
285
return ;
@@ -294,7 +295,7 @@ public void callOnStateMachineError(String stateMachineId, StateContext<S, E> st
294
295
return ;
295
296
}
296
297
List <StateMachineHandler <? extends Annotation , S , E >> handlersList = new ArrayList <StateMachineHandler <? extends Annotation , S , E >>();
297
- String cacheKey = OnStateMachineError .class .getName () + stateMachineId ;
298
+ String cacheKey = OnStateMachineError .class .getName () +"_" + stateMachineId ;
298
299
List <CacheEntry > list = getCacheEntries (cacheKey );
299
300
if (list == null ) {
300
301
return ;
@@ -310,7 +311,7 @@ public void callOnExtendedStateChanged(String stateMachineId, Object key, Object
310
311
return ;
311
312
}
312
313
List <StateMachineHandler <? extends Annotation , S , E >> handlersList = new ArrayList <StateMachineHandler <? extends Annotation , S , E >>();
313
- String cacheKey = OnExtendedStateChanged .class .getName () + stateMachineId ;
314
+ String cacheKey = OnExtendedStateChanged .class .getName () +"_" + stateMachineId ;
314
315
List <CacheEntry > list = getCacheEntries (cacheKey );
315
316
if (list == null ) {
316
317
return ;
@@ -347,7 +348,15 @@ private synchronized List<CacheEntry> getCacheEntries(String cacheKey) {
347
348
}
348
349
}
349
350
}
350
- return cache .get (cacheKey );
351
+ //Try to get the CacheEntry using the provided key
352
+ //Or use default machine name in the key
353
+ if (cache .containsKey (cacheKey )) {
354
+ return cache .get (cacheKey );
355
+ } else {
356
+ cacheKey = cacheKey .replaceFirst (cacheKey .substring (cacheKey .indexOf ("_" )+1 ),
357
+ StateMachineSystemConstants .DEFAULT_ID_STATEMACHINE );
358
+ return cache .get (cacheKey );
359
+ }
351
360
}
352
361
353
362
private boolean annotationHandlerVariableMatch (Annotation annotation , Object key ) {
0 commit comments