1
1
/*
2
- * Copyright 2016-2021 the original author or authors.
2
+ * Copyright 2016-2022 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
19
19
import reactor .core .publisher .Mono ;
20
20
21
21
import java .util .Arrays ;
22
+ import java .util .Collection ;
23
+ import java .util .Collections ;
24
+ import java .util .Map ;
22
25
import java .util .Optional ;
23
26
24
27
import org .springframework .core .ReactiveTypeDescriptor ;
25
28
import org .springframework .data .util .ProxyUtils ;
26
29
import org .springframework .data .util .ReflectionUtils ;
27
30
import org .springframework .util .Assert ;
28
31
import org .springframework .util .ClassUtils ;
32
+ import org .springframework .util .ConcurrentReferenceHashMap ;
29
33
30
34
/**
31
35
* Utility class to expose details about reactive wrapper types. This class exposes whether a reactive wrapper is
@@ -65,6 +69,11 @@ public abstract class ReactiveWrappers {
65
69
private static final boolean MUTINY_PRESENT = ClassUtils .isPresent ("io.smallrye.mutiny.Multi" ,
66
70
ReactiveWrappers .class .getClassLoader ());
67
71
72
+ private static final Map <Class <?>, Boolean > IS_REACTIVE_TYPE = new ConcurrentReferenceHashMap <>();
73
+
74
+ private static final boolean IS_REACTIVE_AVAILABLE = Arrays .stream (ReactiveLibrary .values ())
75
+ .anyMatch (ReactiveWrappers ::isAvailable );
76
+
68
77
private ReactiveWrappers () {}
69
78
70
79
/**
@@ -84,7 +93,7 @@ public enum ReactiveLibrary {
84
93
* @return {@literal true} if reactive support is available.
85
94
*/
86
95
public static boolean isAvailable () {
87
- return Arrays . stream ( ReactiveLibrary . values ()). anyMatch ( ReactiveWrappers :: isAvailable ) ;
96
+ return IS_REACTIVE_AVAILABLE ;
88
97
}
89
98
90
99
/**
@@ -118,7 +127,7 @@ public static boolean isAvailable(ReactiveLibrary reactiveLibrary) {
118
127
* @return {@literal true} if the {@code type} is a supported reactive wrapper type.
119
128
*/
120
129
public static boolean supports (Class <?> type ) {
121
- return isAvailable () && isWrapper (ProxyUtils .getUserClass (type ));
130
+ return isAvailable () && IS_REACTIVE_TYPE . computeIfAbsent ( type , key -> isWrapper (ProxyUtils .getUserClass (key ) ));
122
131
}
123
132
124
133
/**
0 commit comments