1 18 19 package org.apache.jmeter.samplers; 20 21 import java.io.Serializable ; 22 import java.rmi.RemoteException ; 23 24 import org.apache.jmeter.engine.event.LoopIterationEvent; 25 import org.apache.jmeter.engine.util.NoThreadClone; 26 import org.apache.jmeter.testelement.AbstractTestElement; 27 import org.apache.jmeter.testelement.TestListener; 28 import org.apache.jorphan.logging.LoggingManager; 29 import org.apache.log.Logger; 30 import org.apache.jmeter.util.JMeterUtils; 31 import java.util.ArrayList ; 32 import java.util.List ; 33 import java.util.Iterator ; 34 35 43 public class RemoteListenerWrapper 44 extends AbstractTestElement 45 implements SampleListener, TestListener, Serializable , NoThreadClone 46 { 47 transient private static Logger log = LoggingManager.getLoggerForClass(); 48 private RemoteSampleListener listener = null; 49 50 private boolean holdSamples; private List sampleStore; 53 private void setUpStore(){ 54 holdSamples = JMeterUtils.getPropDefault("hold_samples",false); 55 if (holdSamples){ 56 sampleStore = new ArrayList (); 57 log.info("Using Sample store for this test run"); 58 } 59 } 60 61 public RemoteListenerWrapper(RemoteSampleListener l) 62 { 63 listener = l; 64 } 65 66 67 public RemoteListenerWrapper() { 69 } 70 71 public void testStarted() 72 { 73 log.info("Test Started()"); 74 setUpStore(); 75 try 76 { 77 listener.testStarted(); 78 } 79 catch (Throwable ex) 80 { 81 log.warn("testStarted()", ex); 82 } 83 84 } 85 public void testEnded() 86 { 87 log.info("Test ended()"); 88 try 89 { 90 if (holdSamples){ 91 synchronized(sampleStore){ 92 Iterator i = sampleStore.iterator(); 93 while (i.hasNext()) { 94 SampleEvent se = (SampleEvent) i.next(); 95 listener.sampleOccurred(se); 96 } 97 } 98 } 99 listener.testEnded(); 100 sampleStore = null; 101 } 102 catch (Throwable ex) 103 { 104 log.warn("testEnded()", ex); 105 } 106 } 107 public void testStarted(String host) 108 { 109 log.info("Test Started on "+host); setUpStore(); 111 try 112 { 113 listener.testStarted(host); 114 } 115 catch (Throwable ex) 116 { 117 log.error("testStarted(host)", ex); 118 } 119 } 120 public void testEnded(String host) 121 { 122 log.info("Test Ended on " + host); try 124 { 125 if (holdSamples){ 126 Iterator i = sampleStore.iterator(); 127 while (i.hasNext()) { 128 SampleEvent se = (SampleEvent) i.next(); 129 listener.sampleOccurred(se); 130 } 131 } 132 listener.testEnded(host); 133 sampleStore = null; 134 } 135 catch (Throwable ex) 136 { 137 log.error("testEnded(host)", ex); 138 } 139 } 140 141 public void sampleOccurred(SampleEvent e) 142 { 143 log.debug("Sample occurred"); 144 try 145 { 146 if (holdSamples) { 147 synchronized(sampleStore) 148 { 149 sampleStore.add(e); 150 } 151 } else { 152 listener.sampleOccurred(e); 153 } 154 } 155 catch (RemoteException err) 156 { 157 log.error("sampleOccurred", err); 158 } 159 } 160 161 169 public void sampleStarted(SampleEvent e) 170 { 171 log.debug("Sample started"); 172 try 173 { 174 listener.sampleStarted(e); 175 } 176 catch (RemoteException err) 177 { 178 log.error("sampleStarted", err); 179 } 180 } 181 public void sampleStopped(SampleEvent e) 182 { 183 log.debug("Sample stopped"); 184 try 185 { 186 listener.sampleStopped(e); 187 } 188 catch (RemoteException err) 189 { 190 log.error("sampleStopped", err); 191 } 192 } 193 196 public void testIterationStart(LoopIterationEvent event) 197 { 198 } 199 200 } | Popular Tags |