Return-Path: Delivered-To: apmail-activemq-commits-archive@www.apache.org Received: (qmail 74166 invoked from network); 24 Apr 2009 08:27:34 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 24 Apr 2009 08:27:34 -0000 Received: (qmail 55274 invoked by uid 500); 24 Apr 2009 08:27:34 -0000 Delivered-To: apmail-activemq-commits-archive@activemq.apache.org Received: (qmail 55223 invoked by uid 500); 24 Apr 2009 08:27:34 -0000 Mailing-List: contact commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list commits@activemq.apache.org Received: (qmail 55214 invoked by uid 99); 24 Apr 2009 08:27:34 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 24 Apr 2009 08:27:34 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 24 Apr 2009 08:27:32 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id C6D432388979; Fri, 24 Apr 2009 08:27:10 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@activemq.apache.org From: dejanb@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090424082710.C6D432388979@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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); }