KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > benchmark > benchIce > 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): Gael Harbonnier.
23 Contributor(s): _______________.
24
25 ====================================================================*/

26
27
28 package org.objectweb.benchmark.benchIce.latency;
29
30 // Package dependencies.
31
import org.objectweb.benchmark.util.ResultPrinter;
32
33 /**
34  * Ice benchmark client application.
35  *
36  * @author <a HREF="mailto:Christophe.Demarey@lifl.fr">Christophe Demarey</a>
37  *
38  * @version 0.1
39  */

40 public class Client
41 {
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     /** the host */
62     private String JavaDoc host;
63
64     /** Ping interface reference */
65     private PingItfPrx ping = null;
66
67     /** Ice communicator object*/
68     Ice.Communicator ic = null;
69
70     // ==================================================================
71
//
72
// Constructors.
73
//
74
// ==================================================================
75

76     /**
77      * The default constructor.
78      *
79      * @param name - Results file name.
80      */

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             // Bench info
91
propStream = getClass().getClassLoader().getResourceAsStream("benchmark.properties");
92             properties.load(propStream);
93         
94             nb_step = Integer.parseInt( properties.getProperty("step.number") );
95             nb_step_invocation = Integer.parseInt( properties.getProperty("step.invocation.number") );
96             step_start = Integer.parseInt( properties.getProperty("step.start") );
97             host = properties.getProperty("com.host");
98         
99         } catch (Exception JavaDoc e) {
100             e.printStackTrace();
101         }
102     }
103
104     // ==================================================================
105
//
106
// Public methods.
107
//
108
// ==================================================================
109

110    /**
111      * The bootstrap method.
112      *
113      * @param args - Application arguments
114      */

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

130     public void run()
131     {
132         try{
133             ic = Ice.Util.initialize(new String JavaDoc[0]);
134             
135             //Ice doesn't recognize localhost
136
if( host.equals("localhost") )
137             host = java.net.InetAddress.getLocalHost().getHostAddress().toString();
138             
139             Ice.ObjectPrx base = ic.stringToProxy("SimplePrinter:default -h "+host+" -p 10000");
140             ping = PingItfPrxHelper.checkedCast(base);
141         }catch(Exception JavaDoc ex){
142             ex.printStackTrace();
143         }
144         
145         // Runs benchmark
146
test();
147     }
148
149     /**
150      * Runs the latency benchmark.
151      */

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