001: package samplehttp.client;
002:
003: //Import statements
004: import java.io.*;
005:
006: import java.net.*;
007:
008: class SenderThread extends Thread {
009:
010: private String m_host;
011: private int m_port;
012: private String m_treattime;
013: private int m_loops;
014: private long m_wait;
015: private long m_time;
016: private int m_fejb;
017:
018: public SenderThread(String host, int port, String treattime,
019: String wait, int loops, int fejb) {
020: m_host = host;
021: m_port = port;
022: m_treattime = treattime;
023: Long w = new Long(wait.trim());
024: m_wait = w.longValue();
025: m_loops = loops;
026: m_fejb = fejb;
027: }
028:
029: public void run() {
030: System.out.println("Running a SenderThread...");
031: long d_begin = System.currentTimeMillis();
032: Sender s = new Sender(m_host, "samplehttp/SampleServlet",
033: m_port, m_treattime, m_fejb);
034: try {
035: for (int l = 0; l < m_loops; l++) {
036: s.execute();
037: Thread.currentThread().sleep(m_wait);
038: }
039: } catch (Exception e) {
040: System.out.println(">>> SenderThread. Exception caught = "
041: + e);
042: }
043: long d_end = System.currentTimeMillis();
044: m_time = d_end - d_begin;
045: }
046:
047: public long getTime() {
048: return m_time;
049: }
050: }
051:
052: public class SampleClient {
053:
054: private static final int m_MAXTHREADS = 500;
055: private static int poolsize = 1;
056: private static int port;
057: private static int loops = 1;
058: private static String wait = "1000"; // Wait between 2 requests default = 1second
059: private static String treattime = "10"; // Treatment time in servlet default = 10 ms
060: private static String host;
061: private static int flgejb = 0;
062:
063: public static void main(String args[]) {
064:
065: // Get command args
066: for (int argn = 0; argn < args.length; argn++) {
067: String s_arg = args[argn];
068: String sarg;
069: Integer i_arg;
070:
071: if ((argn + 1 < args.length)
072: && (s_arg.equals("-h") == true)) {
073: host = args[++argn];
074:
075: } else if ((argn + 1 < args.length)
076: && (s_arg.equals("-p") == true)) {
077: s_arg = args[++argn];
078: i_arg = java.lang.Integer.valueOf(s_arg);
079: port = i_arg.intValue();
080: } else if ((argn + 1 < args.length)
081: && (s_arg.equals("-n") == true)) {
082: s_arg = args[++argn];
083: i_arg = java.lang.Integer.valueOf(s_arg);
084: poolsize = i_arg.intValue();
085: } else if ((argn + 1 < args.length)
086: && (s_arg.equals("-l") == true)) {
087: s_arg = args[++argn];
088: i_arg = java.lang.Integer.valueOf(s_arg);
089: loops = i_arg.intValue();
090: } else if ((argn + 1 < args.length)
091: && (s_arg.equals("-t") == true)) {
092: s_arg = args[++argn];
093: treattime = s_arg;
094: } else if ((argn + 1 < args.length)
095: && (s_arg.equals("-w") == true)) {
096: s_arg = args[++argn];
097: wait = s_arg;
098:
099: } else if (s_arg.equals("-ejb") == true) {
100: flgejb = 1;
101: } else if (s_arg.equals("-ejbl") == true) {
102: flgejb = 2;
103: } else if (s_arg.equals("-ejbc") == true) {
104: flgejb = 3;
105: } else if (s_arg.equals("-?") == true) {
106: usage();
107: System.exit(0);
108: } else {
109: usage();
110: System.exit(2);
111: }
112: }
113:
114: long tbegin = System.currentTimeMillis();
115: // Start pool of client threads
116: SenderThread t_thr[] = new SenderThread[m_MAXTHREADS];
117: long ttime[] = new long[m_MAXTHREADS];
118: for (int p = 0; p < poolsize; p++) {
119: t_thr[p] = new SenderThread(host, port, treattime, wait,
120: loops, flgejb);
121: t_thr[p].start();
122: }
123: for (int p = 0; p < poolsize; p++) {
124: try {
125: t_thr[p].join();
126: ttime[p] = t_thr[p].getTime();
127:
128: } catch (InterruptedException e) {
129: System.out
130: .println("ERROR: Problem in SenderThread.join():\n"
131: + e);
132: System.exit(2);
133: }
134: }
135: long tend = System.currentTimeMillis();
136: long time = tend - tbegin;
137: System.out.println("Fin de l'essai avec nb clients= "
138: + poolsize + " timetowait betwwen requests = " + wait);
139: System.out.println("nb loops in client = " + loops
140: + " treatment time in servlet = " + treattime);
141: System.out.print("using ejb = ");
142: if (flgejb == 0)
143: System.out.println("no");
144: if (flgejb == 1)
145: System.out.println("yes via remote interface");
146: if (flgejb == 2)
147: System.out.println("yes via local interface");
148: if (flgejb == 3)
149: System.out
150: .println("yes via remote interface + getConnection");
151:
152: System.out.println("Time : " + time);
153: }
154:
155: private static void usage() {
156: System.out
157: .println("Usage: jclient -cp ... samplehttp.client.SampleClient <args>");
158: System.out.println(" -h <host> hostname");
159: System.out.println(" -p <port> port number ");
160: System.out
161: .println(" -n <thread> number of client threads");
162: System.out
163: .println(" -t <treatmenttime> treatment time in servlet");
164: System.out
165: .println(" -w <timetowait> time to wait in thread client");
166: System.out
167: .println(" -l <nbloops> nb loops in each thread client");
168: System.out.println(" -ejb call ejb in servlet");
169: System.out
170: .println(" -ejbl call ejb via local interface in servlet");
171: System.out
172: .println(" -ejbc call ejb + getconnectionin servlet");
173:
174: }
175:
176: }
|