}
final int iterationCount = getIterationCount();
final Logger log = getLog();
final CountDownLatch startFlag = new CountDownLatch(1);
Thread sendThread =
new Thread()
{
/**
* Main processing method for the JMSPerfStressTestCase object
*/
public void run()
{
try
{
TopicSession session = topicConnection.createTopicSession(transacted != TRANS_NONE, Session.AUTO_ACKNOWLEDGE);
Topic topic = (Topic)context.lookup(TEST_TOPIC);
TopicPublisher publisher = session.createPublisher(topic);
startFlag.await();
BytesMessage message = session.createBytesMessage();
message.writeBytes(PERFORMANCE_TEST_DATA_PAYLOAD);
long startTime = System.currentTimeMillis();
for (int i = 0; i < iterationCount; i++)
{
publisher.publish(message, persistence, 4, 0);
//publisher.publish(topic, message, persistence, 4, 0);
//getLog().debug(" Sent #"+i);
if (transacted == TRANS_INDIVIDUAL)
{
session.commit();
}
}
if (transacted == TRANS_TOTAL)
{
session.commit();
}
long endTime = System.currentTimeMillis();
session.close();
long pTime = endTime - startTime;
log.debug(" sent all messages in " + ((double)pTime / 1000) + " seconds. ");
}
catch (Exception e)
{
log.error("error", e);
}
}
};
final TopicSession session = topicConnection.createTopicSession(transacted != TRANS_NONE, Session.AUTO_ACKNOWLEDGE);
Topic topic = (Topic)context.lookup(TEST_TOPIC);
TopicSubscriber subscriber = session.createSubscriber(topic);
MessageListener listener =
new MessageListener()
{
long startTime = System.currentTimeMillis();
int i = 0;
/**
* #Description of the Method
*
* @param message Description of Parameter
*/
public void onMessage(Message message)
{
try
{
if( transacted == TRANS_INDIVIDUAL )
session.commit();
i++;
}
catch (JMSException e)
{
getLog().error("Unable to commit", e);
synchronized (this)
{
this.notify();
}
}
if (i >= iterationCount)
{
long endTime = System.currentTimeMillis();
long pTime = endTime - startTime;
log.debug(" received all messages in " + ((double)pTime / 1000) + " seconds. ");
synchronized (this)
{
this.notify();
}
}
}
};
getLog().debug(" Asynch Topic: This test will send " + getIterationCount() + " "
+ (persistence == DeliveryMode.PERSISTENT ? "persistent" : "non-persistent") + " messages. Each with a payload of "
+ ((double)PERFORMANCE_TEST_DATA_PAYLOAD.length / 1024) + "Kb"
+ " Session is " + TRANS_DESC[transacted] + " transacted");
long startTime = System.currentTimeMillis();
sendThread.start();
subscriber.setMessageListener(listener);
startFlag.countDown();
synchronized (listener)
{
topicConnection.start();
listener.wait();
}