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 11:55:38 UTC
[camel] branch master 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 master
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push:
new c29f083 [IRC] Add commandTimeout parameter for IRC (#2685)
c29f083 is described below
commit c29f083d86f53c18ca46c7de9f4ee99f26f4b114
Author: Andrej Vano <av...@redhat.com>
AuthorDate: Sat Dec 22 12:55:33 2018 +0100
[IRC] Add commandTimeout parameter for IRC (#2685)
---
.../org/apache/camel/component/irc/IrcComponent.java | 2 +-
.../apache/camel/component/irc/IrcConfiguration.java | 18 ++++++++++++++++--
.../org/apache/camel/component/irc/IrcConsumer.java | 15 +++++++--------
.../org/apache/camel/component/irc/IrcEndpoint.java | 2 +-
.../org/apache/camel/component/irc/IrcProducer.java | 9 +++++++++
5 files changed, 34 insertions(+), 12 deletions(-)
diff --git a/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcComponent.java b/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcComponent.java
index fe96ec3..c78cc27 100644
--- a/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcComponent.java
+++ b/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcComponent.java
@@ -21,8 +21,8 @@ import java.util.Map;
import org.apache.camel.RuntimeCamelException;
import org.apache.camel.SSLContextParametersAware;
-import org.apache.camel.support.DefaultComponent;
import org.apache.camel.spi.Metadata;
+import org.apache.camel.support.DefaultComponent;
import org.apache.camel.support.jsse.SSLContextParameters;
import org.schwering.irc.lib.IRCConnection;
import org.schwering.irc.lib.IRCEventListener;
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 d99b37f..72e0dd1 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
@@ -30,10 +30,10 @@ import org.apache.camel.spi.Metadata;
import org.apache.camel.spi.UriParam;
import org.apache.camel.spi.UriParams;
import org.apache.camel.spi.UriPath;
+import org.apache.camel.support.jsse.SSLContextParameters;
import org.apache.camel.util.StringHelper;
import org.apache.camel.util.URISupport;
import org.apache.camel.util.UnsafeUriCharactersEncoder;
-import org.apache.camel.support.jsse.SSLContextParameters;
import org.schwering.irc.lib.ssl.SSLDefaultTrustManager;
import org.schwering.irc.lib.ssl.SSLTrustManager;
import org.slf4j.Logger;
@@ -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 08d1d72..246ccf9 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
@@ -57,15 +57,14 @@ 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.");
// 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());
diff --git a/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcEndpoint.java b/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcEndpoint.java
index b80b561..b9a6bfa 100644
--- a/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcEndpoint.java
+++ b/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcEndpoint.java
@@ -19,9 +19,9 @@ package org.apache.camel.component.irc;
import org.apache.camel.Exchange;
import org.apache.camel.ExchangePattern;
import org.apache.camel.Processor;
-import org.apache.camel.support.DefaultEndpoint;
import org.apache.camel.spi.UriEndpoint;
import org.apache.camel.spi.UriParam;
+import org.apache.camel.support.DefaultEndpoint;
import org.apache.camel.util.ObjectHelper;
import org.apache.camel.util.UnsafeUriCharactersEncoder;
import org.schwering.irc.lib.IRCConnection;
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 e68561c..8da01ab 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
@@ -28,6 +28,7 @@ public class IrcProducer extends DefaultProducer {
public static final String[] COMMANDS = new String[] {"AWAY", "INVITE", "ISON", "JOIN", "KICK", "LIST", "NAMES",
"PRIVMSG", "MODE", "NICK", "NOTICE", "PART", "PONG", "QUIT", "TOPIC", "WHO", "WHOIS", "WHOWAS", "USERHOST"};
+ private final IrcConfiguration configuration;
private IRCConnection connection;
private IrcEndpoint endpoint;
private IRCEventAdapter listener;
@@ -36,6 +37,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 {
@@ -67,6 +69,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();
}