KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > benchmark > ws > latency > Client


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2004 INRIA - USTL - LIFL - GOAL
5 Contact: openccm@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Christophe Demarey.
23 Contributor(s): Gael Harbonnier.
24
25 ====================================================================*/

26
27 package org.objectweb.benchmark.ws.latency;
28
29 // Package dependencies.
30
import org.objectweb.benchmark.util.ResultPrinter;
31 import org.apache.axis.client.Call;
32 import org.apache.axis.client.Service;
33 import org.apache.axis.encoding.XMLType;
34
35
36 /**
37  * This client tests WS latency by calling several times the ping method.
38  *
39  * @author Harbonnier Denimal
40  *
41  * @version 1.0
42  */

43 public class Client
44 {
45     // ==================================================================
46
//
47
// Internal states.
48
//
49
// ==================================================================
50

51     /** Number of steps*/
52     private int nb_step;
53
54     /** Number of invocations per step*/
55     private int nb_step_invocation;
56     
57     /** Beginning of the first step*/
58     private int step_start;
59
60     /** Results file name */
61     private String JavaDoc result_file;
62
63     /** host */
64     private String JavaDoc host;
65     
66     /** Ping interface reference */
67     private Call ping_ws = null;
68
69     // ==================================================================
70
//
71
// Constructors.
72
//
73
// ==================================================================
74

75     /**
76      * The default constructor.
77      *
78      * @param n - Number of invocations to do.
79      * @param name - Results file name.
80      */

81     public Client(String JavaDoc name)
82     {
83         result_file = name;
84         java.util.Properties JavaDoc properties = new java.util.Properties JavaDoc();
85
86         try {
87             java.io.InputStream JavaDoc propStream = null;
88
89             propStream = getClass().getClassLoader().getResourceAsStream("benchmark.properties");
90             properties.load(propStream);
91         
92             nb_step = Integer.parseInt( properties.getProperty("step.number") );
93             nb_step_invocation = Integer.parseInt( properties.getProperty("step.invocation.number") );
94             step_start = Integer.parseInt( properties.getProperty("step.start") );
95             host = properties.getProperty("com.host");
96         } catch (Exception JavaDoc e) {
97             e.printStackTrace();
98         }
99     }
100
101     // ==================================================================
102
//
103
// Internal methods.
104
//
105
// ==================================================================
106

107     // ==================================================================
108
//
109
// Public methods.
110
//
111
// ==================================================================
112

113     /**
114      * The bootstrap method.
115      *
116      * @param args - Client arguments.
117      */

118     public static void main(String JavaDoc[] args)
119     {
120         if (args.length != 1)
121         {
122             System.out.println("Usage: Client <dest_file>");
123             System.exit(0);
124         }
125
126         Client c = new Client(args[0]);
127         c.run();
128     }
129
130     /**
131      * Runs n invocations on the CORBA client.
132      */

133     public void run()
134     {
135         String JavaDoc endpoint = "http://"+host+":8080/axis/PingWS.jws";
136
137         // Obtains the Ping Itf reference
138
try {
139             Service service = new Service();
140             ping_ws = (Call) service.createCall();
141              
142             ping_ws.setTargetEndpointAddress( new java.net.URL JavaDoc(endpoint) );
143             ping_ws.setOperationName("ping");
144             ping_ws.setReturnType( XMLType.AXIS_VOID );
145         } catch (Exception JavaDoc e) {
146             e.printStackTrace();
147         }
148
149         // Runs benchmark
150
test();
151     }
152
153     /**
154      * Runs the latency benchmark.
155      */

156     public void test()
157     {
158         Object JavaDoc[] params = new Object JavaDoc[0];
159         
160         // Don't include the first invocation
161
try
162         {
163             for (int i=0; i<step_start; i++)
164                 ping_ws.invoke(params);
165         } catch (Exception JavaDoc e) {
166             e.printStackTrace();
167         }
168         
169         // Runs test
170
System.out.println("Running WS Benchmark with " + nb_step + " step(s) of " + nb_step_invocation +" method calls.");
171         try{
172             for(int j=0; j<nb_step; j++)
173             {
174                 long timer = System.currentTimeMillis();
175                 
176                 for (int i=0; i<nb_step_invocation; i++)
177                     ping_ws.invoke(params);
178                 timer = (long) ( ( System.currentTimeMillis() - timer ) * 1000 / (float)nb_step_invocation );
179             
180                 // write results
181
ResultPrinter p = new ResultPrinter(result_file);
182                 p.write(timer);
183                 p.close();
184             }
185         }catch(Exception JavaDoc ex){
186             ex.printStackTrace();
187         }
188     }
189 }
190     
191
Popular Tags