KickJava   Java API By Example, From Geeks To Geeks.

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

26
27
28 package org.objectweb.benchmark.fractal.latency;
29
30 // Package dependencies.
31
import org.objectweb.fractal.api.NoSuchInterfaceException;
32 import org.objectweb.fractal.api.control.BindingController;
33 import org.objectweb.fractal.api.control.IllegalBindingException;
34 import org.objectweb.fractal.api.control.IllegalLifeCycleException;
35
36 import org.objectweb.benchmark.util.ResultPrinter;
37
38
39 /**
40  * Fractal Rmi benchmark client application.
41  *
42  * @author <a HREF="mailto:Christophe.Demarey@lifl.fr">Christophe Demarey</a>
43  *
44  * @version 0.1
45  */

46 public class Client
47   implements BindingController,
48              Runnable JavaDoc
49 {
50
51     // ==================================================================
52
//
53
// Internal states.
54
//
55
// ==================================================================
56

57     /** Number of steps*/
58     private int nb_step;
59
60     /** Number of invocations per step*/
61     private int nb_step_invocation;
62     
63     /** Beginning of the first step*/
64     private int step_start;
65
66     /** Results file name */
67     private String JavaDoc result_file;
68
69     /** the host */
70     private String JavaDoc host;
71     
72     /** Ping interface reference */
73     private PingItf ping_impl;
74
75    // ==================================================================
76
//
77
// Constructors.
78
//
79
// ==================================================================
80

81     /**
82      * The default constructor.
83      */

84     public Client()
85     {
86         java.util.Properties JavaDoc properties = new java.util.Properties JavaDoc();
87
88         try {
89             java.io.InputStream JavaDoc propStream = null;
90         
91             // Bench info
92
propStream = getClass().getClassLoader().getResourceAsStream("benchmark.properties");
93             properties.load(propStream);
94         
95             nb_step = Integer.parseInt( properties.getProperty("step.number") );
96             nb_step_invocation = Integer.parseInt( properties.getProperty("step.invocation.number") );
97             step_start = Integer.parseInt( properties.getProperty("step.start") );
98             host = properties.getProperty("com.host");
99
100             // Fractal RMI info
101
propStream = getClass().getClassLoader().getResourceAsStream("build.properties");
102             properties.load(propStream);
103             result_file = properties.getProperty("dest.file");
104         } catch (Exception JavaDoc e) {
105             e.printStackTrace();
106         }
107     }
108
109     // ==================================================================
110
//
111
// Public methods.
112
//
113
// ==================================================================
114

115     /**
116      * Runs the latency benchmark.
117      */

118     public void test()
119     {
120         // Don't include the first step_start invocations
121
for (int i=0; i<step_start; i++)
122             ping_impl.ping();
123         
124         // Runs test
125
System.out.println( "Running Fractal Rmi Benchmark with " + nb_step + " step(s) of "
126                             + nb_step_invocation +" method calls." );
127         try{
128             for(int j=0; j<nb_step; j++)
129             {
130                 long timer = System.currentTimeMillis();
131                 
132                 for (int i=0; i<nb_step_invocation; i++)
133                     ping_impl.ping();
134                 timer = (long) ( ( System.currentTimeMillis() - timer ) * 1000 / (float)nb_step_invocation );
135              
136                 // write results
137
ResultPrinter p = new ResultPrinter(result_file);
138                 p.write(timer);
139                 p.close();
140             }
141         }catch(Exception JavaDoc ex){
142             ex.printStackTrace();
143         }
144     }
145
146     /* (non-Javadoc)
147      * @see org.objectweb.fractal.api.control.BindingController#listFc()
148      */

149     public String JavaDoc[] listFc()
150     {
151         String JavaDoc [] list = new String JavaDoc[0];
152         
153         if (ping_impl != null)
154         {
155             list = new String JavaDoc[1];
156             list[0] = "PingItf";
157         }
158
159         return list;
160     }
161
162     /* (non-Javadoc)
163      * @see org.objectweb.fractal.api.control.BindingController#lookupFc(java.lang.String)
164      */

165     public Object JavaDoc lookupFc(final String JavaDoc cItf)
166     throws NoSuchInterfaceException
167     {
168         if (cItf.compareTo("PingItf") == 0)
169         {
170             return ping_impl;
171         }
172         throw new NoSuchInterfaceException(cItf);
173     }
174
175     /* (non-Javadoc)
176      * @see org.objectweb.fractal.api.control.BindingController#bindFc(java.lang.String, java.lang.Object)
177      */

178     public void bindFc(final String JavaDoc cItf, final Object JavaDoc sItf)
179     throws NoSuchInterfaceException, IllegalBindingException, IllegalLifeCycleException
180     {
181         if (cItf.compareTo("PingItf") == 0)
182         {
183             ping_impl = (PingItf) sItf;
184         }
185         else
186             throw new NoSuchInterfaceException(cItf);
187     }
188
189     /* (non-Javadoc)
190      * @see org.objectweb.fractal.api.control.BindingController#unbindFc(java.lang.String)
191      */

192     public void unbindFc(final String JavaDoc cItf)
193     throws NoSuchInterfaceException, IllegalBindingException, IllegalLifeCycleException
194     {
195         if (cItf.compareTo("PingItf") == 0)
196         {
197             ping_impl = null;
198         }
199         else
200             throw new NoSuchInterfaceException(cItf);
201     }
202
203     /* (non-Javadoc)
204      * @see org.objectweb.benchmark.fractal.latency.Runnable#run()
205      */

206     public void run()
207     {
208         test();
209     }
210 }
211
Popular Tags