Author: tabish
Date: Fri Aug 6 14:26:58 2010
New Revision: 982987
URL: http://svn.apache.org/viewvc?rev=982987&view=rev
Log:
https://issues.apache.org/activemq/browse/AMQCPP-308
Modified:
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQConsumer.cpp
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/RedeliveryPolicy.cpp
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/RedeliveryPolicy.h
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/policies/DefaultRedeliveryPolicy.cpp
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/policies/DefaultRedeliveryPolicy.h
Modified:
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQConsumer.cpp
URL:
http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQConsumer.cpp?rev=982987&r1=982986&r2=982987&view=diff
==============================================================================
---
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQConsumer.cpp
(original)
+++
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQConsumer.cpp
Fri Aug 6 14:26:58 2010
@@ -883,7 +883,9 @@ void ActiveMQConsumer::rollback() {
Pointer<MessageDispatch> lastMsg = dispatchedMessages.front();
const int currentRedeliveryCount =
lastMsg->getMessage()->getRedeliveryCounter();
if( currentRedeliveryCount > 0 ) {
- redeliveryDelay = this->redeliveryPolicy->getRedeliveryDelay(
redeliveryDelay );
+ redeliveryDelay =
this->redeliveryPolicy->getNextRedeliveryDelay( redeliveryDelay );
+ } else {
+ redeliveryDelay =
this->redeliveryPolicy->getInitialRedeliveryDelay();
}
Pointer<MessageId> firstMsgId =
Modified:
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/RedeliveryPolicy.cpp
URL:
http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/RedeliveryPolicy.cpp?rev=982987&r1=982986&r2=982987&view=diff
==============================================================================
---
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/RedeliveryPolicy.cpp
(original)
+++
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/RedeliveryPolicy.cpp
Fri Aug 6 14:26:58 2010
@@ -56,6 +56,10 @@ void RedeliveryPolicy::configure( const
this->setInitialRedeliveryDelay( Long::parseLong(
properties.getProperty(
"cms.RedeliveryPolicy.initialRedeliveryDelay" ) ) );
}
+ if( properties.hasProperty( "cms.RedeliveryPolicy.redeliveryDelay" ) )
{
+ this->setRedeliveryDelay( Long::parseLong(
+ properties.getProperty( "cms.RedeliveryPolicy.redeliveryDelay"
) ) );
+ }
if( properties.hasProperty( "cms.RedeliveryPolicy.maximumRedeliveries"
) ) {
this->setMaximumRedeliveries( Integer::parseInt(
properties.getProperty(
"cms.RedeliveryPolicy.maximumRedeliveries" ) ) );
Modified:
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/RedeliveryPolicy.h
URL:
http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/RedeliveryPolicy.h?rev=982987&r1=982986&r2=982987&view=diff
==============================================================================
---
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/RedeliveryPolicy.h
(original)
+++
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/RedeliveryPolicy.h
Fri Aug 6 14:26:58 2010
@@ -89,6 +89,21 @@ namespace core {
virtual void setInitialRedeliveryDelay( long long value ) = 0;
/**
+ * Gets the time that redelivery of messages is delayed.
+ *
+ * @returns the time in milliseconds that redelivery is delayed.
+ */
+ virtual long long getRedeliveryDelay() const = 0;
+
+ /**
+ * Sets the time that redelivery will be delayed.
+ *
+ * @param value
+ * Time in Milliseconds to wait before the next redelivery.
+ */
+ virtual void setRedeliveryDelay( long long value ) = 0;
+
+ /**
* Gets the Maximum number of allowed redeliveries for a message
before it will
* be discarded by the consumer.
*
@@ -113,7 +128,7 @@ namespace core {
*
* @return the new delay to use before attempting another redelivery.
*/
- virtual long long getRedeliveryDelay( long long previousDelay ) = 0;
+ virtual long long getNextRedeliveryDelay( long long previousDelay ) =
0;
/**
* @returns whether or not collision avoidance is enabled for this
Policy.
Modified:
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/policies/DefaultRedeliveryPolicy.cpp
URL:
http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/policies/DefaultRedeliveryPolicy.cpp?rev=982987&r1=982986&r2=982987&view=diff
==============================================================================
---
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/policies/DefaultRedeliveryPolicy.cpp
(original)
+++
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/policies/DefaultRedeliveryPolicy.cpp
Fri Aug 6 14:26:58 2010
@@ -36,6 +36,7 @@ DefaultRedeliveryPolicy::DefaultRedelive
this->useCollisionAvoidance = false;
this->useExponentialBackOff = false;
this->backOffMultiplier = 5.0;
+ this->redeliveryDelay = initialRedeliveryDelay;
}
////////////////////////////////////////////////////////////////////////////////
@@ -53,18 +54,18 @@ void DefaultRedeliveryPolicy::setCollisi
}
////////////////////////////////////////////////////////////////////////////////
-long long DefaultRedeliveryPolicy::getRedeliveryDelay( long long previousDelay
) {
+long long DefaultRedeliveryPolicy::getNextRedeliveryDelay( long long
previousDelay ) {
static Random randomNumberGenerator;
- long long redeliveryDelay;
+ long long nextDelay;
if( previousDelay == 0 ) {
- redeliveryDelay = initialRedeliveryDelay;
+ nextDelay = redeliveryDelay;
} else if( useExponentialBackOff && (int)backOffMultiplier > 1 ) {
- redeliveryDelay = (long long)( (double)previousDelay *
backOffMultiplier );
+ nextDelay = (long long)( (double)previousDelay * backOffMultiplier );
} else {
- redeliveryDelay = previousDelay;
+ nextDelay = previousDelay;
}
if( useCollisionAvoidance ) {
@@ -74,10 +75,10 @@ long long DefaultRedeliveryPolicy::getRe
*/
double variance = ( randomNumberGenerator.nextBoolean() ?
collisionAvoidanceFactor : -collisionAvoidanceFactor ) *
randomNumberGenerator.nextDouble( );
- redeliveryDelay += (long long)( (double)redeliveryDelay * variance );
+ nextDelay += (long long)( (double)nextDelay * variance );
}
- return redeliveryDelay;
+ return nextDelay;
}
////////////////////////////////////////////////////////////////////////////////
@@ -91,6 +92,7 @@ RedeliveryPolicy* DefaultRedeliveryPolic
copy->useCollisionAvoidance = this->useCollisionAvoidance;
copy->useExponentialBackOff = this->useExponentialBackOff;
copy->backOffMultiplier = this->backOffMultiplier;
+ copy->redeliveryDelay = this->redeliveryDelay;
return copy;
}
Modified:
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/policies/DefaultRedeliveryPolicy.h
URL:
http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/policies/DefaultRedeliveryPolicy.h?rev=982987&r1=982986&r2=982987&view=diff
==============================================================================
---
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/policies/DefaultRedeliveryPolicy.h
(original)
+++
activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/policies/DefaultRedeliveryPolicy.h
Fri Aug 6 14:26:58 2010
@@ -35,6 +35,7 @@ namespace policies {
int maximumRedeliveries;
bool useCollisionAvoidance;
bool useExponentialBackOff;
+ long long redeliveryDelay;
private:
@@ -67,6 +68,14 @@ namespace policies {
this->initialRedeliveryDelay = value;
}
+ virtual long long getRedeliveryDelay() const {
+ return this->redeliveryDelay;
+ }
+
+ virtual void setRedeliveryDelay( long long value ) {
+ this->redeliveryDelay = value;
+ }
+
virtual int getMaximumRedeliveries() const {
return this->maximumRedeliveries;
}
@@ -91,7 +100,7 @@ namespace policies {
this->useExponentialBackOff = value;
}
- virtual long long getRedeliveryDelay( long long previousDelay );
+ virtual long long getNextRedeliveryDelay( long long previousDelay );
virtual RedeliveryPolicy* clone() const;