KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > benchmark > corba > 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.corba.latency;
28
29 // Package dependencies.
30
import java.io.InputStreamReader JavaDoc;
31 import java.io.BufferedReader JavaDoc;
32 import java.net.Socket JavaDoc;
33
34 import org.objectweb.benchmark.util.ResultPrinter;
35 import org.omg.CORBA.ORB JavaDoc;
36
37 /**
38  * CORBA benchmark client application.
39  *
40  * @author <a HREF="mailto:Christophe.Demarey@lifl.fr">Christophe Demarey</a>
41  *
42  * @version 0.1
43  */

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

52     /** Number of steps*/
53     private int nb_step;
54
55     /** Number of invocations per step*/
56     private int nb_step_invocation;
57     
58     /** Beginning of the first step*/
59     private int step_start;
60
61     /** Results file name */
62     private String JavaDoc result_file;
63
64     /** The port for recieving IOR */
65     private int ior_port;
66
67     /** the host */
68     private String JavaDoc host;
69
70     /** ORB reference */
71     private ORB JavaDoc orb = null;
72     
73     /** Ping interface reference */
74     private PingItf ping_impl = null;
75
76     // ==================================================================
77
//
78
// Constructors.
79
//
80
// ==================================================================
81

82     /**
83      * The default constructor.
84      *
85      * @param n - Number of invocations to do.
86      * @param name - Results file name.
87      */

88     public Client(String JavaDoc name)
89     {
90         result_file = name;
91         java.util.Properties JavaDoc properties = new java.util.Properties JavaDoc();
92
93         try {
94             java.io.InputStream JavaDoc propStream = null;
95         
96             // Bench info
97
propStream = getClass().getClassLoader().getResourceAsStream("benchmark.properties");
98             properties.load(propStream);
99         
100             nb_step = Integer.parseInt( properties.getProperty("step.number") );
101             nb_step_invocation = Integer.parseInt( properties.getProperty("step.invocation.number") );
102             step_start = Integer.parseInt( properties.getProperty("step.start") );
103             host = properties.getProperty("com.host");
104         
105             // IOR info
106
propStream = getClass().getClassLoader().getResourceAsStream("build.properties");
107             properties.load(propStream);
108
109             ior_port=Integer.parseInt( properties.getProperty("ior.port") );
110         } catch (Exception JavaDoc e) {
111             e.printStackTrace();
112         }
113     }
114
115     // ==================================================================
116
//
117
// Internal methods.
118
//
119
// ==================================================================
120

121     /**
122      * Inits ORB properties.
123      */

124     private void init_orb()
125     {
126         try {
127             java.io.InputStream JavaDoc propStream = null;
128
129             propStream = getClass().getClassLoader().getResourceAsStream("ORB.properties");
130             System.getProperties().load(propStream);
131         }catch (Exception JavaDoc e) {
132             e.printStackTrace();
133         }
134     }
135     
136     // ==================================================================
137
//
138
// Public methods.
139
//
140
// ==================================================================
141

142    /**
143      * The bootstrap method.
144      *
145      * @param args - Application arguments
146      */

147     public static void main(String JavaDoc[] args)
148     {
149         if (args.length != 1)
150         {
151             System.out.println("Usage: Client <dest_file>");
152             System.exit(0);
153         }
154
155         Client c = new Client(args[0]);
156         c.run();
157     }
158
159     /**
160      * Runs n invocations on the CORBA client.
161      */

162     public void run()
163     {
164         // Inits the ORB
165
init_orb();
166         orb = ORB.init(new String JavaDoc[0], null);
167
168         // Obtains the Ping Itf reference
169
try{
170             // Opens a new Socket for retrieving the IOR
171
Socket JavaDoc s = new Socket JavaDoc(host,ior_port);
172
173             BufferedReader JavaDoc in =new BufferedReader JavaDoc(new InputStreamReader JavaDoc(s.getInputStream()));
174             org.omg.CORBA.Object JavaDoc obj = orb.string_to_object(in.readLine());
175           
176             ping_impl = PingItfHelper.narrow(obj);
177         }catch(Exception JavaDoc ex){
178             ex.printStackTrace();
179         }
180         
181         // Runs benchmark
182
test();
183         
184         // Stops the ORB
185
orb.shutdown(false);
186     }
187
188     /**
189      * Runs the latency benchmark.
190      */

191     public void test()
192     {
193         // Don't include the first step_start invocations
194
for (int i=0; i<step_start; i++)
195             ping_impl.ping();
196         
197         // Runs test
198
System.out.println( "Running CORBA Benchmark with " + nb_step + " step(s) of "
199                             + nb_step_invocation +" method calls." );
200         try{
201             for(int j=0; j<nb_step; j++)
202             {
203                 long timer = System.currentTimeMillis();
204                 
205                 for (int i=0; i<nb_step_invocation; i++)
206                     ping_impl.ping();
207                 timer = (long) ( ( System.currentTimeMillis() - timer ) * 1000 / (float)nb_step_invocation );
208              
209                 // write results
210
ResultPrinter p = new ResultPrinter(result_file);
211                 p.write(timer);
212                 p.close();
213             }
214         }catch(Exception JavaDoc ex){
215             ex.printStackTrace();
216         }
217         
218         // Closes the server
219
ping_impl.shutdown();
220     }
221 }
222
Popular Tags