Source Code Cross Referenced for JavaSamplerContext.java in  » Testing » jakarta-jmeter » org » apache » jmeter » protocol » java » sampler » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Testing » jakarta jmeter » org.apache.jmeter.protocol.java.sampler 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         *
009:         *   http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         * 
017:         */
018:
019:        package org.apache.jmeter.protocol.java.sampler;
020:
021:        import java.util.Iterator;
022:        import java.util.Map;
023:
024:        import org.apache.jmeter.config.Arguments;
025:        import org.apache.jorphan.logging.LoggingManager;
026:        import org.apache.log.Logger;
027:
028:        /**
029:         * JavaSamplerContext is used to provide context information to a
030:         * JavaSamplerClient implementation. This currently consists of the
031:         * initialization parameters which were specified in the GUI. Additional data
032:         * may be accessible through JavaSamplerContext in the future.
033:         * 
034:         * @author <a href="mailto:jeremy_a@bigfoot.com">Jeremy Arnold</a>
035:         * @version $Revision: 493789 $
036:         */
037:        public class JavaSamplerContext {
038:            /*
039:             * Implementation notes:
040:             * 
041:             * All of the methods in this class are currently read-only. If update
042:             * methods are included in the future, they should be defined so that a
043:             * single instance of JavaSamplerContext can be associated with each thread.
044:             * Therefore, no synchronization should be needed. The same instance should
045:             * be used for the call to setupTest, all calls to runTest, and the call to
046:             * teardownTest.
047:             */
048:
049:            /** Logging */
050:            private static transient Logger log = LoggingManager
051:                    .getLoggerForClass();
052:
053:            /**
054:             * Map containing the initialization parameters for the JavaSamplerClient.
055:             */
056:            private Map params = null;
057:
058:            /**
059:             * Create a new JavaSampler with the specified initialization parameters.
060:             * 
061:             * @param args
062:             *            the initialization parameters.
063:             */
064:            public JavaSamplerContext(Arguments args) {
065:                this .params = args.getArgumentsAsMap();
066:            }
067:
068:            /**
069:             * Determine whether or not a value has been specified for the parameter
070:             * with this name.
071:             * 
072:             * @param name
073:             *            the name of the parameter to test
074:             * @return true if the parameter value has been specified, false otherwise.
075:             */
076:            public boolean containsParameter(String name) {
077:                return params.containsKey(name);
078:            }
079:
080:            /**
081:             * Get an iterator of the parameter names. Each entry in the Iterator is a
082:             * String.
083:             * 
084:             * @return an Iterator of Strings listing the names of the parameters which
085:             *         have been specified for this test.
086:             */
087:            public Iterator getParameterNamesIterator() {
088:                return params.keySet().iterator();
089:            }
090:
091:            /**
092:             * Get the value of a specific parameter as a String, or null if the value
093:             * was not specified.
094:             * 
095:             * @param name
096:             *            the name of the parameter whose value should be retrieved
097:             * @return the value of the parameter, or null if the value was not
098:             *         specified
099:             */
100:            public String getParameter(String name) {
101:                return getParameter(name, null);
102:            }
103:
104:            /**
105:             * Get the value of a specified parameter as a String, or return the
106:             * specified default value if the value was not specified.
107:             * 
108:             * @param name
109:             *            the name of the parameter whose value should be retrieved
110:             * @param defaultValue
111:             *            the default value to return if the value of this parameter was
112:             *            not specified
113:             * @return the value of the parameter, or the default value if the parameter
114:             *         was not specified
115:             */
116:            public String getParameter(String name, String defaultValue) {
117:                if (params == null || !params.containsKey(name)) {
118:                    return defaultValue;
119:                }
120:                return (String) params.get(name);
121:            }
122:
123:            /**
124:             * Get the value of a specified parameter as an integer. An exception will
125:             * be thrown if the parameter is not specified or if it is not an integer.
126:             * The value may be specified in decimal, hexadecimal, or octal, as defined
127:             * by Integer.decode().
128:             * 
129:             * @param name
130:             *            the name of the parameter whose value should be retrieved
131:             * @return the value of the parameter
132:             * 
133:             * @throws NumberFormatException
134:             *             if the parameter is not specified or is not an integer
135:             * 
136:             * @see java.lang.Integer#decode(java.lang.String)
137:             */
138:            public int getIntParameter(String name)
139:                    throws NumberFormatException {
140:                if (params == null || !params.containsKey(name)) {
141:                    throw new NumberFormatException(
142:                            "No value for parameter named '" + name + "'.");
143:                }
144:
145:                return Integer.decode((String) params.get(name)).intValue();
146:            }
147:
148:            /**
149:             * Get the value of a specified parameter as an integer, or return the
150:             * specified default value if the value was not specified or is not an
151:             * integer. A warning will be logged if the value is not an integer. The
152:             * value may be specified in decimal, hexadecimal, or octal, as defined by
153:             * Integer.decode().
154:             * 
155:             * @param name
156:             *            the name of the parameter whose value should be retrieved
157:             * @param defaultValue
158:             *            the default value to return if the value of this parameter was
159:             *            not specified
160:             * @return the value of the parameter, or the default value if the parameter
161:             *         was not specified
162:             * 
163:             * @see java.lang.Integer#decode(java.lang.String)
164:             */
165:            public int getIntParameter(String name, int defaultValue) {
166:                if (params == null || !params.containsKey(name)) {
167:                    return defaultValue;
168:                }
169:
170:                try {
171:                    return Integer.decode((String) params.get(name)).intValue();
172:                } catch (NumberFormatException e) {
173:                    log.warn("Value for parameter '" + name
174:                            + "' not an integer: '" + params.get(name)
175:                            + "'.  Using default: '" + defaultValue + "'.", e);
176:                    return defaultValue;
177:                }
178:            }
179:
180:            /**
181:             * Get the value of a specified parameter as a long. An exception will be
182:             * thrown if the parameter is not specified or if it is not a long. The
183:             * value may be specified in decimal, hexadecimal, or octal, as defined by
184:             * Long.decode().
185:             * 
186:             * @param name
187:             *            the name of the parameter whose value should be retrieved
188:             * @return the value of the parameter
189:             * 
190:             * @throws NumberFormatException
191:             *             if the parameter is not specified or is not a long
192:             * 
193:             * @see Long#decode(String)
194:             */
195:            public long getLongParameter(String name)
196:                    throws NumberFormatException {
197:                if (params == null || !params.containsKey(name)) {
198:                    throw new NumberFormatException(
199:                            "No value for parameter named '" + name + "'.");
200:                }
201:
202:                return Long.decode((String) params.get(name)).longValue();
203:            }
204:
205:            /**
206:             * Get the value of a specified parameter as along, or return the specified
207:             * default value if the value was not specified or is not a long. A warning
208:             * will be logged if the value is not a long. The value may be specified in
209:             * decimal, hexadecimal, or octal, as defined by Long.decode().
210:             * 
211:             * @param name
212:             *            the name of the parameter whose value should be retrieved
213:             * @param defaultValue
214:             *            the default value to return if the value of this parameter was
215:             *            not specified
216:             * @return the value of the parameter, or the default value if the parameter
217:             *         was not specified
218:             * 
219:             * @see Long#decode(String)
220:             */
221:            public long getLongParameter(String name, long defaultValue) {
222:                if (params == null || !params.containsKey(name)) {
223:                    return defaultValue;
224:                }
225:                try {
226:                    return Long.decode((String) params.get(name)).longValue();
227:                } catch (NumberFormatException e) {
228:                    log.warn("Value for parameter '" + name + "' not a long: '"
229:                            + params.get(name) + "'.  Using default: '"
230:                            + defaultValue + "'.", e);
231:                    return defaultValue;
232:                }
233:            }
234:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.