15
15
*/
16
16
package org .springframework .modulith .events .support ;
17
17
18
- import java .lang .reflect .Method ;
19
18
import java .time .Duration ;
20
19
import java .util .Collection ;
21
20
import java .util .List ;
31
30
import org .springframework .context .ApplicationListener ;
32
31
import org .springframework .context .PayloadApplicationEvent ;
33
32
import org .springframework .context .event .AbstractApplicationEventMulticaster ;
34
- import org .springframework .context .event .ApplicationEventMulticaster ;
35
33
import org .springframework .context .event .ApplicationListenerMethodAdapter ;
36
34
import org .springframework .core .ResolvableType ;
37
35
import org .springframework .core .annotation .AnnotationAwareOrderComparator ;
46
44
import org .springframework .modulith .events .core .TargetEventPublication ;
47
45
import org .springframework .transaction .event .TransactionPhase ;
48
46
import org .springframework .transaction .event .TransactionalApplicationListener ;
49
- import org .springframework .transaction .event .TransactionalEventListener ;
50
47
import org .springframework .util .Assert ;
51
- import org .springframework .util .ReflectionUtils ;
52
48
53
49
/**
54
50
* An {@link ApplicationEventMulticaster} to register {@link EventPublication}s in an {@link EventPublicationRegistry}
@@ -65,17 +61,12 @@ public class PersistentApplicationEventMulticaster extends AbstractApplicationEv
65
61
implements IncompleteEventPublications , SmartInitializingSingleton {
66
62
67
63
private static final Logger LOGGER = LoggerFactory .getLogger (PersistentApplicationEventMulticaster .class );
68
- private static final Method SUPPORTS_METHOD = ReflectionUtils .findMethod (ApplicationListenerMethodAdapter .class ,
69
- "shouldHandle" , ApplicationEvent .class , Object [].class );
64
+
70
65
static final String REPUBLISH_ON_RESTART = "spring.modulith.republish-outstanding-events-on-restart" ;
71
66
72
67
private final @ NonNull Supplier <EventPublicationRegistry > registry ;
73
68
private final @ NonNull Supplier <Environment > environment ;
74
69
75
- static {
76
- ReflectionUtils .makeAccessible (SUPPORTS_METHOD );
77
- }
78
-
79
70
/**
80
71
* Creates a new {@link PersistentApplicationEventMulticaster} for the given {@link EventPublicationRegistry}.
81
72
*
@@ -228,18 +219,13 @@ private static Object getEventToPersist(ApplicationEvent event) {
228
219
: event ;
229
220
}
230
221
231
- @ SuppressWarnings ("null" )
232
222
private static boolean matches (ApplicationEvent event , Object payload , ApplicationListener <?> listener ) {
233
223
234
224
// Verify general listener matching by eagerly evaluating the condition
235
- if (ApplicationListenerMethodAdapter .class .isInstance (listener )) {
225
+ if (ApplicationListenerMethodAdapter .class .isInstance (listener )
226
+ && !((ApplicationListenerMethodAdapter ) listener ).shouldHandle (event )) {
236
227
237
- boolean result = (boolean ) ReflectionUtils .invokeMethod (SUPPORTS_METHOD , listener , event ,
238
- new Object [] { payload });
239
-
240
- if (!result ) {
241
- return false ;
242
- }
228
+ return false ;
243
229
}
244
230
245
231
return ConditionalEventListener .class .isInstance (listener )
0 commit comments