KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jgroups > tests > adapt > Test


1 package org.jgroups.tests.adapt;
2
3 import org.apache.log4j.Logger;
4
5 import java.io.BufferedReader JavaDoc;
6 import java.io.FileNotFoundException JavaDoc;
7 import java.io.FileReader JavaDoc;
8 import java.io.IOException JavaDoc;
9
10 /** You start the test by running this class.
11  * It only parses the initial params from the config.txt
12  * file (or any other file you wish to pass as the argument)
13  * and instantiates a new JGroupsTester object.<br>
14  * Use parameters -Xbatch -Xconcurrentio (Solaris specific)
15  * @author Milcan Prica (prica@deei.units.it)
16  * @author Bela Ban (belaban@yahoo.com)
17
18  */

19 public class Test {
20
21     public static void main(String JavaDoc[] args) {
22
23         String JavaDoc config="config.txt";
24         BufferedReader JavaDoc fileReader;
25         String JavaDoc line;
26
27         boolean sender=false;
28         int num_msgs=1000;
29         int msg_size=500;
30         int grpMembers=4;
31         int num_senders=1;
32         String JavaDoc props=null;
33         long log_interval=1000;
34
35
36         for(int i=0; i < args.length; i++) {
37             if("-sender".equals(args[i])) {
38                 sender=true;
39                 continue;
40             }
41             if("-receiver".equals(args[i])) {
42                 sender=false;
43                 continue;
44             }
45             if("-config".equals(args[i])) {
46                 config=args[++i];
47                 continue;
48             }
49             if("-props".equals(args[i])) {
50                 props=args[++i];
51                 continue;
52             }
53             help();
54             return;
55         }
56
57
58
59         try {
60             fileReader=new BufferedReader JavaDoc(new FileReader JavaDoc(config));
61             while((line=fileReader.readLine()) != null) {
62                 if(line.startsWith("#"))
63                     continue;
64                 else if(line.startsWith("NUM_MSGS=")) {
65                     num_msgs=Integer.parseInt(line.substring(line.indexOf('=') + 1,
66                             line.indexOf(';')));
67                 }
68                 else if(line.startsWith("MSG_SIZE=")) {
69                     msg_size=Integer.parseInt(line.substring(line.indexOf('=') + 1,
70                             line.indexOf(';')));
71                 }
72                 else if(line.startsWith("GRPMEMBERS=")) {
73                     grpMembers=Integer.parseInt(line.substring(line.indexOf('=') + 1,
74                             line.indexOf(';')));
75                 }
76                 else if(line.startsWith("NUM_SENDERS=")) {
77                     num_senders=Integer.parseInt(line.substring(line.indexOf('=') + 1,
78                             line.indexOf(';')));
79                 }
80                 else if(line.startsWith("LOG_INTERVAL=")) {
81                     log_interval=Long.parseLong(line.substring(line.indexOf('=') + 1,
82                             line.indexOf(';')));
83                 }
84                 else if(line.startsWith("PROPS=")) {
85                     if(props == null) {
86                         props=line.substring(line.indexOf('=') + 1,
87                                 line.indexOf(';')).trim();
88                     }
89                     else {
90                         System.out.println("-- properties " + props + " given on command line override file properies");
91                     }
92                 }
93                 else if(line.startsWith("GNUPLOT_OUTPUT=")) {
94                     // only parse if not yet set by -Dgnuplot_output=true option (overrides file)
95
if(System.getProperty("gnuplot_output") == null) {
96                         String JavaDoc gnuplot_output=line.substring(line.indexOf('=') + 1,
97                                 line.indexOf(';')).trim();
98                         if(gnuplot_output != null)
99                             System.setProperty("gnuplot_output", gnuplot_output);
100                     }
101                 }
102             }
103             fileReader.close();
104
105             System.out.println("Javagroups test:");
106             String JavaDoc s="Initial params parsing completed. Starting test"
107                     + " with these values:\n"
108                     + "Sender:" + sender + " num_msgs:" + num_msgs
109                     + " Size(bytes):" + msg_size + " # Mbrs:" + grpMembers
110                     + " Senders: " + num_senders
111                     + "\nLog interval: " + log_interval + '\n';
112
113             System.out.println(s);
114             Logger.getLogger(Test.class).info("main(): " + s);
115
116             new JGroupsTester(sender, num_msgs,
117                     msg_size, grpMembers, num_senders, props, log_interval).initialize();
118         }
119         catch(FileNotFoundException JavaDoc notFound) {
120             System.err.println("File not found.\n" + notFound);
121         }
122         catch(IOException JavaDoc ioError) {
123             ioError.printStackTrace();
124         }
125     }
126
127     static void help() {
128         System.out.println("Test [-help] ([-sender] | [-receiver]) [-config <config file>] [-props <stack config>]");
129     }
130 }
131
Popular Tags