diff --git a/spring-pulsar-reactive/src/main/java/org/springframework/pulsar/reactive/core/DefaultReactivePulsarSenderFactory.java b/spring-pulsar-reactive/src/main/java/org/springframework/pulsar/reactive/core/DefaultReactivePulsarSenderFactory.java index 2e690903..4214b148 100644 --- a/spring-pulsar-reactive/src/main/java/org/springframework/pulsar/reactive/core/DefaultReactivePulsarSenderFactory.java +++ b/spring-pulsar-reactive/src/main/java/org/springframework/pulsar/reactive/core/DefaultReactivePulsarSenderFactory.java @@ -35,7 +35,6 @@ import org.springframework.pulsar.core.DefaultTopicResolver; import org.springframework.pulsar.core.TopicResolver; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; -import org.springframework.util.ReflectionUtils; /** * Default implementation of {@link ReactivePulsarSenderFactory}. @@ -173,7 +172,6 @@ public final class DefaultReactivePulsarSenderFactory @Override public void doStop() { try { - this.reflectivelyClearCache(); this.reactiveMessageSenderCache.close(); } @@ -182,68 +180,6 @@ public final class DefaultReactivePulsarSenderFactory } } - /** - * Workaround to reflectively clear the underlying producer cache. - * - * TODO: Remove once this is supported in the Reactive client. - */ - private void reflectivelyClearCache() { - if (this.reactiveMessageSenderCache == null) { - this.logger.trace(() -> "Cache is null - nothing to clear"); - return; - } - - // reactiveMessageSenderCache - // (org.apache.pulsar.reactive.client.internal.adapter.ProducerCache) - var cacheProviderField = ReflectionUtils.findField(this.reactiveMessageSenderCache.getClass(), "cacheProvider"); - if (cacheProviderField == null) { - this.logger.trace( - () -> "Could not locate 'cacheProvider' field on sender cache: " + this.reactiveMessageSenderCache); - return; - } - ReflectionUtils.makeAccessible(cacheProviderField); - // org.apache.pulsar.reactive.client.producercache.CaffeineShadedProducerCacheProvider - var cacheProvider = ReflectionUtils.getField(cacheProviderField, this.reactiveMessageSenderCache); - if (cacheProvider == null) { - this.logger.trace(() -> "Cache provider was null on sender cache: " + this.reactiveMessageSenderCache); - return; - } - - // org.apache.pulsar.reactive.shade.com.github.benmanes.caffeine.cache.BoundedLocalCache$BoundedLocalAsyncCache - var cacheField = ReflectionUtils.findField(cacheProvider.getClass(), "cache"); - if (cacheField == null) { - this.logger.trace(() -> "Could not locate 'cache' field on cache provider: " + cacheProvider); - return; - } - ReflectionUtils.makeAccessible(cacheField); - var cache = ReflectionUtils.getField(cacheField, cacheProvider); - if (cacheField == null) { - this.logger.trace(() -> "Cache impl was null on cache provider: " + cacheProvider); - return; - } - - // org.apache.pulsar.reactive.shade.com.github.benmanes.caffeine.cache.SSLMSAW - var actualCacheField = ReflectionUtils.findField(cache.getClass(), "cache"); - if (actualCacheField == null) { - this.logger.trace(() -> "Could not locate 'cache' field on cache impl: " + cache); - return; - } - ReflectionUtils.makeAccessible(actualCacheField); - var actualCache = ReflectionUtils.getField(actualCacheField, cache); - if (actualCache == null) { - this.logger.trace(() -> "Actual cache was null on cache impl: " + cache); - return; - } - - var clearMethod = ReflectionUtils.findMethod(actualCache.getClass(), "clear"); - if (clearMethod == null) { - this.logger.trace(() -> "Could not locate 'clear' method on actual cache: " + actualCache); - return; - } - ReflectionUtils.makeAccessible(clearMethod); - ReflectionUtils.invokeMethod(clearMethod, actualCache); - } - /** * Builder for {@link DefaultReactivePulsarSenderFactory}. *