Skip to content

Commit 9ebdf17

Browse files
authored
Add AOT reflect hints for reactive caffeine cache (#456)
The shaded Caffeine lib used by the Reactive client had an incorrect prefix of 'org.springframework.pulsar'. This commit adjust the prefix to 'org.apache.pulsar.reactive'. Doing so surfaced more classes that needed to be registered for relective hints.
1 parent 981eb05 commit 9ebdf17

File tree

2 files changed

+80
-16
lines changed

2 files changed

+80
-16
lines changed

spring-pulsar-reactive/src/main/java/org/springframework/pulsar/reactive/aot/ReactivePulsarRuntimeHints.java

Lines changed: 70 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,13 @@
4040
import org.springframework.aot.hint.RuntimeHintsRegistrar;
4141
import org.springframework.aot.hint.TypeReference;
4242
import org.springframework.lang.Nullable;
43+
import org.springframework.util.ReflectionUtils;
4344

4445
/**
45-
* {@link RuntimeHintsRegistrar} for Spring for Apache Pulsar.
46+
* {@link RuntimeHintsRegistrar} for Spring for Apache Pulsar (reactive).
4647
*
4748
* @author Soby Chacko
49+
* @author Chris Bono
4850
*/
4951
public class ReactivePulsarRuntimeHints implements RuntimeHintsRegistrar {
5052

@@ -74,8 +76,7 @@ public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader)
7476
MemberCategory.DECLARED_CLASSES, MemberCategory.DECLARED_FIELDS)));
7577

7678
// These are inaccessible interfaces/classes in a normal scenario, thus using the
77-
// String version,
78-
// and we need field level access in them.
79+
// String version, and we need field level access in them.
7980
Stream.of(
8081
"org.apache.pulsar.shade.io.netty.util.internal.shaded.org.jctools.queues.BaseMpscLinkedArrayQueueProducerFields",
8182
"org.apache.pulsar.shade.io.netty.util.internal.shaded.org.jctools.queues.BaseMpscLinkedArrayQueueConsumerFields",
@@ -86,13 +87,72 @@ public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader)
8687
.forEach(typeName -> reflectionHints.registerTypeIfPresent(classLoader, typeName,
8788
MemberCategory.DECLARED_FIELDS));
8889

