Index: SubscriberSampler.java =================================================================== --- SubscriberSampler.java (revision 825637) +++ SubscriberSampler.java (working copy) @@ -22,6 +22,7 @@ import javax.jms.MessageListener; import javax.jms.TextMessage; +import org.apache.jmeter.samplers.Interruptible; import org.apache.jmeter.samplers.SampleResult; import org.apache.jmeter.testelement.TestListener; import org.apache.jmeter.util.JMeterUtils; @@ -38,7 +39,7 @@ /** * This class implements the JMS Subcriber sampler */ -public class SubscriberSampler extends BaseJMSSampler implements TestListener, MessageListener { +public class SubscriberSampler extends BaseJMSSampler implements Interruptible, TestListener, MessageListener { private static final long serialVersionUID = 233L; @@ -52,6 +53,9 @@ //@GuardedBy("this") private transient int counter = 0; + + //@GuardedBy("this") + private boolean interrupted = false; // Don't change the string, as it is used in JMX files private static final String CLIENT_CHOICE = "jms.client_choice"; // $NON-NLS-1$ @@ -93,6 +97,7 @@ * */ private OnMessageSubscriber initListenerClient() { + interrupted = false; OnMessageSubscriber sub = (OnMessageSubscriber) ClientPool.get(this); if (sub == null) { sub = new OnMessageSubscriber(this.getUseJNDIPropertiesAsBoolean(), this.getJNDIInitialContextFactory(), @@ -112,6 +117,7 @@ * Create the ReceiveSubscriber client for the sampler. */ private void initReceiveClient() { + interrupted = false; this.SUBSCRIBER = new ReceiveSubscriber(this.getUseJNDIPropertiesAsBoolean(), this .getJNDIInitialContextFactory(), this.getProviderUrl(), this.getConnectionFactory(), this.getTopic(), this.isUseAuth(), this.getUsername(), this.getPassword()); @@ -148,7 +154,7 @@ int loop = this.getIterationCount(); result.sampleStart(); - while (this.count(0) < loop) { + while (this.count(0) < loop && interrupted == false) { try { Thread.sleep(0, 50); } catch (InterruptedException e) { @@ -190,7 +196,7 @@ this.SUBSCRIBER.setLoop(loop); result.sampleStart(); - while (this.SUBSCRIBER.count(0) < loop) { + while (this.SUBSCRIBER.count(0) < loop && interrupted == false) { try { Thread.sleep(0, 50); } catch (InterruptedException e) { @@ -276,6 +282,18 @@ } return choice; } + + /** + * Handle an interrupt of the test. + */ + public boolean interrupt() { + interrupted = true; // so we break the loops in SampleWithListener and SampleWithReceive + log.debug("SubscribertSampler.interrupt called"); + ClientPool.clearClient(); + this.SUBSCRIBER = null; + this.resetCount(); + return true; + } // This was the old value that was checked for private final static String RECEIVE_STR = JMeterUtils.getResString(JMSSubscriberGui.RECEIVE_RSC); // $NON-NLS-1$ }