KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jmeter > protocol > java > sampler > JavaSamplerClient


1 // $Header: /home/cvs/jakarta-jmeter/src/protocol/java/org/apache/jmeter/protocol/java/sampler/JavaSamplerClient.java,v 1.7 2004/02/10 00:46:44 sebb Exp $
2
/*
3  * Copyright 2002-2004 The Apache Software Foundation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17 */

18
19 package org.apache.jmeter.protocol.java.sampler;
20
21 import org.apache.jmeter.config.Arguments;
22 import org.apache.jmeter.samplers.SampleResult;
23
24 /**
25  * This interface defines the interactions between the JavaSampler
26  * and external Java programs which can be executed by JMeter. Any
27  * Java class which wants to be executed as a JMeter test must
28  * implement this interface (either directly or indirectly through
29  * AbstractJavaSamplerClient).
30  * <p>
31  * JMeter will create one instance of a JavaSamplerClient implementation
32  * for each user/thread in the test. Additional instances may be
33  * created for internal use by JMeter (for example, to find out
34  * what parameters are supported by the client).
35  * <p>
36  * When the test is started, setupTest() will be called on each
37  * thread's JavaSamplerClient instance to initialize the client.
38  * Then runTest() will be called for each iteration of the test.
39  * Finally, teardownTest() will be called to allow the client
40  * to do any necessary clean-up.
41  * <p>
42  * The JMeter JavaSampler GUI allows a list of parameters to be
43  * defined for the test. These are passed to the various test
44  * methods through the {@link JavaSamplerContext}. A list of default
45  * parameters can be defined through the getDefaultParameters()
46  * method. These parameters and any default values associated
47  * with them will be shown in the GUI. Users can add other
48  * parameters as well.
49  * <p>
50  * When possible, Java tests should extend {@link AbstractJavaSamplerClient
51  * AbstractJavaSamplerClient} rather than implementing JavaSamplerClient
52  * directly. This should protect your tests from future changes to the
53  * interface. While it may be necessary to make changes to the
54  * JavaSamplerClient interface from time to time (therefore requiring changes
55  * to any implementations of this interface), we intend to make this abstract
56  * class provide reasonable default implementations of any new methods so that
57  * subclasses do not necessarily need to be updated for new versions.
58  * Implementing JavaSamplerClient directly will continue to be
59  * supported for cases where extending this class is not possible
60  * (for example, when the client class is already a subclass of some
61  * other class).
62  * <p>
63  * See {@link org.apache.jmeter.protocol.java.test.SleepTest} for an
64  * example of how to implement this interface.
65  *
66  * @author Brad Kiewel
67  * @author <a HREF="mailto:jeremy_a@bigfoot.com">Jeremy Arnold</a>
68  * @version $Revision: 1.7 $
69  */

70 public interface JavaSamplerClient
71 {
72     /**
73      * Do any initialization required by this client. It is
74      * generally recommended to do any initialization such as
75      * getting parameter values in the setupTest method rather
76      * than the runTest method in order to add as little overhead
77      * as possible to the test.
78      *
79      * @param context the context to run with. This provides access
80      * to initialization parameters.
81      */

82     void setupTest(JavaSamplerContext context);
83
84     /**
85      * Perform a single sample for each iteration. This method
86      * returns a <code>SampleResult</code> object.
87      * <code>SampleResult</code> has many fields which can be
88      * used. At a minimum, the test should use
89      * <code>SampleResult.sampleStart</code> and
90      * <code>SampleResult.sampleEnd</code>to set the time that
91      * the test required to execute. It is also a good idea to
92      * set the sampleLabel and the successful flag.
93      *
94      * @see org.apache.jmeter.samplers.SampleResult#sampleStart()
95      * @see org.apache.jmeter.samplers.SampleResult#sampleEnd()
96      * @see org.apache.jmeter.samplers.SampleResult#setSuccessful(boolean)
97      * @see org.apache.jmeter.samplers.SampleResult#setSampleLabel(String)
98      *
99      * @param context the context to run with. This provides access
100      * to initialization parameters.
101      *
102      * @return a SampleResult giving the results of this
103      * sample.
104      */

105     SampleResult runTest(JavaSamplerContext context);
106
107     /**
108      * Do any clean-up required by this test at the end of a test run.
109      *
110      * @param context the context to run with. This provides access
111      * to initialization parameters.
112      */

113     void teardownTest(JavaSamplerContext context);
114
115     /**
116      * Provide a list of parameters which this test supports. Any
117      * parameter names and associated values returned by this method
118      * will appear in the GUI by default so the user doesn't have
119      * to remember the exact names. The user can add other parameters
120      * which are not listed here. If this method returns null then
121      * no parameters will be listed. If the value for some parameter
122      * is null then that parameter will be listed in the GUI with
123      * an empty value.
124      *
125      * @return a specification of the parameters used by this
126      * test which should be listed in the GUI, or null
127      * if no parameters should be listed.
128      */

129     Arguments getDefaultParameters();
130 }
131
Popular Tags