1 /** 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 package org.apache.activemq.broker.util; 18 19 import java.io.IOException; 20 import java.util.Map; 21 22 import org.apache.activemq.broker.BrokerPluginSupport; 23 import org.apache.activemq.command.MessageDispatch; 24 import org.apache.commons.logging.Log; 25 import org.apache.commons.logging.LogFactory; 26 27 /** 28 * The TraceBrokerPathPlugin can be used in a network of Brokers. Each Broker 29 * that has the plugin configured, will add it's brokerName to the content 30 * of a JMS Property. If all Brokers have this property enabled, the path the 31 * message actually took through the network can be seen in the defined property. 32 * 33 * @org.apache.xbean.XBean element="traceBrokerPathPlugin" 34 * 35 * @version $Revision$ 36 */ 37 38 public class TraceBrokerPathPlugin extends BrokerPluginSupport { 39 40 private String stampProperty = "BrokerPath"; 41 private static final Log LOG = LogFactory.getLog(TraceBrokerPathPlugin.class); 42 43 public String getStampProperty() { 44 return stampProperty; 45 } 46 47 public void setStampProperty(String stampProperty) { 48 this.stampProperty = stampProperty; 49 } 50 51 public void preProcessDispatch(MessageDispatch messageDispatch) { 52 try { 53 String brokerStamp = (String)messageDispatch.getMessage().getProperty(getStampProperty()); 54 if (brokerStamp == null) { 55 brokerStamp = getBrokerName(); 56 } else { 57 brokerStamp += "," + getBrokerName(); 58 } 59 messageDispatch.getMessage().setProperty(getStampProperty(), brokerStamp); 60 } catch (IOException ioe) { 61 LOG.warn("Setting broker property failed " + ioe, ioe); 62 } 63 super.preProcessDispatch(messageDispatch); 64 } 65 }