KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > broker > util > TimeStampingBrokerPlugin


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

18 package org.apache.activemq.broker.util;
19
20 import org.apache.activemq.broker.BrokerPluginSupport;
21 import org.apache.activemq.broker.ConnectionContext;
22 import org.apache.activemq.broker.ProducerBrokerExchange;
23 import org.apache.activemq.command.Message;
24
25
26 /**
27  * A Broker interceptor which updates a JMS Client's timestamp on the message
28  * with a broker timestamp. Useful when the clocks on client machines are known to
29  * not be correct and you can only trust the time set on the broker machines.
30  *
31  * Enabling this plugin will break JMS compliance since the timestamp that the producer
32  * sees on the messages after as send() will be different from the timestamp the consumer
33  * will observe when he receives the message. This plugin is not enabled in the default
34  * ActiveMQ configuration.
35  *
36  * @org.apache.xbean.XBean element="timeStampingBrokerPlugin"
37  *
38  * @version $Revision$
39  */

40 public class TimeStampingBrokerPlugin extends BrokerPluginSupport {
41     public void send(ProducerBrokerExchange producerExchange, Message message) throws Exception JavaDoc {
42         if (message.getTimestamp() > 0 && (message.getBrokerPath() == null || message.getBrokerPath().length == 0)) {
43             //timestamp not been disabled and has not passed through a network
44
message.setTimestamp(System.currentTimeMillis());
45         }
46         super.send(producerExchange, message);
47     }
48 }
49
Popular Tags