89-
Stream
90-
.of("reactor.core.publisher.Flux", "com.github.benmanes.caffeine.cache.SSMSA",
91-
"com.github.benmanes.caffeine.cache.PSAMS", "com.github.benmanes.caffeine.cache.SSLMSA",
92-
"com.github.benmanes.caffeine.cache.PSAMW")
93-
.forEach(typeName -> reflectionHints.registerTypeIfPresent(classLoader, typeName,
94-
MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.INVOKE_DECLARED_METHODS,
95-
MemberCategory.INTROSPECT_PUBLIC_METHODS));
90+
// @formatter:off
91+
Stream.of(
92+
"reactor.core.publisher.Flux",
93+
"java.lang.Thread",
94+
"org.apache.pulsar.reactive.shade.com.github.benmanes.caffeine.cache.BBHeader$ReadAndWriteCounterRef",
95+
"org.apache.pulsar.reactive.shade.com.github.benmanes.caffeine.cache.BBHeader$ReadCounterRef",
96+
"org.apache.pulsar.reactive.shade.com.github.benmanes.caffeine.cache.BLCHeader",
97+
"org.apache.pulsar.reactive.shade.com.github.benmanes.caffeine.cache.BLCHeader$DrainStatusRef",
98+
"org.apache.pulsar.reactive.shade.com.github.benmanes.caffeine.cache.BLCHeader$PadDrainStatus",
99+
"org.apache.pulsar.reactive.shade.com.github.benmanes.caffeine.cache.BaseMpscLinkedArrayQueueColdProducerFields",
100+
"org.apache.pulsar.reactive.shade.com.github.benmanes.caffeine.cache.BaseMpscLinkedArrayQueueConsumerFields",
101+
"org.apache.pulsar.reactive.shade.com.github.benmanes.caffeine.cache.BaseMpscLinkedArrayQueueProducerFields",
102+
"org.apache.pulsar.reactive.shade.com.github.benmanes.caffeine.cache.BoundedLocalCache",
103+
"org.apache.pulsar.reactive.shade.com.github.benmanes.caffeine.cache.CacheLoader",
104+
"org.apache.pulsar.reactive.shade.com.github.benmanes.caffeine.cache.FS",
105+
"org.apache.pulsar.reactive.shade.com.github.benmanes.caffeine.cache.FW",
106+
"org.apache.pulsar.reactive.shade.com.github.benmanes.caffeine.cache.PD",
107+
"org.apache.pulsar.reactive.shade.com.github.benmanes.caffeine.cache.PS",
108+
"org.apache.pulsar.reactive.shade.com.github.benmanes.caffeine.cache.PSA",
109+
"org.apache.pulsar.reactive.shade.com.github.benmanes.caffeine.cache.PSAMS",
110+
"org.apache.pulsar.reactive.shade.com.github.benmanes.caffeine.cache.PSAW",
111+
"org.apache.pulsar.reactive.shade.com.github.benmanes.caffeine.cache.PSAWMW",
112+
"org.apache.pulsar.reactive.shade.com.github.benmanes.caffeine.cache.PSMS",
113+
"org.apache.pulsar.reactive.shade.com.github.benmanes.caffeine.cache.PSMW",
114+
"org.apache.pulsar.reactive.shade.com.github.benmanes.caffeine.cache.PSR",
115+
"org.apache.pulsar.reactive.shade.com.github.benmanes.caffeine.cache.PSRMS",
116+
"org.apache.pulsar.reactive.shade.com.github.benmanes.caffeine.cache.PSW",
117+
"org.apache.pulsar.reactive.shade.com.github.benmanes.caffeine.cache.PSWMS",
118+
"org.apache.pulsar.reactive.shade.com.github.benmanes.caffeine.cache.PSWMW",
119+
"org.apache.pulsar.reactive.shade.com.github.benmanes.caffeine.cache.PW",
120+
"org.apache.pulsar.reactive.shade.com.github.benmanes.caffeine.cache.SI",
121+
"org.apache.pulsar.reactive.shade.com.github.benmanes.caffeine.cache.SS",
122+
"org.apache.pulsar.reactive.shade.com.github.benmanes.caffeine.cache.SSA",
123+
"org.apache.pulsar.reactive.shade.com.github.benmanes.caffeine.cache.SSAW",
124+
"org.apache.pulsar.reactive.shade.com.github.benmanes.caffeine.cache.SSL",
125+
"org.apache.pulsar.reactive.shade.com.github.benmanes.caffeine.cache.SSLAW",
126+
"org.apache.pulsar.reactive.shade.com.github.benmanes.caffeine.cache.SSLMS",
127+
"org.apache.pulsar.reactive.shade.com.github.benmanes.caffeine.cache.SSLMSA",
128+
"org.apache.pulsar.reactive.shade.com.github.benmanes.caffeine.cache.SSLMSAW",
129+
"org.apache.pulsar.reactive.shade.com.github.benmanes.caffeine.cache.SSLSW",
130+
"org.apache.pulsar.reactive.shade.com.github.benmanes.caffeine.cache.SSLW",
131+
"org.apache.pulsar.reactive.shade.com.github.benmanes.caffeine.cache.SSMS",
132+
"org.apache.pulsar.reactive.shade.com.github.benmanes.caffeine.cache.SSMSA",
133+
"org.apache.pulsar.reactive.shade.com.github.benmanes.caffeine.cache.SSMSAW",
134+
"org.apache.pulsar.reactive.shade.com.github.benmanes.caffeine.cache.SSMSR",
135+
"org.apache.pulsar.reactive.shade.com.github.benmanes.caffeine.cache.SSMSW",
136+
"org.apache.pulsar.reactive.shade.com.github.benmanes.caffeine.cache.SSMW",
137+
"org.apache.pulsar.reactive.shade.com.github.benmanes.caffeine.cache.SSSMS",
138+
"org.apache.pulsar.reactive.shade.com.github.benmanes.caffeine.cache.SSSMWW",
139+
"org.apache.pulsar.reactive.shade.com.github.benmanes.caffeine.cache.SSSW",
140+
"org.apache.pulsar.reactive.shade.com.github.benmanes.caffeine.cache.SSW",
141+
"org.apache.pulsar.reactive.shade.com.github.benmanes.caffeine.cache.StripedBuffer",
142+
"org.apache.pulsar.reactive.shade.com.github.benmanes.caffeine.cache.UnboundedLocalCache",
143+
"org.apache.pulsar.reactive.shade.com.github.benmanes.caffeine.cache.WI",
144+
"org.apache.pulsar.reactive.shade.com.github.benmanes.caffeine.cache.WS")
145+
.forEach(type -> reflectionHints.registerTypeIfPresent(classLoader, type,
146+
builder -> builder.withMembers(
147+
MemberCategory.INVOKE_DECLARED_CONSTRUCTORS,
148+
MemberCategory.INVOKE_PUBLIC_METHODS,
149+
MemberCategory.INVOKE_DECLARED_METHODS,
150+
MemberCategory.INTROSPECT_PUBLIC_METHODS,
151+
MemberCategory.DECLARED_CLASSES,
152+
MemberCategory.DECLARED_FIELDS)));
153+
reflectionHints.registerField(ReflectionUtils.findField(Thread.class, "threadLocalRandomProbe"));
154+
155+
// @formatter:on
96156

