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: package org.apache.jmeter.protocol.jms.sampler;
019:
020: import org.apache.jmeter.testelement.TestListener;
021: import org.apache.jmeter.engine.event.LoopIterationEvent;
022: import org.apache.jmeter.samplers.AbstractSampler;
023: import org.apache.jmeter.samplers.Entry;
024: import org.apache.jmeter.samplers.SampleResult;
025: import org.apache.jmeter.util.JMeterUtils;
026:
027: /**
028: * @author pete
029: *
030: * BaseJMSSampler is an abstract class which provides implementation for common
031: * properties. Rather than duplicate the code, it's contained in the base class.
032: */
033: public abstract class BaseJMSSampler extends AbstractSampler implements
034: TestListener {
035:
036: //++ These are JMX file names and must not be changed
037: private static final String JNDI_INITIAL_CONTEXT_FAC = "jms.initial_context_factory"; // $NON-NLS-1$
038:
039: private static final String PROVIDER_URL = "jms.provider_url"; // $NON-NLS-1$
040:
041: private static final String CONN_FACTORY = "jms.connection_factory"; // $NON-NLS-1$
042:
043: private static final String TOPIC = "jms.topic"; // $NON-NLS-1$
044:
045: private static final String PRINCIPAL = "jms.security_principle"; // $NON-NLS-1$
046:
047: private static final String CREDENTIALS = "jms.security_credentials"; // $NON-NLS-1$
048:
049: private static final String ITERATIONS = "jms.iterations"; // $NON-NLS-1$
050:
051: private static final String USE_AUTH = "jms.authenticate"; // $NON-NLS-1$
052:
053: private static final String USE_PROPERTIES_FILE = "jms.jndi_properties"; // $NON-NLS-1$
054:
055: private static final String READ_RESPONSE = "jms.read_response"; // $NON-NLS-1$
056: //--
057:
058: public static final String required = JMeterUtils
059: .getResString("jms_auth_required"); // $NON-NLS-1$
060:
061: public static final String not_req = JMeterUtils
062: .getResString("jms_auth_not_required"); // $NON-NLS-1$
063:
064: public BaseJMSSampler() {
065: }
066:
067: public abstract void testEnded(String host);
068:
069: public abstract void testStarted(String host);
070:
071: public abstract void testEnded();
072:
073: public abstract void testStarted();
074:
075: public abstract void testIterationStart(LoopIterationEvent event);
076:
077: /*
078: * (non-Javadoc)
079: *
080: * @see org.apache.jmeter.samplers.Sampler#sample(org.apache.jmeter.samplers.Entry)
081: */
082: public SampleResult sample(Entry e) {
083: return new SampleResult();
084: }
085:
086: // ------------- get/set properties ----------------------//
087: /**
088: * set the initial context factory
089: *
090: * @param icf
091: */
092: public void setJNDIIntialContextFactory(String icf) {
093: setProperty(JNDI_INITIAL_CONTEXT_FAC, icf);
094: }
095:
096: /**
097: * method returns the initial context factory for jndi initial context
098: * lookup.
099: *
100: * @return the initial context factory
101: */
102: public String getJNDIInitialContextFactory() {
103: return getPropertyAsString(JNDI_INITIAL_CONTEXT_FAC);
104: }
105:
106: /**
107: * set the provider user for jndi
108: *
109: * @param url the provider URL
110: */
111: public void setProviderUrl(String url) {
112: setProperty(PROVIDER_URL, url);
113: }
114:
115: /**
116: * method returns the provider url for jndi to connect to
117: *
118: * @return the provider URL
119: */
120: public String getProviderUrl() {
121: return getPropertyAsString(PROVIDER_URL);
122: }
123:
124: /**
125: * set the connection factory for
126: *
127: * @param factory
128: */
129: public void setConnectionFactory(String factory) {
130: setProperty(CONN_FACTORY, factory);
131: }
132:
133: /**
134: * return the connection factory parameter used to lookup the connection
135: * factory from the JMS server
136: *
137: * @return the connection factory
138: */
139: public String getConnectionFactory() {
140: return getPropertyAsString(CONN_FACTORY);
141: }
142:
143: /**
144: * set the topic
145: *
146: * @param topic
147: */
148: public void setTopic(String topic) {
149: setProperty(TOPIC, topic);
150: }
151:
152: /**
153: * return the topic used for the benchmark
154: *
155: * @return the topic
156: */
157: public String getTopic() {
158: return getPropertyAsString(TOPIC);
159: }
160:
161: /**
162: * set the username to login into the jms server if needed
163: *
164: * @param user
165: */
166: public void setUsername(String user) {
167: setProperty(PRINCIPAL, user);
168: }
169:
170: /**
171: * return the username used to login to the jms server
172: *
173: * @return the username used to login to the jms server
174: */
175: public String getUsername() {
176: return getPropertyAsString(PRINCIPAL);
177: }
178:
179: /**
180: * Set the password to login to the jms server
181: *
182: * @param pwd
183: */
184: public void setPassword(String pwd) {
185: setProperty(CREDENTIALS, pwd);
186: }
187:
188: /**
189: * return the password used to login to the jms server
190: *
191: * @return the password used to login to the jms server
192: */
193: public String getPassword() {
194: return getPropertyAsString(CREDENTIALS);
195: }
196:
197: /**
198: * set the number of iterations the sampler should aggregate
199: *
200: * @param count
201: */
202: public void setIterations(String count) {
203: setProperty(ITERATIONS, count);
204: }
205:
206: /**
207: * get the iterations as string
208: *
209: * @return the number of iterations
210: */
211: public String getIterations() {
212: return getPropertyAsString(ITERATIONS);
213: }
214:
215: /**
216: * return the number of iterations as int instead of string
217: *
218: * @return the number of iterations as int instead of string
219: */
220: public int getIterationCount() {
221: return getPropertyAsInt(ITERATIONS);
222: }
223:
224: /**
225: * Set whether authentication is required for JNDI
226: *
227: * @param auth
228: */
229: public void setUseAuth(String auth) {
230: setProperty(USE_AUTH, auth);
231: }
232:
233: /**
234: * return whether jndi requires authentication
235: *
236: * @return whether jndi requires authentication
237: */
238: public String getUseAuth() {
239: return getPropertyAsString(USE_AUTH);
240: }
241:
242: /**
243: * set whether the sampler should read the response or not
244: *
245: * @param read whether the sampler should read the response or not
246: */
247: public void setReadResponse(String read) {
248: setProperty(READ_RESPONSE, read);
249: }
250:
251: /**
252: * return whether the sampler should read the response
253: *
254: * @return whether the sampler should read the response
255: */
256: public String getReadResponse() {
257: return getPropertyAsString(READ_RESPONSE);
258: }
259:
260: /**
261: * return whether the sampler should read the response as a boolean value
262: *
263: * @return whether the sampler should read the response as a boolean value
264: */
265: public boolean getReadResponseAsBoolean() {
266: return getPropertyAsBoolean(READ_RESPONSE);
267: }
268:
269: /**
270: * if the sampler should use jndi.properties file, call the method with true
271: *
272: * @param properties
273: */
274: public void setUseJNDIProperties(String properties) {
275: setProperty(USE_PROPERTIES_FILE, properties);
276: }
277:
278: /**
279: * return whether the sampler should use properties file instead of UI
280: * parameters.
281: *
282: * @return whether the sampler should use properties file instead of UI parameters.
283: */
284: public String getUseJNDIProperties() {
285: return getPropertyAsString(USE_PROPERTIES_FILE);
286: }
287:
288: /**
289: * return the properties as boolean true/false.
290: *
291: * @return whether the sampler should use properties file instead of UI parameters.
292: */
293: public boolean getUseJNDIPropertiesAsBoolean() {
294: return getPropertyAsBoolean(USE_PROPERTIES_FILE);
295: }
296: }
|