davsclaus commented on code in PR #26476:
URL: https://github.com/apache/camel/pull/26476#discussion_r4020096868
##########
components/camel-paho/src/main/java/org/apache/camel/component/paho/PahoConsumer.java:
##########
@@ -74,15 +78,26 @@ protected void doStart() throws Exception {
client.connect(connectOptions);
}
- client.setCallback(new MqttCallbackExtended() {
+ MqttClient callbackClient = client;
+ boolean isOwnedClient = stopClient;
+ callbackClient.setCallback(new MqttCallbackExtended() {
@Override
public void connectComplete(boolean reconnect, String
serverURI) {
- if (reconnect) {
+ if (reconnect && isRunAllowed() && callbackClient ==
client) {
Review Comment:
Nice — the `isRunAllowed()` and `callbackClient == client` guards (plus the
`isOwnedClient` snapshot, which avoids racing `doStop()`'s `stopClient = false`
reset) go beyond what `PahoMqtt5Consumer.connectComplete` does today. Not
something to change here, but a follow-up to port these guards to the MQTT5
consumer would be welcome so both consumers stay in sync.
##########
components/camel-paho/src/main/java/org/apache/camel/component/paho/PahoConsumer.java:
##########
@@ -128,6 +143,50 @@ public void deliveryComplete(IMqttDeliveryToken token) {
}
}
+ private void restartRouteAsync() {
+ if (!restarting.compareAndSet(false, true)) {
+ LOG.debug("Route restart already in progress, skipping duplicate
restart");
+ return;
+ }
+ String threadName = "Paho-RestartRoute-" + getRouteId();
+ ExecutorService executor = null;
+ try {
+ executor
+ =
getEndpoint().getCamelContext().getExecutorServiceManager().newSingleThreadExecutor(this,
threadName);
+ ExecutorService restartExecutor = executor;
Review Comment:
Nit (optional): the `executor = null` / `restartExecutor` alias only exists
so the lambda can capture an effectively-final reference. Creating the executor
before the `try` and guarding just the `submit()` call would drop the
null-check in the catch block and the alias. Fine to leave as-is if you prefer
to keep the defensive shape.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]