You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2019/12/04 11:49:29 UTC

[camel] branch camel-3.0.x updated: CAMEL-14224: Fix camel-websocket sendToAll to be faster. Thanks to Michael Elbaz for reporting.

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch camel-3.0.x
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/camel-3.0.x by this push:
     new ef46ae3  CAMEL-14224: Fix camel-websocket sendToAll to be faster. Thanks to Michael Elbaz for reporting.
ef46ae3 is described below

commit ef46ae3d363c54cbf5a67e64958a3b71408aa299
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Wed Dec 4 12:47:51 2019 +0100

    CAMEL-14224: Fix camel-websocket sendToAll to be faster. Thanks to Michael Elbaz for reporting.
---
 .../component/websocket/WebsocketProducer.java     | 23 +++++++++-------------
 1 file changed, 9 insertions(+), 14 deletions(-)

diff --git a/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/WebsocketProducer.java b/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/WebsocketProducer.java
index 895a0db..8b47d16 100644
--- a/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/WebsocketProducer.java
+++ b/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/WebsocketProducer.java
@@ -129,22 +129,17 @@ public class WebsocketProducer extends DefaultProducer implements WebsocketProdu
         int timeout = endpoint.getSendTimeout();
         while (!futures.isEmpty() && watch.taken() < timeout) {
             // remove all that are done/cancelled
-            for (Future future : futures) {
-                if (future.isDone() || future.isCancelled()) {
-                    futures.remove(future);
-                }
-                // if there are still more then we need to wait a little bit before checking again, to avoid burning cpu cycles in the while loop
-                if (!futures.isEmpty()) {
-                    long interval = Math.min(1000, timeout);
-                    log.debug("Sleeping {} millis waiting for sendToAll to complete sending with timeout {} millis", interval, timeout);
-                    try {
-                        Thread.sleep(interval);
-                    } catch (InterruptedException e) {
-                        handleSleepInterruptedException(e, exchange);
-                    }
+            futures.removeIf(future -> future.isDone() || future.isCancelled());
+            // if there are still more then we need to wait a little bit before checking again, to avoid burning cpu cycles in the while loop
+            if (!futures.isEmpty()) {
+                long interval = Math.min(1000, timeout);
+                log.debug("Sleeping {} millis waiting for sendToAll to complete sending with timeout {} millis", interval, timeout);
+                try {
+                    Thread.sleep(interval);
+                } catch (InterruptedException e) {
+                    handleSleepInterruptedException(e, exchange);
                 }
             }
-
         }
         if (!futures.isEmpty()) {
             exception = new WebsocketSendException("Failed to deliver message within " + endpoint.getSendTimeout() + " millis to one or more recipients.", exchange);