package org.apache.jmeter.protocol.java.sampler;
import java.util.Iterator;
import java.util.Map;
import org.apache.jmeter.config.Arguments;
import org.apache.jmeter.protocol.java.test.JavaTest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class JavaSamplerContext {
private static final Logger log = LoggerFactory.getLogger(JavaTest.class);
private final Map<String, String> params;
public JavaSamplerContext(Arguments args) {
this.params = args.getArgumentsAsMap();
}
public boolean containsParameter(String name) {
return this.params.containsKey(name);
}
public Iterator<String> getParameterNamesIterator() {
return this.params.keySet().iterator();
}
public String getParameter(String name) {
return this.getParameter(name, (String)null);
}
public String getParameter(String name, String defaultValue) {
return this.params != null && this.params.containsKey(name) ? (String)this.params.get(name) : defaultValue;
}
public int getIntParameter(String name) throws NumberFormatException {
if (this.params != null && this.params.containsKey(name)) {
return Integer.decode((String)this.params.get(name));
} else {
throw new NumberFormatException("No value for parameter named '" + name + "'.");
}
}
public int getIntParameter(String name, int defaultValue) {
if (this.params != null && this.params.containsKey(name)) {
try {
return Integer.decode((String)this.params.get(name));
} catch (NumberFormatException var4) {
log.warn("Value for parameter '" + name + "' not an integer: '" + (String)this.params.get(name) + "'. Using default: '" + defaultValue + "'.", var4);
return defaultValue;
}
} else {
return defaultValue;
}
}
public long getLongParameter(String name) throws NumberFormatException {
if (this.params != null && this.params.containsKey(name)) {
return Long.decode((String)this.params.get(name));
} else {
throw new NumberFormatException("No value for parameter named '" + name + "'.");
}
}
public long getLongParameter(String name, long defaultValue) {
if (this.params != null && this.params.containsKey(name)) {
try {
return Long.decode((String)this.params.get(name));
} catch (NumberFormatException var5) {
log.warn("Value for parameter '" + name + "' not a long: '" + (String)this.params.get(name) + "'. Using default: '" + defaultValue + "'.", var5);
return defaultValue;
}
} else {
return defaultValue;
}
}
}
【代码块】AbstractJavaSamplerClient类源码
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...