| 1 | |
package kg.apc.jmeter.functions; |
| 2 | |
|
| 3 | |
import kg.apc.jmeter.modifiers.FifoMap; |
| 4 | |
import org.apache.jmeter.engine.util.CompoundVariable; |
| 5 | |
import org.apache.jmeter.functions.AbstractFunction; |
| 6 | |
import org.apache.jmeter.functions.InvalidVariableException; |
| 7 | |
import org.apache.jmeter.samplers.SampleResult; |
| 8 | |
import org.apache.jmeter.samplers.Sampler; |
| 9 | |
import org.apache.jorphan.logging.LoggingManager; |
| 10 | |
import org.apache.log.Logger; |
| 11 | |
|
| 12 | |
import java.util.Collection; |
| 13 | |
import java.util.LinkedList; |
| 14 | |
import java.util.List; |
| 15 | |
|
| 16 | |
public class FifoPut extends AbstractFunction { |
| 17 | 1 | private static final Logger log = LoggingManager.getLoggerForClass(); |
| 18 | |
|
| 19 | 1 | private static final List<String> desc = new LinkedList<String>(); |
| 20 | |
private static final String KEY = "__fifoPut"; |
| 21 | |
|
| 22 | |
static { |
| 23 | 1 | desc.add("Queue name to put value"); |
| 24 | 1 | desc.add("String value to put into FIFO queue"); |
| 25 | 1 | } |
| 26 | |
|
| 27 | |
private Object[] values; |
| 28 | |
|
| 29 | 4 | public FifoPut() { |
| 30 | 4 | FifoMap.getInstance().clear(); |
| 31 | 4 | } |
| 32 | |
|
| 33 | |
@Override |
| 34 | |
public synchronized String execute(SampleResult previousResult, Sampler currentSampler) |
| 35 | |
throws InvalidVariableException { |
| 36 | 1 | String fifoName = ((CompoundVariable) values[0]).execute(); |
| 37 | 1 | String value = ((CompoundVariable) values[1]).execute(); |
| 38 | |
try { |
| 39 | 1 | FifoMap.getInstance().put(fifoName, value); |
| 40 | 0 | } catch (InterruptedException ex) { |
| 41 | 0 | log.warn("Interrupted put into queue " + fifoName); |
| 42 | 0 | value = "INTERRUPTED"; |
| 43 | 1 | } |
| 44 | |
|
| 45 | 1 | return value; |
| 46 | |
} |
| 47 | |
|
| 48 | |
@Override |
| 49 | |
public synchronized void setParameters(Collection<CompoundVariable> parameters) throws InvalidVariableException { |
| 50 | 2 | checkMinParameterCount(parameters, 2); |
| 51 | 2 | values = parameters.toArray(); |
| 52 | 2 | } |
| 53 | |
|
| 54 | |
@Override |
| 55 | |
public String getReferenceKey() { |
| 56 | 1 | return KEY; |
| 57 | |
} |
| 58 | |
|
| 59 | |
@Override |
| 60 | |
public List<String> getArgumentDesc() { |
| 61 | 1 | return desc; |
| 62 | |
} |
| 63 | |
} |