1 package org.jgroups.tests.adaptudp; 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.DatagramSocket ; 10 import java.net.InetAddress ; 11 import java.net.MulticastSocket ; 12 import java.util.ArrayList ; 13 import java.util.List ; 14 import java.util.StringTokenizer ; 15 16 25 public class Test { 26 public static int mcast_port=7777; 27 public static String mcast_addr="228.8.8.8"; 28 public static int grpMembers=4; 29 30 public static void main(String [] args) { 31 String config="config.txt"; 32 BufferedReader fileReader; 33 String line; 34 35 boolean sender=false; 36 int num_msgs=1000; 37 int msg_size=500; 38 39 int num_senders=1; 40 long log_interval=1000; 41 42 43 MulticastSocket recv_sock; 44 DatagramSocket send_sock; 45 46 for(int i=0; i < args.length; i++) { 47 if("-sender".equals(args[i])) { 48 sender=true; 49 continue; 50 } 51 if("-receiver".equals(args[i])) { 52 sender=false; 53 continue; 54 } 55 if("-config".equals(args[i])) { 56 config=args[++i]; 57 continue; 58 } 59 help(); 60 return; 61 } 62 63 64 65 try { 66 fileReader=new BufferedReader (new FileReader (config)); 67 while((line=fileReader.readLine()) != null) { 68 if(line.startsWith("#")) 69 continue; 70 else if(line.startsWith("NUM_MSGS=")) { 71 num_msgs=Integer.parseInt(line.substring(line.indexOf('=') + 1, 72 line.indexOf(';'))); 73 } 74 else if(line.startsWith("MSG_SIZE=")) { 75 msg_size=Integer.parseInt(line.substring(line.indexOf('=') + 1, 76 line.indexOf(';'))); 77 } 78 else if(line.startsWith("GRPMEMBERS=")) { 79 grpMembers=Integer.parseInt(line.substring(line.indexOf('=') + 1, 80 line.indexOf(';'))); 81 } 82 else if(line.startsWith("NUM_SENDERS=")) { 83 num_senders=Integer.parseInt(line.substring(line.indexOf('=') + 1, 84 line.indexOf(';'))); 85 } 86 else if(line.startsWith("LOG_INTERVAL=")) { 87 log_interval=Long.parseLong(line.substring(line.indexOf('=') + 1, 88 line.indexOf(';'))); 89 } 90 else if(line.startsWith("GNUPLOT_OUTPUT=")) { 91 if(System.getProperty("gnuplot_output") == null) { 93 String gnuplot_output=line.substring(line.indexOf('=') + 1, 94 line.indexOf(';')).trim(); 95 if(gnuplot_output != null) 96 System.setProperty("gnuplot_output", gnuplot_output); 97 } 98 } 99 } 100 fileReader.close(); 101 102 System.out.println("Javagroups test:"); 103 String s="Initial params parsing completed. Starting test" 104 + " with these values:\n" 105 + "Sender:" + sender + " num_msgs:" + num_msgs 106 + " Size(bytes):" + msg_size + " # Mbrs:" + grpMembers 107 + " Senders: " + num_senders 108 + "\nLog interval: " + log_interval + '\n'; 109 110 System.out.println(s); 111 Logger.getLogger(Test.class).info("main(): " + s); 112 113 recv_sock=new MulticastSocket (mcast_port); 114 recv_sock.joinGroup(InetAddress.getByName(mcast_addr)); 115 116 send_sock=new DatagramSocket (); 117 118 new UdpTester(recv_sock, send_sock, sender, num_msgs, 119 msg_size, grpMembers, num_senders, 120 log_interval).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 |