You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by fo...@apache.org on 2006/05/31 16:16:19 UTC
svn commit: r410534 - in /incubator/activemq/trunk: activemq-perftest/
assembly/ tooling/maven-activemq-perf-plugin/
tooling/maven-activemq-perf-plugin/src/
tooling/maven-activemq-perf-plugin/src/main/
tooling/maven-activemq-perf-plugin/src/main/java/ ...
Author: foconer
Date: Wed May 31 07:16:18 2006
New Revision: 410534
URL: http://svn.apache.org/viewvc?rev=410534&view=rev
Log:
Renamed perf plugin to activemq-perf and added plugin that will start broker in assembly.
Added:
incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/
incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/pom.xml
incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/
incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/
incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/
incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/
incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/
incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/
incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/maven/
incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/maven/ConsumerMojo.java
incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/maven/ProducerMojo.java
incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/maven/ServerMojo.java
incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/
incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/ConsumerTool.java
incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/ProducerTool.java
incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/ToolSupport.java
Removed:
incubator/activemq/trunk/tooling/maven-perf-plugin/
Modified:
incubator/activemq/trunk/activemq-perftest/pom.xml
incubator/activemq/trunk/assembly/pom.xml
Modified: incubator/activemq/trunk/activemq-perftest/pom.xml
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-perftest/pom.xml?rev=410534&r1=410533&r2=410534&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-perftest/pom.xml (original)
+++ incubator/activemq/trunk/activemq-perftest/pom.xml Wed May 31 07:16:18 2006
@@ -18,7 +18,7 @@
<plugins>
<plugin>
<groupId>incubator-activemq</groupId>
- <artifactId>maven-perf-plugin</artifactId>
+ <artifactId>maven-activemq-perf-plugin</artifactId>
<version>4.0-SNAPSHOT</version>
</plugin>
</plugins>
Modified: incubator/activemq/trunk/assembly/pom.xml
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/assembly/pom.xml?rev=410534&r1=410533&r2=410534&view=diff
==============================================================================
--- incubator/activemq/trunk/assembly/pom.xml (original)
+++ incubator/activemq/trunk/assembly/pom.xml Wed May 31 07:16:18 2006
@@ -296,7 +296,15 @@
</execution>
</executions>
</plugin>
+ <plugin>
+ <groupId>incubator-activemq</groupId>
+ <artifactId>maven-activemq-perf-plugin</artifactId>
+ <version>4.0-SNAPSHOT</version>
+ <configuration>
+ <configFile>src/release/conf/activemq.xml</configFile>
+ </configuration>
+ </plugin>
</plugins>
</build>
-</project>
+</project>
\ No newline at end of file
Added: incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/pom.xml
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/pom.xml?rev=410534&view=auto
==============================================================================
--- incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/pom.xml (added)
+++ incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/pom.xml Wed May 31 07:16:18 2006
@@ -0,0 +1,57 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>incubator-activemq</groupId>
+ <artifactId>activemq-parent</artifactId>
+ <version>4.0-SNAPSHOT</version>
+ <relativePath>../../pom.xml</relativePath>
+ </parent>
+
+
+ <groupId>incubator-activemq</groupId>
+ <artifactId>maven-activemq-perf-plugin</artifactId>
+ <packaging>maven-plugin</packaging>
+ <name>ActiveMQ :: Performance Test Plugin</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-plugin-api</artifactId>
+ <version>2.0</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>incubator-activemq</groupId>
+ <artifactId>activemq-core</artifactId>
+ <version>4.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>incubator-activemq</groupId>
+ <artifactId>activemq-console</artifactId>
+ <version>4.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.derby</groupId>
+ <artifactId>derby</artifactId>
+ <version>10.1.1.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.derby</groupId>
+ <artifactId>derbynet</artifactId>
+ <version>10.1.1.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-j2ee-management_1.0_spec</artifactId>
+ <version>1.0</version>
+ </dependency>
+ </dependencies>
+</project>
\ No newline at end of file
Added: incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/maven/ConsumerMojo.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/maven/ConsumerMojo.java?rev=410534&view=auto
==============================================================================
--- incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/maven/ConsumerMojo.java (added)
+++ incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/maven/ConsumerMojo.java Wed May 31 07:16:18 2006
@@ -0,0 +1,69 @@
+package org.apache.activemq.maven;
+
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+
+import org.apache.activemq.tool.ConsumerTool;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+
+
+/**
+ * Goal which touches a timestamp file.
+ *
+ * @goal consumer
+ * @phase process
+ */
+public class ConsumerMojo
+ extends AbstractMojo {
+
+ /**
+ * @parameter expression="${url}" default-value="tcp://localhost:61616"
+ * @required
+ */
+ private String url;
+
+ /**
+ * @parameter expression="${topic}" default-value="true"
+ * @required
+ */
+ private String topic;
+
+ /**
+ * @parameter expression="${subject}" default-value="FOO.BAR"
+ * @required
+ */
+ private String subject;
+
+ /**
+ * @parameter expression="${durable}" default-value="false"
+ * @required
+ */
+ private String durable;
+
+ /**
+ * @parameter expression="${maximumMessage}" default-value="10"
+ * @required
+ */
+ private String maximumMessage;
+
+ public void execute()
+ throws MojoExecutionException {
+
+ String[] args = {url, topic, subject, durable, maximumMessage};
+ ConsumerTool.main(args);
+ }
+}
Added: incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/maven/ProducerMojo.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/maven/ProducerMojo.java?rev=410534&view=auto
==============================================================================
--- incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/maven/ProducerMojo.java (added)
+++ incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/maven/ProducerMojo.java Wed May 31 07:16:18 2006
@@ -0,0 +1,71 @@
+package org.apache.activemq.maven;
+
+import org.apache.activemq.tool.ConsumerTool;
+import org.apache.activemq.tool.ProducerTool;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+
+
+/**
+ * Goal which touches a timestamp file.
+ *
+ * @goal producer
+ * @phase process
+ */
+public class ProducerMojo
+ extends AbstractMojo {
+
+ /**
+ * @parameter expression="${url}" default-value="tcp://localhost:61616"
+ * @required
+ */
+ private String url;
+ /**
+ * @parameter expression="${topic}" default-value="true"
+ * @required
+ */
+ private String topic;
+ /**
+ * @parameter expression="${subject}" default-value="FOO.BAR"
+ * @required
+ */
+ private String subject;
+ /**
+ * @parameter expression="${durable}" default-value="false"
+ * @required
+ */
+ private String durable;
+ /**
+ * @parameter expression="${messageCount}" default-value="10"
+ * @required
+ */
+ private String messageCount;
+ /**
+ * @parameter expression="${messageSize}" default-value="255"
+ * @required
+ */
+ private String messageSize;
+
+ public void execute()
+ throws MojoExecutionException {
+
+ String[] args = {url,topic,subject,durable,messageCount,messageSize};
+ ProducerTool.main(args);
+ }
+}
Added: incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/maven/ServerMojo.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/maven/ServerMojo.java?rev=410534&view=auto
==============================================================================
--- incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/maven/ServerMojo.java (added)
+++ incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/maven/ServerMojo.java Wed May 31 07:16:18 2006
@@ -0,0 +1,124 @@
+package org.apache.activemq.maven;
+
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+
+import org.apache.activemq.console.Main;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.nio.MappedByteBuffer;
+import java.nio.channels.FileChannel;
+
+/**
+ * Goal which starts activemq broker.
+ *
+ * @goal broker
+ * @phase process-sources
+ */
+public class ServerMojo
+ extends AbstractMojo {
+ /**
+ * Location of the output directory. Defaults to target.
+ *
+ * @parameter expression="${project.build.directory}"
+ * @required
+ */
+ private File outputDirectory;
+
+ /**
+ * Location of the predefined config files.
+ *
+ * @parameter expression="${configDirectory}" default-value="${basedir}/src/main/resources/broker-conf"
+ * @required
+ */
+ private String configDirectory;
+
+ /**
+ * Type of activemq configuration to use. This is also the filename used.
+ *
+ * @parameter expression="${configType}" default-value="activemq"
+ * @required
+ */
+ private String configType;
+
+ /**
+ * Location of activemq config file other those found in resources/config.
+ *
+ * @parameter expression="${configFile}"
+ */
+ private File configFile;
+
+ public void execute()
+ throws MojoExecutionException {
+
+ File out = outputDirectory;
+
+ // Create output directory if it doesn't exist.
+ if (!out.exists()) {
+ out.mkdirs();
+ }
+
+ File config;
+ if (configFile != null) {
+ config = configFile;
+ } else {
+ config = new File(configDirectory + File.separator + configType + ".xml");
+ }
+
+ try {
+ config = copy(config);
+ } catch (IOException e) {
+ throw new MojoExecutionException(e.getMessage());
+ }
+
+ String[] args = {"start", "xbean:" + (config.toURI()).toString()};
+ Main.main(args);
+ }
+
+ /**
+ * Copy activemq configuration file to output directory.
+ *
+ * @param source
+ * @return
+ * @throws IOException
+ */
+ public File copy(File source) throws IOException {
+ FileChannel in = null, out = null;
+
+ File dest = new File(outputDirectory.getAbsolutePath() + File.separator + "activemq.xml");
+
+ try {
+ in = new FileInputStream(source).getChannel();
+ out = new FileOutputStream(dest).getChannel();
+
+ long size = in.size();
+ MappedByteBuffer buf = in.map(FileChannel.MapMode.READ_ONLY, 0, size);
+
+ out.write(buf);
+
+ } finally {
+ if (in != null) in.close();
+ if (out != null) out.close();
+ }
+
+ return dest;
+ }
+}
\ No newline at end of file
Added: incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/ConsumerTool.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/ConsumerTool.java?rev=410534&view=auto
==============================================================================
--- incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/ConsumerTool.java (added)
+++ incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/ConsumerTool.java Wed May 31 07:16:18 2006
@@ -0,0 +1,140 @@
+/**
+ *
+ * Copyright 2005-2006 The Apache Software Foundation
+ *
+ * Licensed 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.tool;
+
+import javax.jms.Connection;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageListener;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.jms.Topic;
+import java.io.IOException;
+
+/**
+ * A simple tool for consuming messages
+ *
+ * @version $Revision$
+ */
+public class ConsumerTool extends ToolSupport implements MessageListener {
+
+ protected int count = 0;
+ protected int dumpCount = 10;
+ protected boolean verbose = true;
+ protected int maxiumMessages = 0;
+ private boolean pauseBeforeShutdown;
+
+
+ public static void main(String[] args) {
+ ConsumerTool tool = new ConsumerTool();
+ if (args.length > 0) {
+ tool.url = args[0];
+ }
+ if (args.length > 1) {
+ tool.topic = args[1].equalsIgnoreCase("true");
+ }
+ if (args.length > 2) {
+ tool.subject = args[2];
+ }
+ if (args.length > 3) {
+ tool.durable = args[3].equalsIgnoreCase("true");
+ }
+ if (args.length > 4) {
+ tool.maxiumMessages = Integer.parseInt(args[4]);
+ }
+ tool.run();
+ }
+
+ public void run() {
+ try {
+ System.out.println("Connecting to URL: " + url);
+ System.out.println("Consuming " + (topic ? "topic" : "queue") + ": " + subject);
+ System.out.println("Using " + (durable ? "durable" : "non-durable") + " subscription");
+
+ Connection connection = createConnection();
+ Session session = createSession(connection);
+ MessageConsumer consumer = null;
+ if (durable && topic) {
+ consumer = session.createDurableSubscriber((Topic) destination, consumerName);
+ }
+ else {
+ consumer = session.createConsumer(destination);
+ }
+ if (maxiumMessages <= 0) {
+ consumer.setMessageListener(this);
+ }
+ connection.start();
+
+ if (maxiumMessages > 0) {
+ consumeMessagesAndClose(connection, session, consumer);
+ }
+ }
+ catch (Exception e) {
+ System.out.println("Caught: " + e);
+ e.printStackTrace();
+ }
+ }
+
+ public void onMessage(Message message) {
+ try {
+ if (message instanceof TextMessage) {
+ TextMessage txtMsg = (TextMessage) message;
+ if (verbose) {
+
+ String msg = txtMsg.getText();
+ if( msg.length() > 50 )
+ msg = msg.substring(0, 50)+"...";
+
+ System.out.println("Received: " + msg);
+ }
+ }
+ else {
+ if (verbose) {
+ System.out.println("Received: " + message);
+ }
+ }
+ /*
+ if (++count % dumpCount == 0) {
+ dumpStats(connection);
+ }
+ */
+ }
+ catch (JMSException e) {
+ System.out.println("Caught: " + e);
+ e.printStackTrace();
+ }
+ }
+
+
+ protected void consumeMessagesAndClose(Connection connection, Session session, MessageConsumer consumer) throws JMSException, IOException {
+ System.out.println("We are about to wait until we consume: " + maxiumMessages + " message(s) then we will shutdown");
+
+ for (int i = 0; i < maxiumMessages; i++) {
+ Message message = consumer.receive();
+ onMessage(message);
+ }
+ System.out.println("Closing connection");
+ consumer.close();
+ session.close();
+ connection.close();
+ if (pauseBeforeShutdown) {
+ System.out.println("Press return to shut down");
+ System.in.read();
+ }
+ }
+}
\ No newline at end of file
Added: incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/ProducerTool.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/ProducerTool.java?rev=410534&view=auto
==============================================================================
--- incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/ProducerTool.java (added)
+++ incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/ProducerTool.java Wed May 31 07:16:18 2006
@@ -0,0 +1,133 @@
+/**
+ *
+ * Copyright 2005-2006 The Apache Software Foundation
+ *
+ * Licensed 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.tool;
+
+import java.util.Date;
+
+import javax.jms.Connection;
+import javax.jms.DeliveryMode;
+import javax.jms.JMSException;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+
+/**
+ * A simple tool for publishing messages
+ *
+ * @version $Revision$
+ */
+public class ProducerTool extends ToolSupport {
+
+ protected int messageCount = 10;
+ protected long sleepTime = 0L;
+ protected boolean verbose = true;
+ protected int messageSize = 255;
+
+ public static void main(String[] args) {
+ runTool(args, new ProducerTool());
+ }
+
+ protected static void runTool(String[] args, ProducerTool tool) {
+ if (args.length > 0) {
+ tool.url = args[0];
+ }
+ if (args.length > 1) {
+ tool.topic = args[1].equalsIgnoreCase("true");
+ }
+ if (args.length > 2) {
+ tool.subject = args[2];
+ }
+ if (args.length > 3) {
+ tool.durable = args[3].equalsIgnoreCase("true");
+ }
+ if (args.length > 4) {
+ tool.messageCount = Integer.parseInt(args[4]);
+ }
+ if (args.length > 5) {
+ tool.messageSize = Integer.parseInt(args[5]);
+ }
+ tool.run();
+ }
+
+ public void run() {
+ try {
+ System.out.println("Connecting to URL: " + url);
+ System.out.println("Publishing a Message with size "+messageSize+" to " + (topic ? "topic" : "queue") + ": " + subject);
+ System.out.println("Using " + (durable ? "durable" : "non-durable") + " publishing");
+
+ Connection connection = createConnection();
+ Session session = createSession(connection);
+ MessageProducer producer = createProducer(session);
+ //connection.start();
+
+ sendLoop(session, producer);
+
+ System.out.println("Done.");
+ close(connection, session);
+ }
+ catch (Exception e) {
+ System.out.println("Caught: " + e);
+ e.printStackTrace();
+ }
+ }
+
+ protected MessageProducer createProducer(Session session) throws JMSException {
+ MessageProducer producer = session.createProducer(destination);
+ if (durable) {
+ producer.setDeliveryMode(DeliveryMode.PERSISTENT);
+ }
+ else {
+ producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+ }
+ return producer;
+ }
+
+ protected void sendLoop(Session session, MessageProducer producer) throws Exception {
+
+ for (int i = 0; i < messageCount; i++) {
+
+
+ TextMessage message = session.createTextMessage(createMessageText(i));
+
+ if (verbose) {
+ String msg = message.getText();
+ if( msg.length() > 50 )
+ msg = msg.substring(0, 50)+"...";
+ System.out.println("Sending message: " + msg);
+ }
+
+ producer.send(message);
+ Thread.sleep(sleepTime);
+ }
+ producer.send(session.createMessage());
+ }
+
+ /**
+ * @param i
+ * @return
+ */
+ private String createMessageText(int index) {
+ StringBuffer buffer = new StringBuffer(messageSize);
+ buffer.append("Message: " + index + " sent at: " + new Date());
+ if( buffer.length() > messageSize ) {
+ return buffer.substring(0, messageSize);
+ }
+ for( int i=buffer.length(); i < messageSize; i++)
+ buffer.append(' ');
+ return buffer.toString();
+ }
+}
\ No newline at end of file
Added: incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/ToolSupport.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/ToolSupport.java?rev=410534&view=auto
==============================================================================
--- incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/ToolSupport.java (added)
+++ incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/ToolSupport.java Wed May 31 07:16:18 2006
@@ -0,0 +1,84 @@
+/**
+ *
+ * Copyright 2005-2006 The Apache Software Foundation
+ *
+ * Licensed 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.tool;
+
+import org.apache.activemq.ActiveMQConnection;
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.activemq.util.IndentPrinter;
+
+import javax.jms.Connection;
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.Session;
+
+/**
+ * Abstract base class useful for implementation inheritence
+ *
+ * @version $Revision$
+ */
+public class ToolSupport {
+
+
+ protected Destination destination;
+ protected String subject = "TOOL.DEFAULT";
+ protected boolean topic = true;
+ protected String user = ActiveMQConnection.DEFAULT_USER;
+ protected String pwd = ActiveMQConnection.DEFAULT_PASSWORD;
+ protected String url = ActiveMQConnection.DEFAULT_BROKER_URL;
+ protected boolean transacted = false;
+ protected boolean durable = false;
+ protected String clientID = getClass().getName();
+ protected int ackMode = Session.AUTO_ACKNOWLEDGE;
+ protected String consumerName = "James";
+
+
+ protected Session createSession(Connection connection) throws Exception {
+ if (durable) {
+ connection.setClientID(clientID);
+ }
+ Session session = connection.createSession(transacted, ackMode);
+ if (topic) {
+ destination = session.createTopic(subject);
+ }
+ else {
+ destination = session.createQueue(subject);
+ }
+ return session;
+ }
+
+ protected Connection createConnection() throws JMSException, Exception {
+ ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(user, pwd, url);
+ return connectionFactory.createConnection();
+ }
+
+ protected void close(Connection connection, Session session) throws JMSException {
+ // lets dump the stats
+ dumpStats(connection);
+
+ if (session != null) {
+ session.close();
+ }
+ if (connection != null) {
+ connection.close();
+ }
+ }
+
+ protected void dumpStats(Connection connection) {
+ ActiveMQConnection c = (ActiveMQConnection) connection;
+ c.getConnectionStats().dump(new IndentPrinter());
+ }
+}
\ No newline at end of file