KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > rice > rubbos > client > RUBBoSProperties


1 package edu.rice.rubbos.client;
2
3 import java.io.BufferedReader JavaDoc;
4 import java.io.FileReader JavaDoc;
5 import java.io.RandomAccessFile JavaDoc;
6 import java.util.ResourceBundle JavaDoc;
7 import java.util.StringTokenizer JavaDoc;
8 import java.util.Vector JavaDoc;
9
10 /**
11  * This program check and get all information for the rubbos.properties file
12  * found in the classpath.
13  *
14  * @author <a HREF="mailto:cecchet@rice.edu">Emmanuel Cecchet</a> and <a HREF="mailto:julie.marguerite@inrialpes.fr">Julie Marguerite</a>
15  * @version 1.0
16  */

17
18 public class RUBBoSProperties
19 {
20   private static ResourceBundle JavaDoc configuration = null;
21   private URLGenerator urlGen = null;
22
23   // Information about web server
24
private String JavaDoc webSiteName;
25   private int webSitePort;
26   private String JavaDoc cjdbcSiteName;
27   private String JavaDoc EJBHTMLPath;
28   private String JavaDoc EJBScriptPath;
29   private String JavaDoc ServletsHTMLPath;
30   private String JavaDoc ServletsScriptPath;
31   private String JavaDoc PHPHTMLPath;
32   private String JavaDoc PHPScriptPath;
33   private String JavaDoc useVersion;
34
35   // Information about Workload
36
private Vector JavaDoc remoteClients;
37   private String JavaDoc remoteCommand;
38   private int nbOfClients;
39   private String JavaDoc userTransitionTable;
40   private String JavaDoc authorTransitionTable;
41   private int nbOfColumns;
42   private int nbOfRows;
43   private int maxNbOfTransitions;
44   private boolean useTPCWThinkTime;
45   private int nbOfStoriesPerPage;
46   private int upTime;
47   private float upSlowdown;
48   private int sessionTime;
49   private int downTime;
50   private float downSlowdown;
51   private int percentOfAuthors;
52
53
54   // Policy to generate database information
55
private String JavaDoc dbServerName;
56   
57   private Integer JavaDoc nbOfAuthors;
58   private Integer JavaDoc nbOfUsers;
59
60   private String JavaDoc storyDictionary;
61   private Integer JavaDoc storyMaxLength;
62   private Integer JavaDoc oldestStoryYear;
63   private Integer JavaDoc oldestStoryMonth;
64
65   private Integer JavaDoc maxCommentsPerStory;
66   private Integer JavaDoc commentMaxLength;
67
68
69   // Monitoring information
70
private Integer JavaDoc monitoringDebug;
71   private String JavaDoc monitoringProgram;
72   private String JavaDoc monitoringOptions;
73   private Integer JavaDoc monitoringSampling;
74   private String JavaDoc monitoringRsh;
75   private String JavaDoc monitoringScp;
76   private String JavaDoc monitoringGnuPlot;
77   
78   /**
79    * Creates a new <code>RUBBoSProperties</code> instance.
80    * If the rubbos.properties file is not found in the classpath,
81    * the current thread is killed.
82    */

83   public RUBBoSProperties()
84   {
85     // Get and check database.properties
86
System.out.println("Looking for rubbos.properties in classpath ("+System.getProperty("java.class.path",".")+")<p>");
87     try
88     {
89       configuration = ResourceBundle.getBundle("rubbos");
90     }
91     catch (java.util.MissingResourceException JavaDoc e)
92     {
93       System.err.println("No rubbos.properties file has been found in your classpath.<p>");
94       Runtime.getRuntime().exit(1);
95     }
96   }
97
98   
99   /**
100    * Returns the value corresponding to a property in the rubbos.properties file.
101    *
102    * @param property the property name
103    * @return a <code>String</code> value
104    */

105   protected String JavaDoc getProperty(String JavaDoc property)
106   {
107     String JavaDoc s = configuration.getString(property);
108     return s;
109   }
110
111
112   /**
113    * Check for all needed fields in rubbos.properties and inialize corresponding values.
114    * This function returns the corresponding URLGenerator on success.
115    *
116    * @return returns null on any error or the URLGenerator corresponding to the configuration if everything was ok.
117    */

118   public URLGenerator checkPropertiesFileAndGetURLGenerator()
119   {
120     try
121     {
122       // # HTTP server information
123
System.out.println("\n<h3>### HTTP server information ###</h3>");
124       System.out.print("Server name : ");
125       webSiteName = getProperty("httpd_hostname");
126       System.out.println(webSiteName+"<br>");
127       System.out.print("Server port : ");
128       Integer JavaDoc foo = new Integer JavaDoc(getProperty("httpd_port"));
129       webSitePort = foo.intValue();
130       System.out.println(webSitePort+"<br>");
131       System.out.print("CJDBC server name : ");
132       cjdbcSiteName = getProperty("cjdbc_hostname");
133       System.out.println(cjdbcSiteName+"<br>");
134       System.out.print("EJB HTML files path : ");
135       EJBHTMLPath = getProperty("ejb_html_path");
136       System.out.println(EJBHTMLPath+"<br>");
137       System.out.print("EJB Script files path : ");
138       EJBScriptPath = getProperty("ejb_script_path");
139       System.out.println(EJBScriptPath+"<br>");
140       System.out.print("Servlets HTML files path : ");
141       ServletsHTMLPath = getProperty("servlets_html_path");
142       System.out.println(ServletsHTMLPath+"<br>");
143       System.out.print("Servlets Script files path : ");
144       ServletsScriptPath = getProperty("servlets_script_path");
145       System.out.println(ServletsScriptPath+"<br>");
146       System.out.print("Servlets HTML files path : ");
147       PHPHTMLPath = getProperty("php_html_path");
148       System.out.println(PHPHTMLPath+"<br>");
149       System.out.print("PHP Script files path : ");
150       PHPScriptPath = getProperty("php_script_path");
151       System.out.println(PHPScriptPath+"<br>");
152       
153       // # Workload
154
System.out.println("\n<h3><br>### Workload ###</h3>");
155       System.out.print("Remote client nodes : ");
156       StringTokenizer JavaDoc nodes = new StringTokenizer JavaDoc(getProperty("workload_remote_client_nodes"),",");
157       remoteClients = new Vector JavaDoc(nodes.countTokens());
158       while (nodes.hasMoreTokens())
159         remoteClients.add(nodes.nextToken().trim());
160       nbOfClients = remoteClients.size();
161       System.out.println(nbOfClients+"<br>");
162       System.out.print("Remote client command : ");
163       remoteCommand = getProperty("workload_remote_client_command");
164       System.out.println(remoteCommand+"<br>");
165       System.out.print("Number of clients : ");
166       foo = new Integer JavaDoc(getProperty("workload_number_of_clients_per_node"));
167       nbOfClients = foo.intValue();
168       System.out.println(nbOfClients+"<br>");
169
170       System.out.print("User transition table : ");
171       userTransitionTable = getProperty("workload_user_transition_table");
172       System.out.println(userTransitionTable+"<br>");
173       System.out.print("Author transition table : ");
174       authorTransitionTable = getProperty("workload_author_transition_table");
175       System.out.println(authorTransitionTable+"<br>");
176       System.out.print("Number of columns : ");
177       foo = new Integer JavaDoc(getProperty("workload_number_of_columns"));
178       nbOfColumns = foo.intValue();
179       System.out.println(nbOfColumns+"<br>");
180       System.out.print("Number of rows : ");
181       foo = new Integer JavaDoc(getProperty("workload_number_of_rows"));
182       nbOfRows = foo.intValue();
183       System.out.println(nbOfRows+"<br>");
184       System.out.print("Maximum number of transitions : ");
185       foo = new Integer JavaDoc(getProperty("workload_maximum_number_of_transitions"));
186       maxNbOfTransitions = foo.intValue();
187       System.out.println(maxNbOfTransitions+"<br>");
188       System.out.print("Number of stories per page : ");
189       foo = new Integer JavaDoc(getProperty("workload_number_of_stories_per_page"));
190       nbOfStoriesPerPage = foo.intValue();
191       System.out.println(nbOfStoriesPerPage+"<br>");
192       System.out.print("Think time : ");
193       useTPCWThinkTime = getProperty("workload_use_tpcw_think_time").compareTo("yes") == 0;
194       if (useTPCWThinkTime)
195         System.out.println("TPCW compatible with 7s mean<br>");
196       else
197         System.out.println("Using Transition Matrix think time information<br>");
198       System.out.print("Up ramp time in ms : ");
199       foo = new Integer JavaDoc(getProperty("workload_up_ramp_time_in_ms"));
200       upTime = foo.intValue();
201       System.out.println(upTime+"<br>");
202       System.out.print("Up ramp slowdown factor : ");
203       Float JavaDoc floo = new Float JavaDoc(getProperty("workload_up_ramp_slowdown_factor"));
204       upSlowdown = floo.intValue();
205       System.out.println(upSlowdown+"<br>");
206       System.out.print("Session run time in ms : ");
207       foo = new Integer JavaDoc(getProperty("workload_session_run_time_in_ms"));
208       sessionTime = foo.intValue();
209       System.out.println(sessionTime+"<br>");
210       System.out.print("Down ramp time in ms : ");
211       foo = new Integer JavaDoc(getProperty("workload_down_ramp_time_in_ms"));
212       downTime = foo.intValue();
213       System.out.println(downTime+"<br>");
214       System.out.print("Down ramp slowdown factor : ");
215       floo = new Float JavaDoc(getProperty("workload_down_ramp_slowdown_factor"));
216       downSlowdown = floo.intValue();
217       System.out.println(downSlowdown+"<br>");
218       System.out.print("Percentage of authors : ");
219       foo = new Integer JavaDoc(getProperty("workload_percentage_of_author"));
220       percentOfAuthors = foo.intValue();
221       System.out.println(percentOfAuthors+"<br>");
222
223       // # Database Information
224
System.out.println("\n<h3><br>### Database Information ###</h3>");
225       System.out.print("Database server : ");
226       dbServerName = getProperty("database_server");
227       System.out.println(dbServerName+"<br>");
228
229       // # Users policy
230
System.out.println("\n<h3><br>### Users policy ###</h3>");
231       System.out.print("Number of authors : ");
232       nbOfAuthors = new Integer JavaDoc(getProperty("database_number_of_authors"));
233       System.out.println(nbOfAuthors+"<br>");
234       System.out.print("Number of users : ");
235       nbOfUsers = new Integer JavaDoc(getProperty("database_number_of_users"));
236       System.out.println(nbOfUsers+"<br>");
237       
238       
239       // # Stories policy
240
System.out.println("\n<h3><br>### Stories policy ###</h3>");
241       System.out.print("Stories dictionary : ");
242       storyDictionary = getProperty("database_story_dictionnary");
243       System.out.println(storyDictionary+"<br>");
244       // Check that the dictionnary file is ok to read
245
try
246       {
247         RandomAccessFile JavaDoc f = new RandomAccessFile JavaDoc(storyDictionary, "r");
248         String JavaDoc useless = f.readLine();
249         f.close();
250       }
251       catch (Exception JavaDoc e)
252       {
253         System.err.println("Unable to read dictionary file '"+storyDictionary+"' (got exception: "+e.getMessage()+")");
254         return null;
255       }
256       System.out.print("Stories maximum lenth : ");
257       storyMaxLength = new Integer JavaDoc(getProperty("database_story_maximum_length"));
258       System.out.println(storyMaxLength+"<br>");
259       System.out.print("Oldest story year : ");
260       oldestStoryYear = new Integer JavaDoc(getProperty("database_oldest_story_year"));
261       System.out.println(oldestStoryYear+"<br>");
262       System.out.print("Oldest story month : ");
263       oldestStoryMonth = new Integer JavaDoc(getProperty("database_oldest_story_month"));
264       System.out.println(oldestStoryMonth+"<br>");
265
266       // # Comments policy
267
System.out.println("\n<h3><br>### Comments policy ###</h3>");
268       System.out.print("Comment maximum length : ");
269       commentMaxLength = new Integer JavaDoc(getProperty("database_comment_max_length"));
270       System.out.println(commentMaxLength+"<br>");
271
272       // # Monitoring Information
273
System.out.println("\n<h3><br>### Database Information ###</h3>");
274       System.out.print("Monitoring debugging level : ");
275       monitoringDebug = new Integer JavaDoc(getProperty("monitoring_debug_level"));
276       System.out.println(monitoringDebug+"<br>");
277       System.out.print("Monitoring program : ");
278       monitoringProgram = getProperty("monitoring_program");
279       System.out.println(monitoringProgram+"<br>");
280       System.out.print("Monitoring options : ");
281       monitoringOptions = getProperty("monitoring_options");
282       System.out.println(monitoringOptions+"<br>");
283       System.out.print("Monitoring sampling in seconds : ");
284       monitoringSampling = new Integer JavaDoc(getProperty("monitoring_sampling_in_seconds"));
285       System.out.println(monitoringSampling+"<br>");
286       System.out.print("Monitoring rsh : ");
287       monitoringRsh = getProperty("monitoring_rsh");
288       System.out.println(monitoringRsh+"<br>");
289       System.out.print("Monitoring scp : ");
290       monitoringScp = getProperty("monitoring_scp");
291       System.out.println(monitoringScp+"<br>");
292       System.out.print("Monitoring Gnuplot Terminal : ");
293       monitoringGnuPlot = getProperty("monitoring_gnuplot_terminal");
294       System.out.println(monitoringGnuPlot+"<br>");
295
296       // Create a new URLGenerator according to the version the user has chosen
297
System.out.println("\n");
298       useVersion = getProperty("httpd_use_version");
299       if (useVersion.compareTo("PHP") == 0)
300         urlGen = new URLGeneratorPHP(webSiteName, webSitePort, PHPHTMLPath, PHPScriptPath);
301 // else if (useVersion.compareTo("EJB") == 0)
302
// urlGen = new URLGeneratorEJB(webSiteName, webSitePort, EJBHTMLPath, EJBScriptPath);
303
else if (useVersion.compareTo("Servlets") == 0)
304       urlGen = new URLGeneratorServlets(webSiteName, webSitePort, ServletsHTMLPath, ServletsScriptPath);
305       else
306       {
307         System.err.println("Sorry but '"+useVersion+"' is not supported. Only PHP, EJB and Servlets are accepted.");
308         return null;
309       }
310       System.out.println("Using "+useVersion+" version.<br>");
311     }
312     catch (Exception JavaDoc e)
313     {
314       System.err.println("Error while checking database.properties: "+e.getMessage());
315       return null;
316     }
317     return urlGen;
318   }
319
320
321   /**
322    * Get the web server name
323    *
324    * @return web server name
325    */

326   public String JavaDoc getWebServerName()
327   {
328     return webSiteName;
329   }
330
331   /**
332    * Get the CJDBC server name
333    *
334    * @return CJDBC server name
335    */

336   public String JavaDoc getCJDBCServerName()
337   {
338     return cjdbcSiteName;
339   }
340
341
342   /**
343    * Get the database server name
344    *
345    * @return database server name
346    */

347   public String JavaDoc getDBServerName()
348   {
349     return dbServerName;
350   }
351
352
353   /**
354    * Get the total number ofauthors given in the database_number_of_authors field
355    *
356    * @return total number of authors
357    */

358   public int getNbOfAuthors()
359   {
360     return nbOfAuthors.intValue();
361   }
362
363
364   /**
365    * Get the total number of users given in the database_number_of_users field
366    *
367    * @return total number of users
368    */

369   public int getNbOfUsers()
370   {
371     return nbOfUsers.intValue();
372   }
373
374
375   /**
376    * Get the percentage of emulated users that should be authors (given in the workload_percentage_of_author field)
377    *
378    * @return percentage of authors
379    */

380   public int getPercentageOfAuthors()
381   {
382     return percentOfAuthors;
383   }
384
385
386   /**
387    * Get the dictionary file used to build the stories.
388    * This file is a plain text file with one word per line.
389    *
390    * @return dictionary file used to build the stories
391    */

392   public String JavaDoc getStoryDictionary()
393   {
394     return storyDictionary;
395   }
396
397
398   /**
399    * Get the maximum story length given in the database_story_maximum_length field
400    *
401    * @return maximum story length
402    */

403   public int getStoryMaximumLength()
404   {
405     return storyMaxLength.intValue();
406   }
407
408
409   /**
410    * Get the year of the oldest story given in the database_oldest_story_year field
411    *
412    * @return year of the oldest story
413    */

414   public int getOldestStoryYear()
415   {
416     return oldestStoryYear.intValue();
417   }
418
419
420   /**
421    * Get the month of the oldest story given in the database_oldest_story_month field
422    *
423    * @return month of the oldest story
424    */

425   public int getOldestStoryMonth()
426   {
427     return oldestStoryMonth.intValue();
428   }
429
430
431   /**
432    * Get the maximum comment length given in the comment_max_length field
433    *
434    * @return maximum comment length
435    */

436   public int getCommentMaxLength()
437   {
438     return commentMaxLength.intValue();
439   }
440
441
442   /**
443    * Get the user transition table file name given in the workload_user_transition_table field
444    *
445    * @return user transition table file name
446    */

447   public String JavaDoc getUserTransitionTable()
448   {
449     return userTransitionTable;
450   }
451
452
453   /**
454    * Get the author transition table file name given in the workload_author_transition_table field
455    *
456    * @return user transition table file name
457    */

458   public String JavaDoc getAuthorTransitionTable()
459   {
460     return authorTransitionTable;
461   }
462
463
464   /**
465    * Get the number of columns in the transition table
466    *
467    * @return number of columns
468    */

469   public int getNbOfColumns()
470   {
471     return nbOfColumns;
472   }
473
474
475   /**
476    * Get the number of rows in the transition table
477    *
478    * @return number of rows
479    */

480   public int getNbOfRows()
481   {
482     return nbOfRows;
483   }
484
485
486   /**
487    * Returns true if TPC-W compatible think time must be used,
488    * false if transition matrix think time has to be used.
489    *
490    * @return if think time should be TPC-W compatible
491    */

492   public boolean useTPCWThinkTime()
493   {
494     return useTPCWThinkTime;
495   }
496
497
498   /**
499    * Get the number of stories to display per page (when browsing) given in the number_of_storis_per_page field
500    *
501    * @return number of stories to display per page
502    */

503   public int getNbOfStoriesPerPage()
504   {
505     return nbOfStoriesPerPage;
506   }
507
508
509   /**
510    * Get the total number of clients user sessions to launch in parallel
511    *
512    * @return total number of clients
513    */

514   public int getNbOfClients()
515   {
516     return nbOfClients;
517   }
518
519
520   /**
521    * Get a vector of remote node names to launch clients on
522    *
523    * @return vector of remote node names to launch clients on
524    */

525   public Vector JavaDoc getRemoteClients()
526   {
527     return remoteClients;
528   }
529
530
531   /**
532    * Get a vector of remote node names to launch clients on
533    *
534    * @return vector of remote node names to launch clients on
535    */

536   public String JavaDoc getClientsRemoteCommand()
537   {
538     return remoteCommand;
539   }
540
541
542   /**
543    * Get the maximum number of transitions a client may perform
544    *
545    * @return maximum number of transitions
546    */

547   public int getMaxNbOfTransitions()
548   {
549     return maxNbOfTransitions;
550   }
551
552
553   /**
554    * Get up ramp time in milliseconds
555    *
556    * @return up ramp time
557    */

558   public int getUpRampTime()
559   {
560     return upTime;
561   }
562
563
564   /**
565    * Get up ramp slowdown factor
566    *
567    * @return up ramp slowdown
568    */

569   public float getUpRampSlowdown()
570   {
571     return upSlowdown;
572   }
573
574
575   /**
576    * Get session time in milliseconds
577    *
578    * @return session time
579    */

580   public int getSessionTime()
581   {
582     return sessionTime;
583   }
584
585
586   /**
587    * Get down ramp time in milliseconds
588    *
589    * @return down ramp time
590    */

591   public int getDownRampTime()
592   {
593     return downTime;
594   }
595
596
597   /**
598    * Get down ramp slowdown factor
599    *
600    * @return down ramp slowdown
601    */

602   public float getDownRampSlowdown()
603   {
604     return downSlowdown;
605   }
606
607
608   /**
609    * Get the monitoring debug level. Level is defined as follow: <pre>
610    * 0 = no debug message
611    * 1 = just error messages
612    * 2 = error messages+HTML pages
613    * 3 = everything!
614    * </pre>
615    *
616    * @return monitoring program full path and name
617    */

618   public int getMonitoringDebug()
619   {
620     return monitoringDebug.intValue();
621   }
622
623
624   /**
625    * Get the monitoring program full path and name
626    *
627    * @return monitoring program full path and name
628    */

629   public String JavaDoc getMonitoringProgram()
630   {
631     return monitoringProgram;
632   }
633
634
635   /**
636    * Get the monitoring program options
637    *
638    * @return monitoring program options
639    */

640   public String JavaDoc getMonitoringOptions()
641   {
642     return monitoringOptions;
643   }
644
645
646   /**
647    * Get the interval of time in seconds between 2 sample collection by the monitoring program.
648    *
649    * @return monitoring program sampling time in seconds
650    */

651   public Integer JavaDoc getMonitoringSampling()
652   {
653     return monitoringSampling;
654   }
655
656
657   /**
658    * Get the rsh program path that should be used to run the monitoring program remotely
659    *
660    * @return rsh program path
661    */

662   public String JavaDoc getMonitoringRsh()
663   {
664     return monitoringRsh;
665   }
666
667   /**
668    * Get scp program path that should be used to fetch remote files
669    *
670    * @return rsh program path
671    */

672   public String JavaDoc getMonitoringScp()
673   {
674     return monitoringScp;
675   }
676
677
678   /**
679    * Get the terminal to use for gnuplot. Usually it is set to 'gif' or 'jpeg'.
680    *
681    * @return gnuplot terminal
682    */

683   public String JavaDoc getGnuPlotTerminal()
684   {
685     return monitoringGnuPlot;
686   }
687
688 }
689
Popular Tags