001: /*
002: * Copyright 2000,2005 wingS development team.
003: *
004: * This file is part of wingS (http://wingsframework.org).
005: *
006: * wingS is free software; you can redistribute it and/or modify
007: * it under the terms of the GNU Lesser General Public License
008: * as published by the Free Software Foundation; either version 2.1
009: * of the License, or (at your option) any later version.
010: *
011: * Please see COPYING for the complete licence.
012: */
013: package org.wings.recorder;
014:
015: import java.io.FileOutputStream;
016: import java.io.PrintStream;
017: import java.util.Iterator;
018: import java.util.LinkedList;
019: import java.util.List;
020:
021: public class Simulator {
022: public static void main(String[] args) {
023: int index = 0;
024: boolean fail = false;
025:
026: float delay = 1.0f;
027: String auth = "BASIC";
028: String userid = "user ";
029: String password = null;
030: int iterations = 1;
031: int ramp = 0;
032:
033: try {
034: while (index < args.length) {
035: if ("-d".equals(args[index])
036: || "--delay".equals(args[index]))
037: delay = new Float(args[index + 1]).floatValue();
038: else if ("-a".equals(args[index])
039: || "--auth".equals(args[index]))
040: auth = args[index + 1];
041: else if ("-u".equals(args[index])
042: || "--userid".equals(args[index]))
043: userid = args[index + 1];
044: else if ("-p".equals(args[index])
045: || "--password".equals(args[index]))
046: password = args[index + 1];
047: else if ("-i".equals(args[index])
048: || "--iterations".equals(args[index]))
049: iterations = new Integer(args[index + 1])
050: .intValue();
051: else if ("-r".equals(args[index])
052: || "--ramp".equals(args[index]))
053: ramp = new Integer(args[index + 1]).intValue();
054: else if ("-o".equals(args[index])
055: || "--output".equals(args[index]))
056: System.setOut(new PrintStream(new FileOutputStream(
057: args[index + 1])));
058: else
059: break;
060:
061: index += 2;
062: }
063: } catch (Exception e) {
064: fail = true;
065: }
066:
067: if (fail || args.length < index + 2) {
068: printUsage();
069: System.exit(1);
070: }
071:
072: String url = args[index];
073: String scriptClassName = args[index + 1];
074:
075: int firstUser;
076: int lastUser;
077: int pos = args[index + 2].indexOf("-");
078: if (pos > -1) {
079: String a = args[index + 2].substring(0, pos);
080: String b = args[index + 2].substring(pos + 1);
081: firstUser = Integer.valueOf(a).intValue();
082: lastUser = Integer.valueOf(b).intValue();
083: } else {
084: firstUser = 1;
085: lastUser = Integer.valueOf(args[index + 2]).intValue();
086: }
087:
088: try {
089: Class scriptClass = Class.forName(scriptClassName);
090:
091: System.out.println("INFO: initializing clients for "
092: + userid + firstUser + " to " + userid + lastUser);
093: List clients = new LinkedList();
094: for (int i = firstUser; i <= lastUser; i++) {
095: Script script = (Script) scriptClass.newInstance();
096: script.setUrl(url);
097: script.setDelay(delay);
098:
099: Client client = new Client();
100: client.init(script);
101: client.setUserid(userid + i);
102: client.setPasswd(password);
103: client.setInitialDelay((i - firstUser) * ramp);
104: client.setIterations(iterations);
105: clients.add(client);
106: }
107:
108: System.out.println("INFO: starting clients");
109: Iterator it = clients.iterator();
110: while (it.hasNext()) {
111: Client client = (Client) it.next();
112: client.start();
113: }
114: } catch (Exception e) {
115: System.err.println(e.getMessage());
116: e.printStackTrace(System.err);
117: }
118: }
119:
120: protected static void printUsage() {
121: System.err
122: .println("usage: simulator [options] url script_class user_range");
123: System.err.println("arguments:");
124: System.err
125: .println(" url url of application client jar with deployment descriptors");
126: System.err
127: .println(" script_class full qualified classname");
128: System.err
129: .println(" user_range 1-'lastUser' or 'firstUser'-'lastUser'");
130: System.err.println("options:");
131: System.err
132: .println(" -d, --delay [0..t] factor, that is applied to the recorded delays");
133: System.err
134: .println(" 0.0 for no delays, 1.0 for same tempo as during recording (default)");
135: System.err
136: .println(" -a, --auth the auth type, one of HTTP, JBoss (more to follow), defaults to HTTP");
137: System.err
138: .println(" -u, --userid the base userid, to which firstUser .. lastUser will be appended, defaults to 'demo'");
139: System.err
140: .println(" -p, --password the password for all users");
141: System.err
142: .println(" -i, --iterations number of iterations a virtual user runs the script, defaults to 'start'");
143: System.err
144: .println(" -r, --ramp load ramp, n'th client is started after n times the delay in ms, default is 0");
145: System.err
146: .println(" -o, --output redirect output to a file");
147: }
148: }
|