/**
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.activemq.broker.util;

import org.apache.activemq.broker.BrokerPluginSupport;
import org.apache.activemq.broker.ProducerBrokerExchange;
import org.apache.activemq.command.Message;

/**
 * A Broker interceptor which updates a JMS Client's timestamp on the message
 * with a broker timestamp. Useful when the clocks on client machines are known
 * to not be correct and you can only trust the time set on the broker machines.
 * 
 * Enabling this plugin will break JMS compliance since the timestamp that the
 * producer sees on the messages after as send() will be different from the
 * timestamp the consumer will observe when he receives the message. This plugin
 * is not enabled in the default ActiveMQ configuration.
 * 
 * @org.apache.xbean.XBean element="timeStampingBrokerPlugin"
 * 
 * @version $Revision$
 */
public class TimeStampingBrokerPlugin extends BrokerPluginSupport {
    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
            message.setTimestamp(System.currentTimeMillis());
        }
        super.send(producerExchange, message);
    }
}

@@ -2021,16 +2021,37 @@
         
+ long oldExpiration =
  message
@@ -2055,21 +2055,57 @@
 age.
-s
+g
 et
+Expiration();%0A            long new
 Time
-s
+S
 tamp
-(
+ = 
 Syst
@@ -2126,16 +2126,346 @@
 Millis()
+;%0A            if (oldExpiration %3E 0) %7B%0A                long oldTimestamp = message.getTimestamp();%0A                long timeToLive = oldExpiration-oldTimestamp;%0A                long expiration = timeToLive+newTimeStamp;%0A                message.setExpiration(expiration);%0A            %7D%0A            message.setTimestamp(newTimeStamp
 );%0A     

set new expiration time