activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dej...@apache.org
Subject svn commit: r1091434 - in /activemq/trunk/activemq-tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool: JmsConsumerClient.java JmsProducerClient.java properties/JmsConsumerProperties.java properties/JmsProducerProperties.java
Date Tue, 12 Apr 2011 14:38:53 GMT
Author: dejanb
Date: Tue Apr 12 14:38:52 2011
New Revision: 1091434

URL: http://svn.apache.org/viewvc?rev=1091434&view=rev
Log:
https://issues.apache.org/jira/browse/AMQ-3280 - support selectors in perf plugin

Modified:
    activemq/trunk/activemq-tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/JmsConsumerClient.java
    activemq/trunk/activemq-tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/JmsProducerClient.java
    activemq/trunk/activemq-tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/properties/JmsConsumerProperties.java
    activemq/trunk/activemq-tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/properties/JmsProducerProperties.java

Modified: activemq/trunk/activemq-tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/JmsConsumerClient.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/JmsConsumerClient.java?rev=1091434&r1=1091433&r2=1091434&view=diff
==============================================================================
--- activemq/trunk/activemq-tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/JmsConsumerClient.java
(original)
+++ activemq/trunk/activemq-tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/JmsConsumerClient.java
Tue Apr 12 14:38:52 2011
@@ -193,7 +193,11 @@ public class JmsConsumerClient extends A
 
     public MessageConsumer createJmsConsumer() throws JMSException {
         Destination[] dest = createDestination(destIndex, destCount);
-        return createJmsConsumer(dest[0]);
+        
+        if (this.client.getMessageSelector() == null)
+        	return createJmsConsumer(dest[0]);
+        else 
+        	return createJmsConsumer(dest[0], this.client.getMessageSelector(), false);
     }
 
     public MessageConsumer createJmsConsumer(Destination dest) throws JMSException {

Modified: activemq/trunk/activemq-tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/JmsProducerClient.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/JmsProducerClient.java?rev=1091434&r1=1091433&r2=1091434&view=diff
==============================================================================
--- activemq/trunk/activemq-tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/JmsProducerClient.java
(original)
+++ activemq/trunk/activemq-tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/JmsProducerClient.java
Tue Apr 12 14:38:52 2011
@@ -17,6 +17,7 @@
 package org.apache.activemq.tool;
 
 import java.util.Arrays;
+import java.util.Set;
 
 import javax.jms.ConnectionFactory;
 import javax.jms.DeliveryMode;
@@ -248,6 +249,13 @@ public class JmsProducerClient extends A
 
     public TextMessage createJmsTextMessage(int size) throws JMSException {
         jmsTextMessage = getSession().createTextMessage(buildText("", size));
+        
+        // support for adding message headers
+        Set<String> headerKeys = this.client.getHeaderKeys();
+        for (String key : headerKeys) {
+        	jmsTextMessage.setObjectProperty(key, this.client.getHeaderValue(key));
+        }
+        
         return jmsTextMessage;
     }
 

Modified: activemq/trunk/activemq-tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/properties/JmsConsumerProperties.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/properties/JmsConsumerProperties.java?rev=1091434&r1=1091433&r2=1091434&view=diff
==============================================================================
--- activemq/trunk/activemq-tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/properties/JmsConsumerProperties.java
(original)
+++ activemq/trunk/activemq-tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/properties/JmsConsumerProperties.java
Tue Apr 12 14:38:52 2011
@@ -28,7 +28,8 @@ public class JmsConsumerProperties exten
     protected long recvDuration = 5 * 60 * 1000; // Receive for 5 mins by default
     protected long recvDelay = 0; // delay in milliseconds for processing received msg 
     protected String recvType   = TIME_BASED_RECEIVING;
-
+    protected String messageSelector = null;
+    
     public boolean isDurable() {
         return durable;
     }
@@ -84,4 +85,13 @@ public class JmsConsumerProperties exten
     public long getRecvDelay() {
     	return this.recvDelay;
     }
+    
+    public String getMessageSelector() {
+    	return this.messageSelector;
+    }
+    
+    public void setMessageSelector(String selector) {
+    	if (selector != null )
+    		this.messageSelector = new String(selector);
+    }
 }

Modified: activemq/trunk/activemq-tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/properties/JmsProducerProperties.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/properties/JmsProducerProperties.java?rev=1091434&r1=1091433&r2=1091434&view=diff
==============================================================================
--- activemq/trunk/activemq-tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/properties/JmsProducerProperties.java
(original)
+++ activemq/trunk/activemq-tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/properties/JmsProducerProperties.java
Tue Apr 12 14:38:52 2011
@@ -16,7 +16,17 @@
  */
 package org.apache.activemq.tool.properties;
 
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 public class JmsProducerProperties extends JmsClientProperties {
+	
+	private static final Logger LOG = LoggerFactory.getLogger(ReflectionUtil.class);
+	
     public static final String TIME_BASED_SENDING  = "time"; // Produce messages base on
a time interval
     public static final String COUNT_BASED_SENDING = "count"; // Produce a specific count
of messages
     public static final String DELIVERY_MODE_PERSISTENT     = "persistent"; // Persistent
message delivery
@@ -29,8 +39,15 @@ public class JmsProducerProperties exten
     protected String sendType = TIME_BASED_SENDING;
     protected long sendDelay = 0;  // delay in milliseconds between each producer send
     
+    protected Map<String,Object> headerMap = null;
+ 
+    
     // If true, create a different message on each send, otherwise reuse.
     protected boolean createNewMsg; 
+    
+    public JmsProducerProperties() {
+    	this.headerMap = new HashMap();
+    }
 
     public String getDeliveryMode() {
         return deliveryMode;
@@ -87,4 +104,53 @@ public class JmsProducerProperties exten
     public long getSendDelay() {
     	return this.sendDelay;
     }
+    
+    
+    /* Operations for supporting message headers */
+    
+    /**
+     * Method for setting a message header. 
+     * @param encodedHeader - the header is encoded as a string using this syntax:
+     * encodedHeader = [headerkey '=' headervalue ':' ]*
+     * E.g. an encodedHeader could read "JMSType=car", or
+     * "JMSType=car:MyHeader=MyValue"
+     *
+     * That implies neither the header key nor the value 
+     * can contain any of the characters ':' and '='.
+     */
+    public void setHeader(String encodedHeader) {
+    	
+    	// remove any trailing ':' characters
+    	if (encodedHeader.endsWith(":")) {
+    		encodedHeader = encodedHeader.substring(0, encodedHeader.length()-1);
+    	}
+
+    	// split headers 
+    	String headers[] = encodedHeader.split(":");
+    	for (String h : headers) {
+    		
+    		// split into header name and value
+    		String tokens[] = h.split("=");
+    		
+    		// sanity check, don't allow empty string for header names
+    		if (tokens.length != 2 || tokens[0].equals("") || tokens[1].equals("") ) {
+    			LOG.error("Error parsing message headers. Header: \"" + h +
+    					"\". This header will be ignored.");
+    		} else {
+    			this.headerMap.put(tokens[0], tokens[1]);
+    		}
+    	}
+    }
+    
+    public Set<String> getHeaderKeys() {
+    	return this.headerMap.keySet();
+    }
+    
+    public Object getHeaderValue(String key) {
+    	return this.headerMap.get(key);
+    }  
+    
+    public void clearHeaders() {
+    	this.headerMap.clear();
+    }
 }



Mime
View raw message