KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > benchmark > ccm > latency > ClientImpl


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):
24
25 ====================================================================*/

26
27 package org.objectweb.benchmark.ccm.latency;
28
29 // Package dependencies
30
import org.objectweb.benchmark.util.ResultPrinter;
31
32 /**
33  * This is the implementation of the OMG IDL3 latency::Client component type.
34  *
35  * This class inherits from the CIF generated skeleton class defined
36  * as ClientSessionComposition::ComponentImpl.
37  */

38
39 public class ClientImpl
40      extends org.objectweb.benchmark.ccm.latency.ClientSessionComposition.ComponentImpl
41 {
42     // ==================================================================
43
//
44
// Internal state.
45
//
46
// ==================================================================
47

48     /** Number of steps*/
49     private int nb_step;
50
51     /** Number of invocations per step*/
52     private int nb_step_invocation;
53     
54     /** Beginning of the first step*/
55     private int step_start;
56     
57     /** Results file name */
58     private String JavaDoc result_file;
59
60     /** host */
61     private String JavaDoc host;
62     
63     // ==================================================================
64
//
65
// Constructor.
66
//
67
// ==================================================================
68

69     /** The default constructor. */
70     public
71     ClientImpl()
72     {
73         java.util.Properties JavaDoc properties = new java.util.Properties JavaDoc();
74         result_file = "OpenCCM.txt";
75
76         try {
77             java.io.InputStream JavaDoc propStream = null;
78
79             propStream = getClass().getClassLoader().getResourceAsStream("benchmark.properties");
80             properties.load(propStream);
81         
82             nb_step = Integer.parseInt( properties.getProperty("step.number") );
83             nb_step_invocation = Integer.parseInt( properties.getProperty("step.invocation.number") );
84             step_start = Integer.parseInt( properties.getProperty("step.start") );
85             host = properties.getProperty("com.host");
86         } catch (Exception JavaDoc e) {
87             e.printStackTrace();
88         }
89     }
90
91     // ==================================================================
92
//
93
// Internal methods.
94
//
95
// ==================================================================
96

97     // ==================================================================
98
//
99
// Public methods.
100
//
101
// ==================================================================
102

103     // ==================================================================
104
//
105
// Methods for OMG IDL Components::EnterpriseComponent
106
//
107
// ==================================================================
108

109     /**
110      * Complete the component configuration.
111      *
112      * @exception org.omg.Components.InvalidConfiguration
113      * Thrown if the configuration is invalid.
114      */

115     public void
116     configuration_complete()
117     throws org.omg.Components.InvalidConfiguration
118     {
119         // Check if the connection to the server is set.
120
if(get_context().get_connection_to_server() == null)
121             throw new org.omg.Components.InvalidConfiguration();
122
123         // Obtain the object reference associated to the
124
// 'to_server' receptacle.
125
PingInterface to_server = get_context().get_connection_to_server();
126
127         // Check if the connection is available.
128
if(to_server == null)
129         {
130             System.err.println("The hello::Client::to_server receptacle is not set!");
131             return;
132         }
133
134         // Don't include the first step_start invocations
135
for (int i=0; i<step_start; i++)
136             to_server.ping();
137     
138         // Runs test
139
System.out.println("Running Rmi Benchmark with " + nb_step + " step(s) of " + nb_step_invocation +" method calls.");
140         try
141         {
142             for(int j=0; j<nb_step; j++)
143             {
144                 long timer = System.currentTimeMillis();
145                 
146                 for (int i=0; i<nb_step_invocation; i++)
147                     to_server.ping();
148                 timer = (long) ( ( System.currentTimeMillis() - timer ) * 1000 / (float)nb_step_invocation );
149             
150                 // write results
151
ResultPrinter p = new ResultPrinter(result_file);
152                 p.write(timer);
153                 p.close();
154             }
155         }catch(Exception JavaDoc ex){
156             ex.printStackTrace();
157         }
158     }
159
160     // ==================================================================
161
//
162
// Methods for the OMG IDL org.omg.Components.SessionComponent
163
//
164
// ==================================================================
165

166     /**
167      * Container callback to signal that the component is removed.
168      *
169      * @throw org.omg.Components.CCMException For any problems.
170      */

171     public void
172     ccm_remove()
173     throws org.omg.Components.CCMException
174     {
175     }
176
177     // ==================================================================
178
//
179
// Methods for the OMG IDL demo1::CCM_Client_Executor
180
//
181
// ==================================================================
182

183 }
184
Popular Tags