Repository: camel Updated Branches: refs/heads/master 2e3b2bdfd -> 795145892
CAMEL-11409: Add writeTimeout configuration property and use with the WriteFuture in Mina2Helper Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/3b3cbe86 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/3b3cbe86 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/3b3cbe86 Branch: refs/heads/master Commit: 3b3cbe8681a339f367198fdd17b44296c17dc270 Parents: 2e3b2bd Author: Gijsbert van den Brink <vandenbr...@zorgdomein.nl> Authored: Wed Jun 14 11:46:35 2017 +0200 Committer: Zoran Regvart <zregv...@apache.org> Committed: Wed Jun 14 11:56:37 2017 +0200 ---------------------------------------------------------------------- .../camel/component/mina2/Mina2Configuration.java | 13 +++++++++++++ .../apache/camel/component/mina2/Mina2Consumer.java | 2 +- .../apache/camel/component/mina2/Mina2Helper.java | 10 +++++----- .../apache/camel/component/mina2/Mina2Producer.java | 4 +++- .../springboot/Mina2ComponentConfiguration.java | 15 ++++++++++++++- 5 files changed, 36 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/3b3cbe86/components/camel-mina2/src/main/java/org/apache/camel/component/mina2/Mina2Configuration.java ---------------------------------------------------------------------- diff --git a/components/camel-mina2/src/main/java/org/apache/camel/component/mina2/Mina2Configuration.java b/components/camel-mina2/src/main/java/org/apache/camel/component/mina2/Mina2Configuration.java index 2721791..e096fb9 100644 --- a/components/camel-mina2/src/main/java/org/apache/camel/component/mina2/Mina2Configuration.java +++ b/components/camel-mina2/src/main/java/org/apache/camel/component/mina2/Mina2Configuration.java @@ -51,6 +51,8 @@ public class Mina2Configuration implements Cloneable { private ProtocolCodecFactory codec; @UriParam(label = "codec") private String encoding; + @UriParam(defaultValue = "10000") + private long writeTimeout = 10000; @UriParam(defaultValue = "30000") private long timeout = 30000; @UriParam(label = "producer,advanced", defaultValue = "true") @@ -200,6 +202,17 @@ public class Mina2Configuration implements Cloneable { this.encoding = encoding; } + public long getWriteTimeout() { + return writeTimeout; + } + + /** + * Maximum amount of time it should take to send data to the MINA session. Default is 10000 milliseconds. + */ + public void setWriteTimeout(long writeTimeout) { + this.writeTimeout = writeTimeout; + } + public long getTimeout() { return timeout; } http://git-wip-us.apache.org/repos/asf/camel/blob/3b3cbe86/components/camel-mina2/src/main/java/org/apache/camel/component/mina2/Mina2Consumer.java ---------------------------------------------------------------------- diff --git a/components/camel-mina2/src/main/java/org/apache/camel/component/mina2/Mina2Consumer.java b/components/camel-mina2/src/main/java/org/apache/camel/component/mina2/Mina2Consumer.java index a916bab..7e375f0 100644 --- a/components/camel-mina2/src/main/java/org/apache/camel/component/mina2/Mina2Consumer.java +++ b/components/camel-mina2/src/main/java/org/apache/camel/component/mina2/Mina2Consumer.java @@ -436,7 +436,7 @@ public class Mina2Consumer extends DefaultConsumer { if (response != null) { LOG.debug("Writing body: {}", response); - Mina2Helper.writeBody(session, response, exchange); + Mina2Helper.writeBody(session, response, exchange, configuration.getWriteTimeout()); } else { LOG.debug("Writing no response"); disconnect = Boolean.TRUE; http://git-wip-us.apache.org/repos/asf/camel/blob/3b3cbe86/components/camel-mina2/src/main/java/org/apache/camel/component/mina2/Mina2Helper.java ---------------------------------------------------------------------- diff --git a/components/camel-mina2/src/main/java/org/apache/camel/component/mina2/Mina2Helper.java b/components/camel-mina2/src/main/java/org/apache/camel/component/mina2/Mina2Helper.java index 4e843b6..d2553d3 100644 --- a/components/camel-mina2/src/main/java/org/apache/camel/component/mina2/Mina2Helper.java +++ b/components/camel-mina2/src/main/java/org/apache/camel/component/mina2/Mina2Helper.java @@ -36,21 +36,21 @@ public final class Mina2Helper { /** * Asynchronously writes the given body to MINA session. Will wait at most for - * 10 seconds until the body has been written. + * {{ writeTimeout }} milliseconds until the body has been written. * * @param session the MINA session * @param body the body to write (send) * @param exchange the exchange + * @param writeTimeout maximum amount of time we wait for the WriteFuture to complete (in milliseconds) * @throws CamelExchangeException is thrown if the body could not be written for some reasons * (eg remote connection is closed etc.) */ - public static void writeBody(IoSession session, Object body, Exchange exchange) throws CamelExchangeException { + public static void writeBody(IoSession session, Object body, Exchange exchange, long writeTimeout) throws CamelExchangeException { // the write operation is asynchronous. Use WriteFuture to wait until the session has been written WriteFuture future = session.write(body); - // must use a timeout (we use 10s) as in some very high performance scenarios a write can cause - // thread hanging forever + // must use a timeout as in some very high performance scenarios a write can cause thread hanging forever LOG.trace("Waiting for write to complete for body: {} using session: {}", body, session); - if (!future.awaitUninterruptibly(10000L)) { + if (!future.awaitUninterruptibly(writeTimeout)) { String message = "Cannot write body: " + body.getClass().getCanonicalName() + " using session: " + session; if (future.getException() != null) { throw new CamelExchangeException(message, exchange, future.getException()); http://git-wip-us.apache.org/repos/asf/camel/blob/3b3cbe86/components/camel-mina2/src/main/java/org/apache/camel/component/mina2/Mina2Producer.java ---------------------------------------------------------------------- diff --git a/components/camel-mina2/src/main/java/org/apache/camel/component/mina2/Mina2Producer.java b/components/camel-mina2/src/main/java/org/apache/camel/component/mina2/Mina2Producer.java index 7f6cc03..4fde49b 100644 --- a/components/camel-mina2/src/main/java/org/apache/camel/component/mina2/Mina2Producer.java +++ b/components/camel-mina2/src/main/java/org/apache/camel/component/mina2/Mina2Producer.java @@ -71,6 +71,7 @@ public class Mina2Producer extends DefaultProducer implements ServicePoolAware { private CountDownLatch responseLatch; private CountDownLatch closeLatch; private boolean lazySessionCreation; + private long writeTimeout; private long timeout; private SocketAddress address; private IoConnector connector; @@ -84,6 +85,7 @@ public class Mina2Producer extends DefaultProducer implements ServicePoolAware { super(endpoint); this.configuration = endpoint.getConfiguration(); this.lazySessionCreation = configuration.isLazySessionCreation(); + this.writeTimeout = configuration.getWriteTimeout(); this.timeout = configuration.getTimeout(); this.sync = configuration.isSync(); this.noReplyLogger = new CamelLogger(LOG, configuration.getNoReplyLogLevel()); @@ -165,7 +167,7 @@ public class Mina2Producer extends DefaultProducer implements ServicePoolAware { LOG.debug("Writing body: {}", out); } // write the body - Mina2Helper.writeBody(session, body, exchange); + Mina2Helper.writeBody(session, body, exchange, writeTimeout); if (sync) { // wait for response, consider timeout http://git-wip-us.apache.org/repos/asf/camel/blob/3b3cbe86/platforms/spring-boot/components-starter/camel-mina2-starter/src/main/java/org/apache/camel/component/mina2/springboot/Mina2ComponentConfiguration.java ---------------------------------------------------------------------- diff --git a/platforms/spring-boot/components-starter/camel-mina2-starter/src/main/java/org/apache/camel/component/mina2/springboot/Mina2ComponentConfiguration.java b/platforms/spring-boot/components-starter/camel-mina2-starter/src/main/java/org/apache/camel/component/mina2/springboot/Mina2ComponentConfiguration.java index 0404030..97cc051 100644 --- a/platforms/spring-boot/components-starter/camel-mina2-starter/src/main/java/org/apache/camel/component/mina2/springboot/Mina2ComponentConfiguration.java +++ b/platforms/spring-boot/components-starter/camel-mina2-starter/src/main/java/org/apache/camel/component/mina2/springboot/Mina2ComponentConfiguration.java @@ -123,6 +123,11 @@ public class Mina2ComponentConfiguration */ private String encoding; /** + * Maximum amount of time it should take to send data to the MINA + * session. Default is 10000 milliseconds. + */ + private Long writeTimeout = 10000L; + /** * You can configure the timeout that specifies how long to wait for a * response from a remote server. The timeout unit is in milliseconds, * so 60000 is 60 seconds. @@ -279,6 +284,14 @@ public class Mina2ComponentConfiguration this.encoding = encoding; } + public Long getWriteTimeout() { + return writeTimeout; + } + + public void setWriteTimeout(Long writeTimeout) { + this.writeTimeout = writeTimeout; + } + public Long getTimeout() { return timeout; } @@ -417,4 +430,4 @@ public class Mina2ComponentConfiguration this.clientMode = clientMode; } } -} \ No newline at end of file +}