1 2 package samplehttp.client; 3 4 import java.io.*; 6 7 import java.net.*; 8 9 10 11 12 13 class SenderThread extends Thread { 14 15 private String m_host; 16 private int m_port; 17 private String m_treattime; 18 private int m_loops; 19 private long m_wait; 20 private long m_time; 21 private int m_fejb; 22 23 public SenderThread(String host, int port, String treattime, String wait, int loops, int fejb){ 24 m_host = host; 25 m_port = port; 26 m_treattime = treattime; 27 Long w = new Long(wait.trim()); 28 m_wait = w.longValue(); 29 m_loops = loops; 30 m_fejb = fejb; 31 } 32 33 public void run() { 34 System.out.println("Running a SenderThread..."); 35 long d_begin = System.currentTimeMillis(); 36 Sender s = new Sender(m_host,"samplehttp/SampleServlet", m_port, m_treattime, m_fejb ); 37 try{ 38 for (int l = 0; l < m_loops; l++) { 39 s.execute(); 40 Thread.currentThread().sleep(m_wait); 41 } 42 }catch(Exception e) { 43 System.out.println(">>> SenderThread. Exception caught = "+e); 44 } 45 long d_end = System.currentTimeMillis(); 46 m_time = d_end - d_begin; 47 } 48 49 public long getTime(){ 50 return m_time; 51 } 52 } 53 54 public class SampleClient { 55 56 57 private static final int m_MAXTHREADS = 500; 58 private static int poolsize = 1; 59 private static int port; 60 private static int loops = 1; 61 private static String wait = "1000"; private static String treattime = "10"; private static String host; 64 private static int flgejb = 0; 65 66 public static void main(String args[]) { 67 68 for (int argn = 0; argn < args.length; argn++) { 70 String s_arg = args[argn]; 71 String sarg; 72 Integer i_arg; 73 74 if ((argn+1<args.length) && (s_arg.equals("-h") == true)) { 75 host = args[++argn]; 76 77 } else if ((argn+1<args.length) && (s_arg.equals("-p") == true)) { 78 s_arg = args[++argn]; 79 i_arg = java.lang.Integer.valueOf(s_arg); 80 port = i_arg.intValue(); 81 } else if ((argn+1<args.length) && (s_arg.equals("-n") == true)) { 82 s_arg = args[++argn]; 83 i_arg = java.lang.Integer.valueOf(s_arg); 84 poolsize = i_arg.intValue(); 85 } else if ((argn+1<args.length) && (s_arg.equals("-l") == true)) { 86 s_arg = args[++argn]; 87 i_arg = java.lang.Integer.valueOf(s_arg); 88 loops = i_arg.intValue(); 89 } else if ((argn+1<args.length) && (s_arg.equals("-t") == true)) { 90 s_arg = args[++argn]; 91 treattime = s_arg; 92 } else if ((argn+1<args.length) && (s_arg.equals("-w") == true)) { 93 s_arg = args[++argn]; 94 wait = s_arg; 95 96 } else if (s_arg.equals("-ejb") == true) { 97 flgejb = 1; 98 } else if (s_arg.equals("-ejbl") == true) { 99 flgejb = 2; 100 } else if (s_arg.equals("-ejbc") == true) { 101 flgejb = 3; 102 } else if (s_arg.equals("-?") == true) { 103 usage(); 104 System.exit(0); 105 } else { 106 usage(); 107 System.exit(2); 108 } 109 } 110 111 long tbegin = System.currentTimeMillis(); 112 SenderThread t_thr[] = new SenderThread [m_MAXTHREADS]; 114 long ttime[] = new long[m_MAXTHREADS]; 115 for (int p = 0; p < poolsize; p++) { 116 t_thr[p] = new SenderThread(host, port, treattime, wait, loops, flgejb); 117 t_thr[p].start(); 118 } 119 for (int p = 0; p < poolsize; p++) { 120 try { 121 t_thr[p].join(); 122 ttime[p] = t_thr[p].getTime(); 123 124 } catch (InterruptedException e) { 125 System.out.println("ERROR: Problem in SenderThread.join():\n"+e); 126 System.exit(2); 127 } 128 } 129 long tend = System.currentTimeMillis(); 130 long time = tend - tbegin; 131 System.out.println("Fin de l'essai avec nb clients= "+ poolsize+ " timetowait betwwen requests = "+wait); 132 System.out.println("nb loops in client = "+loops+ " treatment time in servlet = "+treattime); 133 System.out.print("using ejb = "); 134 if (flgejb == 0) 135 System.out.println("no"); 136 if (flgejb == 1) 137 System.out.println("yes via remote interface"); 138 if (flgejb == 2) 139 System.out.println("yes via local interface"); 140 if (flgejb == 3) 141 System.out.println("yes via remote interface + getConnection"); 142 143 System.out.println("Time : "+time); 144 } 145 146 147 private static void usage() { 148 System.out.println("Usage: jclient -cp ... samplehttp.client.SampleClient <args>"); 149 System.out.println(" -h <host> hostname"); 150 System.out.println(" -p <port> port number "); 151 System.out.println(" -n <thread> number of client threads"); 152 System.out.println(" -t <treatmenttime> treatment time in servlet"); 153 System.out.println(" -w <timetowait> time to wait in thread client"); 154 System.out.println(" -l <nbloops> nb loops in each thread client"); 155 System.out.println(" -ejb call ejb in servlet"); 156 System.out.println(" -ejbl call ejb via local interface in servlet"); 157 System.out.println(" -ejbc call ejb + getconnectionin servlet"); 158 159 } 160 161 } 162 163 | Popular Tags |