ClassUtils clean & deprecation in JmsOutGateway
* Remove previously deprecated methods with typos from the `ClassUtils` * Optimize `ClassUtils` logic via `KotlinDetector.isKotlinPresent()` condition * Resolve deprecation warnings in the `JmsOutboundGateway` around `TaskScheduler`
This commit is contained in:
@@ -23,6 +23,7 @@ import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import org.springframework.core.KotlinDetector;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
@@ -98,12 +99,13 @@ public abstract class ClassUtils {
|
||||
PRIMITIVE_WRAPPER_TYPE_MAP.put(Long.class, long.class);
|
||||
PRIMITIVE_WRAPPER_TYPE_MAP.put(Short.class, short.class);
|
||||
|
||||
ClassLoader defaultClassLoader = org.springframework.util.ClassUtils.getDefaultClassLoader();
|
||||
|
||||
Class<?> genericSelectorClass = null;
|
||||
try {
|
||||
genericSelectorClass =
|
||||
org.springframework.util.ClassUtils.forName(
|
||||
"org.springframework.integration.core.GenericSelector",
|
||||
org.springframework.util.ClassUtils.getDefaultClassLoader());
|
||||
"org.springframework.integration.core.GenericSelector", defaultClassLoader);
|
||||
}
|
||||
catch (ClassNotFoundException e) {
|
||||
ReflectionUtils.rethrowRuntimeException(e);
|
||||
@@ -115,8 +117,7 @@ public abstract class ClassUtils {
|
||||
try {
|
||||
genericTransformerClass =
|
||||
org.springframework.util.ClassUtils.forName(
|
||||
"org.springframework.integration.transformer.GenericTransformer",
|
||||
org.springframework.util.ClassUtils.getDefaultClassLoader());
|
||||
"org.springframework.integration.transformer.GenericTransformer", defaultClassLoader);
|
||||
}
|
||||
catch (ClassNotFoundException e) {
|
||||
ReflectionUtils.rethrowRuntimeException(e);
|
||||
@@ -129,8 +130,7 @@ public abstract class ClassUtils {
|
||||
try {
|
||||
genericHandlerClass =
|
||||
org.springframework.util.ClassUtils.forName(
|
||||
"org.springframework.integration.handler.GenericHandler",
|
||||
org.springframework.util.ClassUtils.getDefaultClassLoader());
|
||||
"org.springframework.integration.handler.GenericHandler", defaultClassLoader);
|
||||
}
|
||||
catch (ClassNotFoundException e) {
|
||||
ReflectionUtils.rethrowRuntimeException(e);
|
||||
@@ -138,45 +138,51 @@ public abstract class ClassUtils {
|
||||
|
||||
HANDLER_HANDLE_METHOD = ReflectionUtils.findMethod(genericHandlerClass, "handle", (Class<?>[]) null);
|
||||
|
||||
Class<?> kotlinClass = null;
|
||||
Method kotlinMethod = null;
|
||||
try {
|
||||
kotlinClass = org.springframework.util.ClassUtils.forName("kotlin.jvm.functions.Function0",
|
||||
org.springframework.util.ClassUtils.getDefaultClassLoader());
|
||||
if (KotlinDetector.isKotlinPresent()) {
|
||||
Class<?> kotlinClass = null;
|
||||
Method kotlinMethod = null;
|
||||
try {
|
||||
kotlinClass = org.springframework.util.ClassUtils.forName("kotlin.jvm.functions.Function0",
|
||||
defaultClassLoader);
|
||||
|
||||
kotlinMethod = ReflectionUtils.findMethod(kotlinClass, "invoke", (Class<?>[]) null);
|
||||
}
|
||||
catch (ClassNotFoundException e) {
|
||||
//Ignore: assume no Kotlin in classpath
|
||||
}
|
||||
finally {
|
||||
KOTLIN_FUNCTION_0_CLASS = kotlinClass;
|
||||
KOTLIN_FUNCTION_0_INVOKE_METHOD = kotlinMethod;
|
||||
}
|
||||
kotlinMethod = ReflectionUtils.findMethod(kotlinClass, "invoke", (Class<?>[]) null);
|
||||
}
|
||||
catch (ClassNotFoundException e) {
|
||||
//Ignore: assume no Kotlin in classpath
|
||||
}
|
||||
finally {
|
||||
KOTLIN_FUNCTION_0_CLASS = kotlinClass;
|
||||
KOTLIN_FUNCTION_0_INVOKE_METHOD = kotlinMethod;
|
||||
}
|
||||
|
||||
kotlinClass = null;
|
||||
kotlinMethod = null;
|
||||
try {
|
||||
kotlinClass = org.springframework.util.ClassUtils.forName("kotlin.jvm.functions.Function1",
|
||||
org.springframework.util.ClassUtils.getDefaultClassLoader());
|
||||
}
|
||||
catch (ClassNotFoundException e) {
|
||||
//Ignore: assume no Kotlin in classpath
|
||||
}
|
||||
finally {
|
||||
KOTLIN_FUNCTION_1_CLASS = kotlinClass;
|
||||
}
|
||||
kotlinClass = null;
|
||||
try {
|
||||
kotlinClass = org.springframework.util.ClassUtils.forName("kotlin.jvm.functions.Function1",
|
||||
defaultClassLoader);
|
||||
}
|
||||
catch (ClassNotFoundException e) {
|
||||
//Ignore: assume no Kotlin in classpath
|
||||
}
|
||||
finally {
|
||||
KOTLIN_FUNCTION_1_CLASS = kotlinClass;
|
||||
}
|
||||
|
||||
kotlinClass = null;
|
||||
try {
|
||||
kotlinClass = org.springframework.util.ClassUtils.forName("kotlin.Unit",
|
||||
org.springframework.util.ClassUtils.getDefaultClassLoader());
|
||||
kotlinClass = null;
|
||||
try {
|
||||
kotlinClass = org.springframework.util.ClassUtils.forName("kotlin.Unit", defaultClassLoader);
|
||||
}
|
||||
catch (ClassNotFoundException e) {
|
||||
//Ignore: assume no Kotlin in classpath
|
||||
}
|
||||
finally {
|
||||
KOTLIN_UNIT_CLASS = kotlinClass;
|
||||
}
|
||||
}
|
||||
catch (ClassNotFoundException e) {
|
||||
//Ignore: assume no Kotlin in classpath
|
||||
}
|
||||
finally {
|
||||
KOTLIN_UNIT_CLASS = kotlinClass;
|
||||
else {
|
||||
KOTLIN_FUNCTION_0_CLASS = null;
|
||||
KOTLIN_FUNCTION_0_INVOKE_METHOD = null;
|
||||
KOTLIN_FUNCTION_1_CLASS = null;
|
||||
KOTLIN_UNIT_CLASS = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -245,18 +251,6 @@ public abstract class ClassUtils {
|
||||
|| aClass.getName().contains("$inlined$"); // for Kotlin lambdas
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if class is {@code kotlin.jvm.functions.Function0}.
|
||||
* @param aClass the {@link Class} to check.
|
||||
* @return true if class is a {@code kotlin.jvm.functions.Function0} implementation.
|
||||
* @since 5.2
|
||||
* @deprecated since 5.5.14 in favor of {@link #isKotlinFunction0(Class)}
|
||||
*/
|
||||
@Deprecated
|
||||
public static boolean isKotlinFaction0(Class<?> aClass) {
|
||||
return KOTLIN_FUNCTION_0_CLASS != null && KOTLIN_FUNCTION_0_CLASS.isAssignableFrom(aClass);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if class is {@code kotlin.jvm.functions.Function0}.
|
||||
* @param aClass the {@link Class} to check.
|
||||
@@ -267,18 +261,6 @@ public abstract class ClassUtils {
|
||||
return KOTLIN_FUNCTION_0_CLASS != null && KOTLIN_FUNCTION_0_CLASS.isAssignableFrom(aClass);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if class is {@code kotlin.jvm.functions.Function1}.
|
||||
* @param aClass the {@link Class} to check.
|
||||
* @return true if class is a {@code kotlin.jvm.functions.Function1} implementation.
|
||||
* @since 5.2
|
||||
* @deprecated since 5.5.14 in favor of {@link #isKotlinFunction1(Class)}
|
||||
*/
|
||||
@Deprecated
|
||||
public static boolean isKotlinFaction1(Class<?> aClass) {
|
||||
return KOTLIN_FUNCTION_1_CLASS != null && KOTLIN_FUNCTION_1_CLASS.isAssignableFrom(aClass);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if class is {@code kotlin.jvm.functions.Function1}.
|
||||
* @param aClass the {@link Class} to check.
|
||||
@@ -289,7 +271,6 @@ public abstract class ClassUtils {
|
||||
return KOTLIN_FUNCTION_1_CLASS != null && KOTLIN_FUNCTION_1_CLASS.isAssignableFrom(aClass);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if class is {@code kotlin.Unit}.
|
||||
* @param aClass the {@link Class} to check.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,7 +16,8 @@
|
||||
|
||||
package org.springframework.integration.jms;
|
||||
|
||||
import java.util.Date;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
@@ -683,7 +684,7 @@ public class JmsOutboundGateway extends AbstractReplyProducingMessageHandler
|
||||
}
|
||||
if (!isAsync() && this.receiveTimeout >= 0) {
|
||||
Assert.state(taskScheduler != null, "'taskScheduler' is required.");
|
||||
this.reaper = taskScheduler.schedule(new LateReplyReaper(), new Date());
|
||||
this.reaper = taskScheduler.schedule(new LateReplyReaper(), Instant.now());
|
||||
}
|
||||
}
|
||||
this.active = true;
|
||||
@@ -732,8 +733,10 @@ public class JmsOutboundGateway extends AbstractReplyProducingMessageHandler
|
||||
if (!this.replyContainer.isRunning()) {
|
||||
logger.debug(() -> getComponentName() + ": Starting reply container.");
|
||||
this.replyContainer.start();
|
||||
this.idleTask = getTaskScheduler().scheduleAtFixedRate(new IdleContainerStopper(),
|
||||
this.idleReplyContainerTimeout / 2);
|
||||
this.idleTask =
|
||||
getTaskScheduler()
|
||||
.scheduleAtFixedRate(new IdleContainerStopper(),
|
||||
Duration.ofMillis(this.idleReplyContainerTimeout / 2));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1170,8 +1173,7 @@ public class JmsOutboundGateway extends AbstractReplyProducingMessageHandler
|
||||
SettableListenableFuture<AbstractIntegrationMessageBuilder<?>> future = new SettableListenableFuture<>();
|
||||
this.futures.put(correlationId, future);
|
||||
if (this.receiveTimeout > 0) {
|
||||
getTaskScheduler().schedule(() -> expire(correlationId),
|
||||
new Date(System.currentTimeMillis() + this.receiveTimeout));
|
||||
getTaskScheduler().schedule(() -> expire(correlationId), Instant.now().plusMillis(this.receiveTimeout));
|
||||
}
|
||||
return future;
|
||||
}
|
||||
@@ -1448,8 +1450,10 @@ public class JmsOutboundGateway extends AbstractReplyProducingMessageHandler
|
||||
}
|
||||
// reschedule myself
|
||||
if (JmsOutboundGateway.this.receiveTimeout >= 0) {
|
||||
JmsOutboundGateway.this.reaper = getTaskScheduler().schedule(this,
|
||||
new Date(now + JmsOutboundGateway.this.receiveTimeout));
|
||||
JmsOutboundGateway.this.reaper =
|
||||
getTaskScheduler()
|
||||
.schedule(this,
|
||||
Instant.ofEpochMilli(now).plusMillis(JmsOutboundGateway.this.receiveTimeout));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user