activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r1170867 - in /activemq/trunk/activemq-tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool: JmsProducerClient.java properties/JmsProducerProperties.java
Date Wed, 14 Sep 2011 22:07:30 GMT
Author: tabish
Date: Wed Sep 14 22:07:30 2011
New Revision: 1170867

URL: http://svn.apache.org/viewvc?rev=1170867&view=rev
Log:
apply patch for: https://issues.apache.org/jira/browse/AMQ-3492

Modified:
    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/JmsProducerProperties.java

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=1170867&r1=1170866&r2=1170867&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
Wed Sep 14 22:07:30 2011
@@ -16,6 +16,12 @@
  */
 package org.apache.activemq.tool;
 
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+
 import java.util.Arrays;
 import java.util.Set;
 
@@ -83,7 +89,20 @@ public class JmsProducerClient extends A
         }
         try {
             getConnection().start();
-            LOG.info("Starting to publish " + client.getMessageSize() + " byte(s) of " +
messageCount + " messages...");
+            if (client.getMsgFileName() != null) {
+            	LOG.info("Starting to publish " +
+            		messageCount + 
+            		" messages from file " + 
+            		client.getMsgFileName()
+            	);
+            } else {
+            	LOG.info("Starting to publish " +
+            		messageCount +
+            		" messages of size " +
+            		client.getMessageSize() + 
+            		" byte(s)." 
+            	);
+            }
 
             // Send one type of message only, avoiding the creation of different messages
on sending
             if (!client.isCreateNewMsg()) {
@@ -158,8 +177,19 @@ public class JmsProducerClient extends A
 
         try {
             getConnection().start();
-            LOG.info("Starting to publish " + client.getMessageSize() + " byte(s) messages
for " + duration + " ms");
-
+            if (client.getMsgFileName() != null) {
+            	LOG.info("Starting to publish messages from file " + 
+            			client.getMsgFileName() + 
+            			" for " +
+            			duration + 
+            			" ms");
+            } else {
+            	LOG.info("Starting to publish " + 
+            			client.getMessageSize() + 
+            			" byte(s) messages for " + 
+            			duration + 
+            			" ms");
+            }
             // Send one type of message only, avoiding the creation of different messages
on sending
             if (!client.isCreateNewMsg()) {
                 // Create only a single message
@@ -252,7 +282,11 @@ public class JmsProducerClient extends A
     }
 
     public TextMessage createJmsTextMessage() throws JMSException {
-        return createJmsTextMessage(client.getMessageSize());
+    	if (client.getMsgFileName() != null) {
+    		return loadJmsMessage();
+    	} else {
+          return createJmsTextMessage(client.getMessageSize());
+    	}
     }
 
     public TextMessage createJmsTextMessage(int size) throws JMSException {
@@ -300,4 +334,38 @@ public class JmsProducerClient extends A
         	}
         }
     }
+    
+    /**
+     * loads the message to be sent from the specified TextFile
+     */
+    protected TextMessage loadJmsMessage() throws JMSException {
+    	try {
+    		// couple of sanity checks upfront 
+    		if (client.getMsgFileName() == null) {
+    			throw new JMSException("Invalid filename specified.");
+    		}
+    		
+    		File f = new File(client.getMsgFileName());
+    		if (f.isDirectory()) {
+    			throw new JMSException("Cannot load from " + 
+    					client.getMsgFileName() + 
+    					" as it is a directory not a text file.");
+    		} 
+    		
+    		// try to load file
+    		BufferedReader br = new BufferedReader(new FileReader(f));
+    		StringBuffer payload = new StringBuffer();
+    		String tmp = null;
+    		while ((tmp = br.readLine()) != null) {
+    			payload.append(tmp);
+    		}
+    		jmsTextMessage = getSession().createTextMessage(payload.toString());
+    		return jmsTextMessage;
+    		
+    	} catch (FileNotFoundException ex) {
+    		throw new JMSException(ex.getMessage());
+    	} catch (IOException iox) {
+    		throw new JMSException(iox.getMessage());
+    	}
+    }
 }

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=1170867&r1=1170866&r2=1170867&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
Wed Sep 14 22:07:30 2011
@@ -31,13 +31,14 @@ public class JmsProducerProperties exten
     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
     public static final String DELIVERY_MODE_NON_PERSISTENT = "nonpersistent"; // Non-persistent
message delivery
-
+    
     protected String deliveryMode = DELIVERY_MODE_NON_PERSISTENT; // Message delivery mode
     protected int messageSize = 1024; // Send 1kb messages by default
     protected long sendCount  = 1000000; // Send a million messages by default
     protected long sendDuration = 5 * 60 * 1000; // Send for 5 mins by default
     protected String sendType = TIME_BASED_SENDING;
     protected long sendDelay = 0;  // delay in milliseconds between each producer send
+    protected String msgFileName = null; // for sending a particular msg from a file
     
     protected Map<String,Object> headerMap = null;
  
@@ -153,4 +154,15 @@ public class JmsProducerProperties exten
     public void clearHeaders() {
     	this.headerMap.clear();
     }
+    
+    public void setMsgFileName(String file) {
+    	LOG.info("\"producer.msgFileName\" specified. " +
+    			"Will ignore setting \"producer.messageSize\".");
+    	this.msgFileName = file;
+    }
+    
+    public String getMsgFileName() {
+    	return this.msgFileName;
+    }
+    
 }



Mime
View raw message