1 package org.jgroups.tests.adapttcp; 2 3 import org.apache.log4j.Logger; 4 5 import java.io.BufferedReader ; 6 import java.io.FileNotFoundException ; 7 import java.io.FileReader ; 8 import java.io.IOException ; 9 import java.net.InetAddress ; 10 import java.net.ServerSocket ; 11 import java.util.ArrayList ; 12 import java.util.List ; 13 import java.util.StringTokenizer ; 14 15 24 public class Test { 25 public static int srv_port=7777; 26 public static int grpMembers=4; 27 28 public static void main(String [] args) { 29 String config="config.txt"; 30 BufferedReader fileReader; 31 String line; 32 33 boolean sender=false; 34 int num_msgs=1000; 35 int msg_size=500; 36 37 int num_senders=1; 38 long log_interval=1000; 39 40 41 ServerSocket srv_sock; 42 List nodes=new ArrayList (); 44 for(int i=0; i < args.length; i++) { 45 if("-sender".equals(args[i])) { 46 sender=true; 47 continue; 48 } 49 if("-receiver".equals(args[i])) { 50 sender=false; 51 continue; 52 } 53 if("-config".equals(args[i])) { 54 config=args[++i]; 55 continue; 56 } 57 help(); 58 return; 59 } 60 61 62 63 try { 64 fileReader=new BufferedReader (new FileReader (config)); 65 while((line=fileReader.readLine()) != null) { 66 if(line.startsWith("#")) 67 continue; 68 else if(line.startsWith("NUM_MSGS=")) { 69 num_msgs=Integer.parseInt(line.substring(line.indexOf('=') + 1, 70 line.indexOf(';'))); 71 } 72 else if(line.startsWith("MSG_SIZE=")) { 73 msg_size=Integer.parseInt(line.substring(line.indexOf('=') + 1, 74 line.indexOf(';'))); 75 } 76 else if(line.startsWith("GRPMEMBERS=")) { 77 grpMembers=Integer.parseInt(line.substring(line.indexOf('=') + 1, 78 line.indexOf(';'))); 79 } 80 else if(line.startsWith("NUM_SENDERS=")) { 81 num_senders=Integer.parseInt(line.substring(line.indexOf('=') + 1, 82 line.indexOf(';'))); 83 } 84 else if(line.startsWith("LOG_INTERVAL=")) { 85 log_interval=Long.parseLong(line.substring(line.indexOf('=') + 1, 86 line.indexOf(';'))); 87 } 88 else if(line.startsWith("CLUSTER=")) { 89 nodes=parseCommaDelimitedList(line.substring(line.indexOf('=') + 1, 90 line.indexOf(';')).trim()); 91 92 } 93 else if(line.startsWith("GNUPLOT_OUTPUT=")) { 94 if(System.getProperty("gnuplot_output") == null) { 96 String 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 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 srv_sock=new ServerSocket (srv_port); 117 118 new TcpTester(sender, num_msgs, 119 msg_size, grpMembers, num_senders, 120 log_interval, srv_sock, nodes).initialize(); 121 } 122 catch(FileNotFoundException notFound) { 123 System.err.println("File not found.\n" + notFound); 124 } 125 catch(IOException ioError) { 126 System.err.println(ioError); 127 } 128 catch(Exception ex) { 129 ex.printStackTrace(); 130 } 131 } 132 133 134 135 public static List parseCommaDelimitedList(String s) throws Exception { 136 List retval=new ArrayList (); 137 StringTokenizer tok; 138 InetAddress host; 139 140 if(s == null) return null; 141 tok=new StringTokenizer (s, ","); 142 while(tok.hasMoreTokens()) { 143 host=InetAddress.getByName(tok.nextToken()); 144 retval.add(host); 145 } 146 return retval; 147 } 148 149 static void help() { 150 System.out.println("Test [-help] ([-sender] | [-receiver]) [-config <config file>]"); 151 } 152 } 153 | Popular Tags |