-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GH-9112: Workaround for Paho
stopReconnectCycle
Fixes: #9112 `Mqttv5ClientManager` hangs in `stop()` if never was connected. The scheduled reconnect timer in the client is never cancelled. * Call `stopReconnectCycle()` on the client via reflection when we disconnect from the client in Spring Integration MQTT components **Auto-cherry-pick to `6.2.x` & `6.1.x`**
- Loading branch information
1 parent
da29e2d
commit 937da13
Showing
11 changed files
with
151 additions
and
7 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
...gration-mqtt/src/main/java/org/springframework/integration/mqtt/aot/MqttRuntimeHints.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright 2024 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. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.integration.mqtt.aot; | ||
|
||
import java.util.stream.Stream; | ||
|
||
import org.springframework.aot.hint.ExecutableMode; | ||
import org.springframework.aot.hint.ReflectionHints; | ||
import org.springframework.aot.hint.RuntimeHints; | ||
import org.springframework.aot.hint.RuntimeHintsRegistrar; | ||
import org.springframework.util.ClassUtils; | ||
import org.springframework.util.ReflectionUtils; | ||
|
||
/** | ||
* {@link RuntimeHintsRegistrar} for Spring Integration MQTT module. | ||
* | ||
* @author Artem Bilan | ||
* | ||
* @since 6.1.9 | ||
*/ | ||
class MqttRuntimeHints implements RuntimeHintsRegistrar { | ||
|
||
@Override | ||
public void registerHints(RuntimeHints hints, ClassLoader classLoader) { | ||
ReflectionHints reflectionHints = hints.reflection(); | ||
// TODO until the real fix in Paho library. | ||
Stream.of("org.eclipse.paho.client.mqttv3.MqttAsyncClient", "org.eclipse.paho.mqttv5.client.MqttAsyncClient") | ||
.filter((typeName) -> ClassUtils.isPresent(typeName, classLoader)) | ||
.map((typeName) -> loadClassByName(typeName, classLoader)) | ||
.flatMap((type) -> Stream.ofNullable(ReflectionUtils.findMethod(type, "stopReconnectCycle"))) | ||
.forEach(method -> reflectionHints.registerMethod(method, ExecutableMode.INVOKE)); | ||
} | ||
|
||
private static Class<?> loadClassByName(String typeName, ClassLoader classLoader) { | ||
try { | ||
return ClassUtils.forName(typeName, classLoader); | ||
} | ||
catch (ClassNotFoundException ex) { | ||
throw new IllegalArgumentException(ex); | ||
} | ||
} | ||
|
||
} |
6 changes: 6 additions & 0 deletions
6
...integration-mqtt/src/main/java/org/springframework/integration/mqtt/aot/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/** | ||
* Provides classes to support Spring AOT. | ||
*/ | ||
@org.springframework.lang.NonNullApi | ||
@org.springframework.lang.NonNullFields | ||
package org.springframework.integration.mqtt.aot; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
spring-integration-mqtt/src/main/resources/META-INF/spring/aot.factories
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
org.springframework.aot.hint.RuntimeHintsRegistrar=org.springframework.integration.mqtt.aot.MqttRuntimeHints |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters