1 18 19 package org.apache.jmeter.control; 20 21 import java.io.Serializable ; 22 23 import org.apache.jmeter.samplers.SampleEvent; 24 import org.apache.jmeter.samplers.SampleResult; 25 import org.apache.jmeter.samplers.Sampler; 26 import org.apache.jmeter.threads.JMeterContext; 27 import org.apache.jmeter.threads.JMeterThread; 28 import org.apache.jmeter.threads.JMeterVariables; 29 import org.apache.jmeter.threads.ListenerNotifier; 30 import org.apache.jmeter.threads.SamplePackage; 31 import org.apache.jorphan.logging.LoggingManager; 32 import org.apache.log.Logger; 33 34 39 public class TransactionController 40 extends GenericController 41 implements Controller, Serializable 42 { 43 protected static final Logger log = LoggingManager.getLoggerForClass(); 44 45 transient private String threadName; 46 transient private ListenerNotifier lnf; 47 transient private JMeterContext threadContext; 48 transient private JMeterVariables threadVars; 49 transient private SampleResult res; 50 51 54 public TransactionController() 55 { 56 threadName = Thread.currentThread().getName(); 57 lnf = new ListenerNotifier(); 58 } 59 60 private void log_debug(String s) 61 { 62 String n = this.getName(); 63 log.debug(threadName + " " + n + " "+ s); 64 } 65 66 private int calls; 67 70 public Sampler next() 71 { 72 Sampler returnValue = null; 73 if (isFirst()) { 75 log_debug("+++++++++++++++++++++++++++++"); 76 calls = 0; 77 res = new SampleResult(); 78 res.sampleStart(); 79 } 80 81 calls++; 82 83 returnValue = super.next(); 84 85 if (returnValue == null) { 87 log_debug("-----------------------------"+calls); 88 if (res == null){ 89 log_debug("already called"); 90 } else { 91 res.sampleEnd(); 92 res.setSuccessful(true); 93 res.setSampleLabel(getName()); 94 res.setResponseCode("200"); 95 res.setResponseMessage("Called: "+calls); 96 res.setThreadName(threadName); 97 98 threadContext = getThreadContext(); 100 threadVars = threadContext.getVariables(); 101 102 SamplePackage pack = (SamplePackage) 103 threadVars.getObject(JMeterThread.PACKAGE_OBJECT); 104 if (pack == null) 105 { 106 log.warn("Could not fetch SamplePackage"); 107 } 108 else 109 { 110 lnf.notifyListeners(new SampleEvent(res,getName()),pack.getSampleListeners()); 111 } 112 res=null; 113 } 114 } 115 116 return returnValue; 117 } 118 } 119 | Popular Tags |