97157
// Registering JDK dynamic proxies for these interfaces. Since the Connection
98158
// interface is protected,

spring-pulsar/src/main/java/org/springframework/pulsar/aot/PulsarRuntimeHints.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -218,13 +218,17 @@ public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader)
218218
"org.apache.pulsar.shade.org.jvnet.hk2.internal.DynamicConfigurationServiceImpl",
219219
"org.apache.pulsar.shade.org.jvnet.hk2.internal.ServiceLocatorRuntimeImpl",
220220
"org.apache.pulsar.shade.org.jvnet.hk2.internal.ServiceLocatorRuntimeImpl",
221+
"org.springframework.pulsar.shade.com.github.benmanes.caffeine.cache.PSAMS",
222+
"org.springframework.pulsar.shade.com.github.benmanes.caffeine.cache.PSW",
223+
"org.springframework.pulsar.shade.com.github.benmanes.caffeine.cache.PSWMS",
224+
"org.springframework.pulsar.shade.com.github.benmanes.caffeine.cache.SSLA",
221225
"org.springframework.pulsar.shade.com.github.benmanes.caffeine.cache.SSMSA",
222-
"org.springframework.pulsar.shade.com.github.benmanes.caffeine.cache.PSAMS")
223-
.forEach(type -> reflectionHints.registerTypeIfPresent(classLoader, type,
224-
builder -> builder.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS,
225-
MemberCategory.INVOKE_PUBLIC_METHODS, MemberCategory.INVOKE_DECLARED_METHODS,
226-
MemberCategory.INTROSPECT_PUBLIC_METHODS, MemberCategory.DECLARED_CLASSES,
227-
MemberCategory.DECLARED_FIELDS)));
226+
"org.springframework.pulsar.shade.com.github.benmanes.caffeine.cache.SSLMSAW")
227+
.forEach(type -> reflectionHints.registerTypeIfPresent(classLoader, type,
228+
builder -> builder.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS,
229+
MemberCategory.INVOKE_PUBLIC_METHODS, MemberCategory.INVOKE_DECLARED_METHODS,
230+
MemberCategory.INTROSPECT_PUBLIC_METHODS, MemberCategory.DECLARED_CLASSES,
231+
MemberCategory.DECLARED_FIELDS)));
228232
// @formatter:on
229233

230234
// Registering JDK dynamic proxies for these interfaces. Since the Connection

0 commit comments

Comments
 (0)