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 2018/12/22 13:47:18 UTC

[camel] branch camel-2.22.x updated: [IRC] Add commandTimeout parameter for IRC (#2685)

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

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


The following commit(s) were added to refs/heads/camel-2.22.x by this push:
     new 0a5b82c  [IRC] Add commandTimeout parameter for IRC (#2685)
0a5b82c is described below

commit 0a5b82ca198ad26db8e3fce770e007c862665174
Author: Andrej Vano <av...@redhat.com>
AuthorDate: Sat Dec 22 12:55:33 2018 +0100

    [IRC] Add commandTimeout parameter for IRC (#2685)
---
 components/camel-irc/src/main/docs/irc-component.adoc   |  3 ++-
 .../apache/camel/component/irc/IrcConfiguration.java    | 16 +++++++++++++++-
 .../org/apache/camel/component/irc/IrcConsumer.java     | 17 ++++++++---------
 .../org/apache/camel/component/irc/IrcProducer.java     |  9 +++++++++
 4 files changed, 34 insertions(+), 11 deletions(-)

diff --git a/components/camel-irc/src/main/docs/irc-component.adoc b/components/camel-irc/src/main/docs/irc-component.adoc
index 9a9070b..6e7ac4f 100644
--- a/components/camel-irc/src/main/docs/irc-component.adoc
+++ b/components/camel-irc/src/main/docs/irc-component.adoc
@@ -73,13 +73,14 @@ with the following path and query parameters:
 |===
 
 
-==== Query Parameters (24 parameters):
+==== Query Parameters (25 parameters):
 
 
 [width="100%",cols="2,5,^1,2",options="header"]
 |===
 | Name | Description | Default | Type
 | *autoRejoin* (common) | Whether to auto re-join when being kicked | true | boolean
+| *commandTimeout* (common) | Delay in milliseconds before sending commands after the connection is established. | 5000 | long
 | *namesOnJoin* (common) | Sends NAMES command to channel after joining it. link onReply has to be true in order to process the result which will have the header value irc.num = '353'. | false | boolean
 | *nickname* (common) | The nickname used in chat. |  | String
 | *persistent* (common) | *Deprecated* Use persistent messages. | true | boolean
diff --git a/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcConfiguration.java b/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcConfiguration.java
index 6b913b4..8ec9cb6 100644
--- a/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcConfiguration.java
+++ b/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcConfiguration.java
@@ -92,6 +92,8 @@ public class IrcConfiguration implements Cloneable {
     private SSLContextParameters sslContextParameters;
     @UriParam(label = "security", secret = true)
     private String nickPassword;
+    @UriParam(defaultValue = "5000")
+    private long commandTimeout = 5000L;
 
     public IrcConfiguration() {
     }
@@ -459,7 +461,19 @@ public class IrcConfiguration implements Cloneable {
     public void setNickPassword(String nickPassword) {
         this.nickPassword = nickPassword;
     }
-    
+
+    /**
+     * Delay in milliseconds before sending commands after the connection is established.
+     * @param timeout timeout value in milliseconds
+     */
+    public void setCommandTimeout(long timeout) {
+        this.commandTimeout = timeout;
+    }
+
+    public long getCommandTimeout() {
+        return commandTimeout;
+    }
+
     public boolean isNamesOnJoin() {
         return namesOnJoin;
     }
diff --git a/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcConsumer.java b/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcConsumer.java
index e132f1a..506a24d 100644
--- a/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcConsumer.java
+++ b/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcConsumer.java
@@ -60,16 +60,15 @@ public class IrcConsumer extends DefaultConsumer {
         listener = getListener();
         connection.addIRCEventListener(listener);
 
+        log.debug("Sleeping for {} seconds before sending commands.", configuration.getCommandTimeout() / 1000);
+        // sleep for a few seconds as the server sometimes takes a moment to fully connect, print banners, etc after connection established
+        try {
+            Thread.sleep(configuration.getCommandTimeout());
+        } catch (InterruptedException ex) {
+            // ignore
+        }
         if (ObjectHelper.isNotEmpty(configuration.getNickPassword())) {
-            try {
-                // TODO : sleep before joinChannels() may be another useful config param (even when not identifying)
-                // sleep for a few seconds as the server sometimes takes a moment to fully connect, print banners, etc after connection established
-                LOG.debug("Sleeping for 5 seconds before identifying to NickServ.");
-                Thread.sleep(5000);
-            } catch (InterruptedException ex) {
-                // ignore
-            }
-            LOG.debug("Identifying and enforcing nick with NickServ.");
+            log.debug("Identifying and enforcing nick with NickServ.");
             // Identify nick and enforce, https://meta.wikimedia.org/wiki/IRC/Instructions#Register_your_nickname.2C_identify.2C_and_enforce
             connection.doPrivmsg("nickserv", "identify " + configuration.getNickPassword());
             connection.doPrivmsg("nickserv", "set enforce on");
diff --git a/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcProducer.java b/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcProducer.java
index a129be9..9d7541c 100644
--- a/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcProducer.java
+++ b/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcProducer.java
@@ -32,6 +32,7 @@ public class IrcProducer extends DefaultProducer {
 
     private static final Logger LOG = LoggerFactory.getLogger(IrcProducer.class);
 
+    private final IrcConfiguration configuration;
     private IRCConnection connection;
     private IrcEndpoint endpoint;
     private IRCEventAdapter listener;
@@ -40,6 +41,7 @@ public class IrcProducer extends DefaultProducer {
         super(endpoint);
         this.endpoint = endpoint;
         this.connection = connection;
+        this.configuration = endpoint.getConfiguration();
     }
 
     public void process(Exchange exchange) throws Exception {
@@ -71,6 +73,13 @@ public class IrcProducer extends DefaultProducer {
         super.doStart();
         listener = getListener();
         connection.addIRCEventListener(listener);
+        log.debug("Sleeping for {} seconds before sending commands.", configuration.getCommandTimeout() / 1000);
+        // sleep for a few seconds as the server sometimes takes a moment to fully connect, print banners, etc after connection established
+        try {
+            Thread.sleep(configuration.getCommandTimeout());
+        } catch (InterruptedException ex) {
+            // ignore
+        }
         endpoint.joinChannels();
     }