美文网首页
【代码块】AbstractJavaSamplerClient类源

【代码块】AbstractJavaSamplerClient类源

作者: 悠哉的小C | 来源:发表于2020-01-18 22:32 被阅读0次
    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类源

          本文链接:https://www.haomeiwen.com/subject/ksylzctx.html