KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > benchmark > xmlrpc > 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.xmlrpc.latency;
28
29 // Package dependencies.
30
import org.apache.xmlrpc.XmlRpcClient ;
31 import org.objectweb.benchmark.util.ResultPrinter;
32
33
34 /**
35  * This client tests WS latency by calling several times the ping method.
36  *
37  * @author Harbonnier Denimal
38  *
39  * @version 1.0
40  */

41 public class Client
42 {
43     // ==================================================================
44
//
45
// Internal states.
46
//
47
// ==================================================================
48

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

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

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

109     // ==================================================================
110
//
111
// Public methods.
112
//
113
// ==================================================================
114

115     /**
116      * The bootstrap method.
117      *
118      * @param args - Client arguments.
119      */

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

135     public void run()
136     {
137         // Obtains the Ping Itf reference
138
try{
139             ping_impl = new XmlRpcClient ("http://"+host+":"+port);
140         }catch(Exception JavaDoc ex){
141             ex.printStackTrace();
142         }
143         
144         // Runs benchmark
145
test();
146     }
147
148     /**
149      * Runs the latency benchmark.
150      */

151     public void test()
152     {
153         java.util.Vector JavaDoc args = new java.util.Vector JavaDoc();
154         
155         // Don't include the first invocation
156
try
157         {
158             for (int i=0; i<step_start; i++)
159                 ping_impl.execute ("pingServer.ping", args) ;
160         } catch (Exception JavaDoc e) {
161             e.printStackTrace();
162         }
163         
164         // Runs test
165
System.out.println("Running WS Benchmark with " + nb_step + " step(s) of " + nb_step_invocation +" method calls.");
166         try{
167             for(int j=0; j<nb_step; j++)
168             {
169                 long timer = System.currentTimeMillis();
170                 
171                 for (int i=0; i<nb_step_invocation; i++)
172                     ping_impl.execute ("pingServer.ping", args) ;
173                 timer = (long) ( ( System.currentTimeMillis() - timer ) * 1000 / (float)nb_step_invocation );
174             
175                 // write results
176
ResultPrinter p = new ResultPrinter(result_file);
177                 p.write(timer);
178                 p.close();
179             }
180         }catch(Exception JavaDoc ex){
181             ex.printStackTrace();
182         }
183     }
184 }
185     
186
Popular Tags