activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject [1/4] activemq-cpp git commit: https://issues.apache.org/jira/browse/AMQCPP-580
Date Tue, 28 Jul 2015 20:56:17 GMT
Repository: activemq-cpp
Updated Branches:
  refs/heads/master a43b8e9fd -> b7e418ebe


https://issues.apache.org/jira/browse/AMQCPP-580

Add maximum redelivery delay to policy.

Project: http://git-wip-us.apache.org/repos/asf/activemq-cpp/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-cpp/commit/6b190a98
Tree: http://git-wip-us.apache.org/repos/asf/activemq-cpp/tree/6b190a98
Diff: http://git-wip-us.apache.org/repos/asf/activemq-cpp/diff/6b190a98

Branch: refs/heads/master
Commit: 6b190a9821c1d9cda175603f1b1e82a7025a9c80
Parents: a43b8e9
Author: Timothy Bish <tabish121@gmail.com>
Authored: Tue Jul 28 16:08:32 2015 -0400
Committer: Timothy Bish <tabish121@gmail.com>
Committed: Tue Jul 28 16:08:32 2015 -0400

----------------------------------------------------------------------
 .../src/main/activemq/core/RedeliveryPolicy.cpp |  4 +++
 .../src/main/activemq/core/RedeliveryPolicy.h   | 28 ++++++++++++++++----
 .../core/policies/DefaultRedeliveryPolicy.cpp   | 11 ++++++--
 .../core/policies/DefaultRedeliveryPolicy.h     |  9 +++++++
 4 files changed, 45 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-cpp/blob/6b190a98/activemq-cpp/src/main/activemq/core/RedeliveryPolicy.cpp
----------------------------------------------------------------------
diff --git a/activemq-cpp/src/main/activemq/core/RedeliveryPolicy.cpp b/activemq-cpp/src/main/activemq/core/RedeliveryPolicy.cpp
index 92f6b01..91975ac 100644
--- a/activemq-cpp/src/main/activemq/core/RedeliveryPolicy.cpp
+++ b/activemq-cpp/src/main/activemq/core/RedeliveryPolicy.cpp
@@ -72,6 +72,10 @@ void RedeliveryPolicy::configure(const decaf::util::Properties& properties)
{
             this->setUseExponentialBackOff(Boolean::parseBoolean(
                 properties.getProperty("cms.redeliveryPolicy.useExponentialBackOff")));
         }
+        if (properties.hasProperty("cms.redeliveryPolicy.maxRedeliveryDelay")) {
+            this->setMaximumRedeliveryDelay(Long::parseLong(
+                properties.getProperty("cms.redeliveryPolicy.maxRedeliveryDelay")));
+        }
     }
     DECAF_CATCH_RETHROW(Exception)
     DECAF_CATCHALL_THROW(Exception)

