- Added a getClientID to retrieve the connectionID of a client

- Added a getSettings to PerfMeasurable client and remove unnecessary getters.
- Added a PerfMeasurable parameter to the listeners.

git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@411019 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Adrian T. Co 2006-06-02 02:27:12 +00:00
parent a37fa0d6f3
commit 29eef80774
6 changed files with 76 additions and 76 deletions

View File

@ -32,6 +32,7 @@ public class JmsConfigurableClientSupport extends JmsBasicClientSupport {
private String serverType = ""; private String serverType = "";
private String factoryClass = ""; private String factoryClass = "";
private String clientID = "";
private Map factorySettings = new HashMap(); private Map factorySettings = new HashMap();
private Map connectionSettings = new HashMap(); private Map connectionSettings = new HashMap();
@ -154,6 +155,14 @@ public class JmsConfigurableClientSupport extends JmsBasicClientSupport {
return jmsMessageConsumer; return jmsMessageConsumer;
} }
public String getClientID() {
try {
return getConnection().getClientID();
} catch (Exception e) {
return "";
}
}
public TopicSubscriber createDurableSubscriber(Topic dest, String name, String selector, boolean noLocal) throws JMSException { public TopicSubscriber createDurableSubscriber(Topic dest, String name, String selector, boolean noLocal) throws JMSException {
jmsMessageConsumer = getSession().createDurableSubscriber(dest, name, selector, noLocal); jmsMessageConsumer = getSession().createDurableSubscriber(dest, name, selector, noLocal);
configureJmsObject(jmsMessageConsumer, consumerSettings); configureJmsObject(jmsMessageConsumer, consumerSettings);
@ -192,14 +201,14 @@ public class JmsConfigurableClientSupport extends JmsBasicClientSupport {
public void addConfigParam(String key, Object value) { public void addConfigParam(String key, Object value) {
// Simple mapping of JMS Server to connection factory class // Simple mapping of JMS Server to connection factory class
if (key.equalsIgnoreCase("server")) { if (key.equalsIgnoreCase("client.server")) {
serverType = value.toString(); serverType = value.toString();
if (serverType.equalsIgnoreCase(AMQ_SERVER)) { if (serverType.equalsIgnoreCase(AMQ_SERVER)) {
factoryClass = AMQ_CONNECTION_FACTORY_CLASS; factoryClass = AMQ_CONNECTION_FACTORY_CLASS;
} }
// Manually specify the connection factory class to use // Manually specify the connection factory class to use
} else if (key.equalsIgnoreCase("factoryClass")) { } else if (key.equalsIgnoreCase("client.factoryClass")) {
factoryClass = value.toString(); factoryClass = value.toString();
// Connection factory specific settings // Connection factory specific settings

View File

@ -16,13 +16,12 @@
*/ */
package org.apache.activemq.tool; package org.apache.activemq.tool;
import java.util.Map;
import java.util.HashMap;
public class JmsPerfClientSupport extends JmsConfigurableClientSupport implements PerfMeasurable { public class JmsPerfClientSupport extends JmsConfigurableClientSupport implements PerfMeasurable {
protected long throughput = 0; protected long throughput = 0;
protected long interval = 1000; // 1 sec
protected long duration = 1000 * 60 * 10; // 10 min
protected long rampUpTime = 1000 * 60 * 1; // 1 min
protected long rampDownTime = 1000 * 60 * 1; // 1 min
protected PerfEventListener listener = null; protected PerfEventListener listener = null;
@ -46,38 +45,6 @@ public class JmsPerfClientSupport extends JmsConfigurableClientSupport implement
throughput += val; throughput += val;
} }
public long getInterval() {
return interval;
}
public void setInterval(long val) {
this.interval = val;
}
public long getDuration() {
return duration;
}
public void setDuration(long val) {
this.duration = val;
}
public long getRampUpTime() {
return rampUpTime;
}
public void setRampUpTime(long val) {
this.rampUpTime = val;
}
public long getRampDownTime() {
return rampDownTime;
}
public void setRampDownTime(long val) {
this.rampDownTime = val;
}
public void setPerfEventListener(PerfEventListener listener) { public void setPerfEventListener(PerfEventListener listener) {
this.listener = listener; this.listener = listener;
} }
@ -85,4 +52,21 @@ public class JmsPerfClientSupport extends JmsConfigurableClientSupport implement
public PerfEventListener getPerfEventListener() { public PerfEventListener getPerfEventListener() {
return listener; return listener;
} }
public Map getClientSettings() {
Map settings = new HashMap();
settings.put("client.server", getServerType());
settings.put("client.factoryClass", getFactoryClass());
settings.put("client.clientID", getClientID());
settings.putAll(getFactorySettings());
settings.putAll(getConnectionSettings());
settings.putAll(getSessionSettings());
settings.putAll(getQueueSettings());
settings.putAll(getTopicSettings());
settings.putAll(getProducerSettings());
settings.putAll(getConsumerSettings());
settings.putAll(getMessageSettings());
return settings;
}
} }

View File

@ -80,7 +80,7 @@ public class JmsProducerClient extends JmsPerfClientSupport {
public void createProducer(int messageSize) throws JMSException { public void createProducer(int messageSize) throws JMSException {
listener.onConfigStart(); listener.onConfigStart(this);
// Create connection factory // Create connection factory
if (factory != null) { if (factory != null) {
@ -120,7 +120,7 @@ public class JmsProducerClient extends JmsPerfClientSupport {
message = createTextMessage(buff); message = createTextMessage(buff);
} }
listener.onConfigEnd(); listener.onConfigEnd(this);
} }
public void sendCountBasedMessages(long messageCount) throws JMSException { public void sendCountBasedMessages(long messageCount) throws JMSException {
@ -132,20 +132,22 @@ public class JmsProducerClient extends JmsPerfClientSupport {
if (message != null) { if (message != null) {
// Send to more than one actual destination // Send to more than one actual destination
if (dest.length > 1) { if (dest.length > 1) {
listener.onPublishStart(); listener.onPublishStart(this);
for (int i=0; i<messageCount; i++) { for (int i=0; i<messageCount; i++) {
for (int j=0; j<dest.length; j++) { for (int j=0; j<dest.length; j++) {
getMessageProducer().send(dest[j], message); getMessageProducer().send(dest[j], message);
incThroughput();
} }
} }
listener.onPublishEnd(); listener.onPublishEnd(this);
// Send to only one actual destination // Send to only one actual destination
} else { } else {
listener.onPublishStart(); listener.onPublishStart(this);
for (int i=0; i<messageCount; i++) { for (int i=0; i<messageCount; i++) {
getMessageProducer().send(message); getMessageProducer().send(message);
incThroughput();
} }
listener.onPublishEnd(); listener.onPublishEnd(this);
} }
// Send different type of messages using indexing to identify each one. // Send different type of messages using indexing to identify each one.
@ -154,21 +156,23 @@ public class JmsProducerClient extends JmsPerfClientSupport {
} else { } else {
// Send to more than one actual destination // Send to more than one actual destination
if (dest.length > 1) { if (dest.length > 1) {
listener.onPublishStart(); listener.onPublishStart(this);
for (int i=0; i<messageCount; i++) { for (int i=0; i<messageCount; i++) {
for (int j=0; j<dest.length; j++) { for (int j=0; j<dest.length; j++) {
getMessageProducer().send(dest[j], createTextMessage("Text Message [" + i + "]")); getMessageProducer().send(dest[j], createTextMessage("Text Message [" + i + "]"));
incThroughput();
} }
} }
listener.onPublishEnd(); listener.onPublishEnd(this);
// Send to only one actual destination // Send to only one actual destination
} else { } else {
listener.onPublishStart(); listener.onPublishStart(this);
for (int i=0; i<messageCount; i++) { for (int i=0; i<messageCount; i++) {
getMessageProducer().send(createTextMessage("Text Message [" + i + "]")); getMessageProducer().send(createTextMessage("Text Message [" + i + "]"));
incThroughput();
} }
listener.onPublishEnd(); listener.onPublishEnd(this);
} }
} }
} finally { } finally {
@ -188,20 +192,22 @@ public class JmsProducerClient extends JmsPerfClientSupport {
if (message != null) { if (message != null) {
// Send to more than one actual destination // Send to more than one actual destination
if (dest.length > 1) { if (dest.length > 1) {
listener.onPublishStart(); listener.onPublishStart(this);
while (System.currentTimeMillis() < endTime) { while (System.currentTimeMillis() < endTime) {
for (int j=0; j<dest.length; j++) { for (int j=0; j<dest.length; j++) {
getMessageProducer().send(dest[j], message); getMessageProducer().send(dest[j], message);
incThroughput();
} }
} }
listener.onPublishEnd(); listener.onPublishEnd(this);
// Send to only one actual destination // Send to only one actual destination
} else { } else {
listener.onPublishStart(); listener.onPublishStart(this);
while (System.currentTimeMillis() < endTime) { while (System.currentTimeMillis() < endTime) {
getMessageProducer().send(message); getMessageProducer().send(message);
incThroughput();
} }
listener.onPublishEnd(); listener.onPublishEnd(this);
} }
// Send different type of messages using indexing to identify each one. // Send different type of messages using indexing to identify each one.
@ -211,21 +217,23 @@ public class JmsProducerClient extends JmsPerfClientSupport {
// Send to more than one actual destination // Send to more than one actual destination
long count = 1; long count = 1;
if (dest.length > 1) { if (dest.length > 1) {
listener.onPublishStart(); listener.onPublishStart(this);
while (System.currentTimeMillis() < endTime) { while (System.currentTimeMillis() < endTime) {
for (int j=0; j<dest.length; j++) { for (int j=0; j<dest.length; j++) {
getMessageProducer().send(dest[j], createTextMessage("Text Message [" + count++ + "]")); getMessageProducer().send(dest[j], createTextMessage("Text Message [" + count++ + "]"));
incThroughput();
} }
} }
listener.onPublishEnd(); listener.onPublishEnd(this);
// Send to only one actual destination // Send to only one actual destination
} else { } else {
listener.onPublishStart(); listener.onPublishStart(this);
while (System.currentTimeMillis() < endTime) { while (System.currentTimeMillis() < endTime) {
getMessageProducer().send(createTextMessage("Text Message [" + count++ + "]")); getMessageProducer().send(createTextMessage("Text Message [" + count++ + "]"));
incThroughput();
} }
listener.onPublishEnd(); listener.onPublishEnd(this);
} }
} }
} finally { } finally {

View File

@ -19,27 +19,27 @@ package org.apache.activemq.tool;
import javax.jms.JMSException; import javax.jms.JMSException;
public class PerfEventAdapter implements PerfEventListener { public class PerfEventAdapter implements PerfEventListener {
public void onConfigStart() { public void onConfigStart(PerfMeasurable client) {
} }
public void onConfigEnd() { public void onConfigEnd(PerfMeasurable client) {
} }
public void onPublishStart() { public void onPublishStart(PerfMeasurable client) {
} }
public void onPublishEnd() { public void onPublishEnd(PerfMeasurable client) {
} }
public void onConsumeStart() { public void onConsumeStart(PerfMeasurable client) {
} }
public void onConsumeEnd() { public void onConsumeEnd(PerfMeasurable client) {
} }
public void onJMSException(JMSException e) { public void onJMSException(PerfMeasurable client, JMSException e) {
} }
public void onException(Exception e) { public void onException(PerfMeasurable client, Exception e) {
} }
} }

View File

@ -19,12 +19,12 @@ package org.apache.activemq.tool;
import javax.jms.JMSException; import javax.jms.JMSException;
public interface PerfEventListener { public interface PerfEventListener {
public void onConfigStart(); public void onConfigStart(PerfMeasurable client);
public void onConfigEnd(); public void onConfigEnd(PerfMeasurable client);
public void onPublishStart(); public void onPublishStart(PerfMeasurable client);
public void onPublishEnd(); public void onPublishEnd(PerfMeasurable client);
public void onConsumeStart(); public void onConsumeStart(PerfMeasurable client);
public void onConsumeEnd(); public void onConsumeEnd(PerfMeasurable client);
public void onJMSException(JMSException e); public void onJMSException(PerfMeasurable client, JMSException e);
public void onException(Exception e); public void onException(PerfMeasurable client, Exception e);
} }

View File

@ -16,13 +16,12 @@
*/ */
package org.apache.activemq.tool; package org.apache.activemq.tool;
import java.util.Map;
public interface PerfMeasurable { public interface PerfMeasurable {
public void reset(); public void reset();
public long getThroughput(); public long getThroughput();
public long getInterval(); public Map getClientSettings();
public long getDuration();
public long getRampUpTime();
public long getRampDownTime();
public void setPerfEventListener(PerfEventListener listener); public void setPerfEventListener(PerfEventListener listener);
public PerfEventListener getPerfEventListener(); public PerfEventListener getPerfEventListener();
} }