001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019:
020: package samples.userguide;
021:
022: public class ThreadedClient {
023:
024: public static final int STATELESS = 0;
025: public static final int SOAP_SESSION = 1;
026: public static final int SIMPLE_CLIENT_SESSION = 2;
027: public static final int TRANSPORT_SESSION = 3;
028:
029: private int session = STATELESS;
030:
031: /**
032: * @param args 1: epr
033: * 2: operation
034: * 3: number of requests
035: * 4: load
036: * 5: number of clients
037: * 6: session (client | transport)
038: */
039: public static void main(String[] args) {
040: new ThreadedClient().work();
041: }
042:
043: public void work() {
044:
045: String epr1 = System.getProperty("epr");
046: if (epr1 == null) {
047: epr1 = "http://localhost:8080";
048: }
049: System.out.println("EPR: " + epr1);
050:
051: String op = System.getProperty("op");
052: if (op == null) {
053: op = "sleepOperation";
054: }
055: System.out.println("Operation: " + op);
056:
057: long requests = 10;
058: String requestsProp = System.getProperty("req");
059: if (requestsProp != null) {
060: requests = Long.parseLong(requestsProp);
061: }
062: System.out.println("Number of requests: " + requests);
063:
064: String loadParameter = System.getProperty("load");
065: if (loadParameter == null) {
066: loadParameter = "1000";
067: }
068: System.out.println("Load: " + loadParameter);
069:
070: long msgSize = 0;
071: String msgSizeProp = System.getProperty("msg");
072: if (msgSizeProp != null) {
073: msgSize = Long.parseLong(msgSizeProp);
074: }
075: System.out.println("Number of dummy elements in the message: "
076: + msgSize);
077:
078: String sessionProp = System.getProperty("session");
079: if (sessionProp == null) {
080: session = STATELESS;
081: } else {
082: if (sessionProp.equalsIgnoreCase("client")) {
083: session = SIMPLE_CLIENT_SESSION;
084: } else if (sessionProp.equalsIgnoreCase("transport")) {
085: session = TRANSPORT_SESSION;
086: }
087: }
088:
089: int clients = 2;
090: String clientsProp = System.getProperty("t");
091: if (clientsProp != null) {
092: clients = Integer.parseInt(clientsProp);
093: }
094: System.out.println("Number of client threads: " + clients);
095:
096: ServiceInvoker[] invokers = new ServiceInvoker[clients];
097:
098: for (int i = 0; i < clients; i++) {
099:
100: ServiceInvoker invoker = new ServiceInvoker(epr1, op);
101:
102: if (session != STATELESS) {
103: invoker.setStatefull(true);
104: }
105:
106: invoker.setInvokerName("CLIENT " + i);
107: invoker.setIterations(requests);
108: invoker.setLoad(loadParameter);
109: invoker.addDummyElements(msgSize);
110:
111: if (session == SIMPLE_CLIENT_SESSION) {
112: invoker.setClientSessionID("CLIENT " + i);
113: }
114:
115: invokers[i] = invoker;
116: }
117:
118: long t1 = System.currentTimeMillis();
119:
120: for (int i = 0; i < clients; i++) {
121: invokers[i].start();
122: }
123:
124: try {
125: for (int i = 0; i < clients; i++) {
126: invokers[i].join();
127: }
128: } catch (InterruptedException e) {
129: System.out
130: .println("ERROR: A client thread is interrupted while sending requests.");
131: }
132:
133: long t2 = System.currentTimeMillis();
134:
135: System.out
136: .println("\n================================================================\n");
137:
138: for (int i = 0; i < clients; i++) {
139: System.out.println(invokers[i].getInvokerName()
140: + " completed requests in "
141: + invokers[i].getRunningTime() + " milliseconds.");
142: }
143:
144: System.out
145: .println("Time taken for completing all the requests is "
146: + (t2 - t1) + " milliseconds.");
147:
148: }
149: }
|