activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dej...@apache.org
Subject svn commit: r768219 - /activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/TimeStampingBrokerPlugin.java
Date Fri, 24 Apr 2009 08:27:10 GMT
Author: dejanb
Date: Fri Apr 24 08:27:10 2009
New Revision: 768219

URL: http://svn.apache.org/viewvc?rev=768219&view=rev
Log:
fix for https://issues.apache.org/activemq/browse/AMQ-2221 - improvments for timestamp plugin

Modified:
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/TimeStampingBrokerPlugin.java

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/TimeStampingBrokerPlugin.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/TimeStampingBrokerPlugin.java?rev=768219&r1=768218&r2=768219&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/TimeStampingBrokerPlugin.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/TimeStampingBrokerPlugin.java
Fri Apr 24 08:27:10 2009
@@ -19,6 +19,8 @@
 import org.apache.activemq.broker.BrokerPluginSupport;
 import org.apache.activemq.broker.ProducerBrokerExchange;
 import org.apache.activemq.command.Message;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 /**
  * A Broker interceptor which updates a JMS Client's timestamp on the message
@@ -30,24 +32,70 @@
  * timestamp the consumer will observe when he receives the message. This plugin
  * is not enabled in the default ActiveMQ configuration.
  * 
+ * 2 new attributes have been added which will allow the administrator some override control
+ * over the expiration time for incoming messages:
+ *
+ * Attribute 'zeroExpirationOverride' can be used to apply an expiration
+ * time to incoming messages with no expiration defined (messages that would never expire)
+ *
+ * Attribute 'ttlCeiling' can be used to apply a limit to the expiration time
+ *
  * @org.apache.xbean.XBean element="timeStampingBrokerPlugin"
  * 
  * @version $Revision$
  */
 public class TimeStampingBrokerPlugin extends BrokerPluginSupport {
+
+    private static final Log LOG = LogFactory.getLog(TimeStampingBrokerPlugin.class);
+
+    /** 
+    * variable which (when non-zero) is used to override
+    * the expiration date for messages that arrive with
+    * no expiration date set (in Milliseconds).
+    */
+    long zeroExpirationOverride = 0;
+
+    /** 
+    * variable which (when non-zero) is used to limit
+    * the expiration date (in Milliseconds).  
+    */
+    long ttlCeiling = 0;
+
+    /** 
+    * setter method for zeroExpirationOverride
+    */
+    public void setZeroExpirationOverride(long ttl)
+    {
+        this.zeroExpirationOverride = ttl;
+    }
+
+    /** 
+    * setter method for ttlCeiling
+    */
+    public void setTtlCeiling(long ttlCeiling)
+    {
+        this.ttlCeiling = ttlCeiling;
+    }
+
     public void send(ProducerBrokerExchange producerExchange, Message message) throws Exception
{
         if (message.getTimestamp() > 0
             && (message.getBrokerPath() == null || message.getBrokerPath().length
== 0)) {
             // timestamp not been disabled and has not passed through a network
             long oldExpiration = message.getExpiration();
             long newTimeStamp = System.currentTimeMillis();
+            message.setTimestamp(newTimeStamp);
+            long timeToLive = zeroExpirationOverride;
             if (oldExpiration > 0) {
                 long oldTimestamp = message.getTimestamp();
-                long timeToLive = oldExpiration-oldTimestamp;
-                long expiration = timeToLive+newTimeStamp;
+                timeToLive = oldExpiration - oldTimestamp;
+            }
+            if (timeToLive > 0 && ttlCeiling > 0 && timeToLive >
ttlCeiling) {
+                timeToLive = ttlCeiling;
+            }
+            long expiration = timeToLive + newTimeStamp;
+            if (timeToLive > 0 && expiration > 0) {
                 message.setExpiration(expiration);
             }
-            message.setTimestamp(newTimeStamp);
         }
         super.send(producerExchange, message);
     }



Mime
View raw message