1 package org.jgroups.tests.adaptjms; 2 3 import org.apache.log4j.Logger; 4 5 import javax.jms.*; 6 import javax.naming.InitialContext ; 7 import java.io.BufferedReader ; 8 import java.io.FileNotFoundException ; 9 import java.io.FileReader ; 10 import java.io.IOException ; 11 import java.net.InetAddress ; 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 ConnectionFactory factory; 42 InitialContext ctx; 43 TopicConnection conn; 44 TopicSession session; 45 TopicPublisher pub; 46 Topic topic; 47 String topic_name="topic/testTopic"; 48 49 for(int i=0; i < args.length; i++) { 50 if("-sender".equals(args[i])) { 51 sender=true; 52 continue; 53 } 54 if("-receiver".equals(args[i])) { 55 sender=false; 56 continue; 57 } 58 if("-config".equals(args[i])) { 59 config=args[++i]; 60 continue; 61 } 62 help(); 63 return; 64 } 65 66 67 68 try { 69 fileReader=new BufferedReader (new FileReader (config)); 70 while((line=fileReader.readLine()) != null) { 71 if(line.startsWith("#")) 72 continue; 73 else if(line.startsWith("NUM_MSGS=")) { 74 num_msgs=Integer.parseInt(line.substring(line.indexOf('=') + 1, 75 line.indexOf(';'))); 76 } 77 else if(line.startsWith("MSG_SIZE=")) { 78 msg_size=Integer.parseInt(line.substring(line.indexOf('=') + 1, 79 line.indexOf(';'))); 80 } 81 else if(line.startsWith("GRPMEMBERS=")) { 82 grpMembers=Integer.parseInt(line.substring(line.indexOf('=') + 1, 83 line.indexOf(';'))); 84 } 85 else if(line.startsWith("NUM_SENDERS=")) { 86 num_senders=Integer.parseInt(line.substring(line.indexOf('=') + 1, 87 line.indexOf(';'))); 88 } 89 else if(line.startsWith("LOG_INTERVAL=")) { 90 log_interval=Long.parseLong(line.substring(line.indexOf('=') + 1, 91 line.indexOf(';'))); 92 } 93 else if(line.startsWith("TOPIC=")) { 94 topic_name=line.substring(line.indexOf('=') + 1, line.indexOf(';')); 95 } 96 else if(line.startsWith("GNUPLOT_OUTPUT=")) { 97 if(System.getProperty("gnuplot_output") == null) { 99 String gnuplot_output=line.substring(line.indexOf('=') + 1, 100 line.indexOf(';')).trim(); 101 if(gnuplot_output != null) 102 System.setProperty("gnuplot_output", gnuplot_output); 103 } 104 } 105 } 106 fileReader.close(); 107 108 System.out.println("Javagroups test:"); 109 String s="Initial params parsing completed. Starting test" 110 + " with these values:\n" 111 + "Sender:" + sender + " num_msgs:" + num_msgs 112 + " Size(bytes):" + msg_size + " # Mbrs:" + grpMembers 113 + " Senders: " + num_senders 114 + "\nLog interval: " + log_interval + '\n'; 115 116 System.out.println(s); 117 Logger.getLogger(Test.class).info("main(): " + s); 118 119 ctx=new InitialContext (); 120 factory=(ConnectionFactory)ctx.lookup("ConnectionFactory"); 121 conn=((TopicConnectionFactory)factory).createTopicConnection(); 122 session=conn.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); 123 topic=(Topic)ctx.lookup(topic_name); 124 pub=session.createPublisher(topic); 125 new JmsTester(conn, session, topic, pub, sender, num_msgs, 126 msg_size, grpMembers, num_senders, 127 log_interval).initialize(); 128 } 129 catch(FileNotFoundException notFound) { 130 System.err.println("File not found.\n" + notFound); 131 } 132 catch(IOException ioError) { 133 System.err.println(ioError); 134 } 135 catch(Exception ex) { 136 ex.printStackTrace(); 137 } 138 } 139 140 141 142 public static List parseCommaDelimitedList(String s) throws Exception { 143 List retval=new ArrayList (); 144 StringTokenizer tok; 145 InetAddress host; 146 147 if(s == null) return null; 148 tok=new StringTokenizer (s, ","); 149 while(tok.hasMoreTokens()) { 150 host=InetAddress.getByName(tok.nextToken()); 151 retval.add(host); 152 } 153 return retval; 154 } 155 156 static void help() { 157 System.out.println("Test [-help] ([-sender] | [-receiver]) [-config <config file>]"); 158 } 159 } 160 | Popular Tags |