http://git-wip-us.apache.org/repos/asf/activemq-cpp/blob/6b190a98/activemq-cpp/src/main/activemq/core/RedeliveryPolicy.h
----------------------------------------------------------------------
diff --git a/activemq-cpp/src/main/activemq/core/RedeliveryPolicy.h b/activemq-cpp/src/main/activemq/core/RedeliveryPolicy.h
index 3c68493..0e52d51 100644
--- a/activemq-cpp/src/main/activemq/core/RedeliveryPolicy.h
+++ b/activemq-cpp/src/main/activemq/core/RedeliveryPolicy.h
@@ -50,7 +50,7 @@ namespace core {
         virtual ~RedeliveryPolicy();
 
         /**
-         * @returns The value of the Back-Off Multiplier for Message Redelivery.
+         * @return The value of the Back-Off Multiplier for Message Redelivery.
          */
         virtual double getBackOffMultiplier() const = 0;
 
@@ -63,7 +63,7 @@ namespace core {
         virtual void setBackOffMultiplier(double value) = 0;
 
         /**
-         * @returns the currently set Collision Avoidance percentage.
+         * @return the currently set Collision Avoidance percentage.
          */
         virtual short getCollisionAvoidancePercent() const = 0;
 
@@ -76,7 +76,7 @@ namespace core {
         /**
          * Gets the initial time that redelivery of messages is delayed.
          *
-         * @returns the time in milliseconds that redelivery is delayed initially.
+         * @return the time in milliseconds that redelivery is delayed initially.
          */
         virtual long long getInitialRedeliveryDelay() const = 0;
 
@@ -91,7 +91,7 @@ namespace core {
         /**
          * Gets the time that redelivery of messages is delayed.
          *
-         * @returns the time in milliseconds that redelivery is delayed.
+         * @return the time in milliseconds that redelivery is delayed.
          */
         virtual long long getRedeliveryDelay() const = 0;
 
@@ -107,7 +107,7 @@ namespace core {
          * Gets the Maximum number of allowed redeliveries for a message before it will
          * be discarded by the consumer.
          *
-         * @returns maximum allowed redeliveries for a message.
+         * @return maximum allowed redeliveries for a message.
          */
         virtual int getMaximumRedeliveries() const = 0;
 
@@ -153,6 +153,24 @@ namespace core {
         virtual void setUseExponentialBackOff(bool value) = 0;
 
         /**
+         * Returns the maximum amount of time that the redelivery delay is allowed
+         * to increase to before it is capped.
+         *
+         * @return the maximum redelivery delay value.
+         */
+        virtual long long getMaximumRedeliveryDelay() const = 0;
+
+        /**
+         * Sets the maximum amount of time that the redelivery delay is allowed
+         * to increase to before it is capped.  By default this value is set to
+         * -1 which disables any maximum delay.
+         *
+         * @param value
+         *      The maximum redelivery delay value in milliseconds.
+         */
+        virtual void setMaximumRedeliveryDelay(long long value) = 0;
+
+        /**
          * Create a copy of this Policy and return it.
          *
          * @return pointer to a new RedeliveryPolicy that is a copy of this one.

http://git-wip-us.apache.org/repos/asf/activemq-cpp/blob/6b190a98/activemq-cpp/src/main/activemq/core/policies/DefaultRedeliveryPolicy.cpp
----------------------------------------------------------------------
diff --git a/activemq-cpp/src/main/activemq/core/policies/DefaultRedeliveryPolicy.cpp b/activemq-cpp/src/main/activemq/core/policies/DefaultRedeliveryPolicy.cpp
index a1ef686..d6d3f4b 100644
--- a/activemq-cpp/src/main/activemq/core/policies/DefaultRedeliveryPolicy.cpp
+++ b/activemq-cpp/src/main/activemq/core/policies/DefaultRedeliveryPolicy.cpp
@@ -34,7 +34,8 @@ DefaultRedeliveryPolicy::DefaultRedeliveryPolicy() : backOffMultiplier(5.0),
                                                      maximumRedeliveries(6),
                                                      useCollisionAvoidance(false),
                                                      useExponentialBackOff(false),
-                                                     redeliveryDelay(initialRedeliveryDelay)
{
+                                                     redeliveryDelay(initialRedeliveryDelay),
+                                                     maximumRedeliveryDelay(-1) {
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -60,6 +61,10 @@ long long DefaultRedeliveryPolicy::getNextRedeliveryDelay(long long previousDela
 
     if (previousDelay > 0 && useExponentialBackOff && (int) backOffMultiplier
> 1) {
         nextDelay = (long long) ((double) previousDelay * backOffMultiplier);
+        if (maximumRedeliveryDelay != -1 && nextDelay > maximumRedeliveryDelay)
{
+            // in case the user made max redelivery delay less than redelivery delay for
some reason.
+            nextDelay = Math::max(maximumRedeliveryDelay, redeliveryDelay);
+        }
     }
 
     if (useCollisionAvoidance) {
@@ -67,7 +72,8 @@ long long DefaultRedeliveryPolicy::getNextRedeliveryDelay(long long previousDela
          * First random determines +/-, second random determines how far to
          * go in that direction. -cgs
          */
-        double variance = (randomNumberGenerator.nextBoolean() ? collisionAvoidanceFactor
: -collisionAvoidanceFactor) * randomNumberGenerator.nextDouble();
+        double variance = (randomNumberGenerator.nextBoolean() ?
+                collisionAvoidanceFactor : -collisionAvoidanceFactor) * randomNumberGenerator.nextDouble();
         nextDelay += (long long) ((double) nextDelay * variance);
     }
 
@@ -86,6 +92,7 @@ RedeliveryPolicy* DefaultRedeliveryPolicy::clone() const {
     copy->useExponentialBackOff = this->useExponentialBackOff;
     copy->backOffMultiplier = this->backOffMultiplier;
     copy->redeliveryDelay = this->redeliveryDelay;
+    copy->maximumRedeliveryDelay = this->maximumRedeliveryDelay;
 
     return copy;
 }

http://git-wip-us.apache.org/repos/asf/activemq-cpp/blob/6b190a98/activemq-cpp/src/main/activemq/core/policies/DefaultRedeliveryPolicy.h
----------------------------------------------------------------------
diff --git a/activemq-cpp/src/main/activemq/core/policies/DefaultRedeliveryPolicy.h b/activemq-cpp/src/main/activemq/core/policies/DefaultRedeliveryPolicy.h
index 8635f63..0a205c8 100644
--- a/activemq-cpp/src/main/activemq/core/policies/DefaultRedeliveryPolicy.h
+++ b/activemq-cpp/src/main/activemq/core/policies/DefaultRedeliveryPolicy.h
@@ -36,6 +36,7 @@ namespace policies {
         bool useCollisionAvoidance;
         bool useExponentialBackOff;
         long long redeliveryDelay;
+        long long maximumRedeliveryDelay;
 
     private:
 
@@ -100,6 +101,14 @@ namespace policies {
             this->useExponentialBackOff = value;
         }
 
+        virtual long long getMaximumRedeliveryDelay() const {
+            return this->maximumRedeliveryDelay;
+        }
+
+        virtual void setMaximumRedeliveryDelay(long long value) {
+            this->maximumRedeliveryDelay = value;
+        }
+
         virtual long long getNextRedeliveryDelay(long long previousDelay);
 
         virtual RedeliveryPolicy* clone() const;


Mime
View raw message