001: /*
002: * <copyright>
003: *
004: * Copyright 2002-2004 BBNT Solutions, LLC
005: * under sponsorship of the Defense Advanced Research Projects
006: * Agency (DARPA).
007: *
008: * You can redistribute this software and/or modify it under the
009: * terms of the Cougaar Open Source License as published on the
010: * Cougaar Open Source Website (www.cougaar.org).
011: *
012: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
013: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
014: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
015: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
016: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
017: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
018: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
019: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
020: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
021: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
022: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
023: *
024: * </copyright>
025: */
026:
027: package org.cougaar.yp.examples;
028:
029: import org.cougaar.yp.*;
030:
031: import org.uddi4j.client.*;
032: import org.uddi4j.transport.*;
033:
034: import org.w3c.dom.Element;
035:
036: import java.io.*;
037: import java.net.*;
038: import java.util.*;
039:
040: import org.cougaar.core.component.*;
041:
042: import org.cougaar.core.mts.*;
043: import org.cougaar.core.agent.*;
044: import org.cougaar.core.agent.service.MessageSwitchService;
045:
046: import org.cougaar.core.blackboard.*;
047: import org.cougaar.core.service.BlackboardService;
048: import org.cougaar.core.plugin.*;
049: import org.cougaar.util.*;
050:
051: import org.cougaar.util.log.*;
052:
053: import org.uddi4j.*;
054: import org.uddi4j.client.*;
055: import org.uddi4j.datatype.*;
056: import org.uddi4j.datatype.assertion.*;
057: import org.uddi4j.datatype.binding.*;
058: import org.uddi4j.datatype.business.*;
059: import org.uddi4j.datatype.service.*;
060: import org.uddi4j.datatype.tmodel.*;
061: import org.uddi4j.request.*;
062: import org.uddi4j.response.*;
063: import org.uddi4j.util.*;
064:
065: /** A plugin which uses large numbers of blocking YP Service queries to
066: * try to crush the YPServer. Also good for testing interactions
067: * with blackboard, etc. Argument is a tag used for diagnostics. Also,
068: * if the parameter is "Y", it'll make 10 YP queries per execute cycle instead
069: * of just 1.
070: **/
071: public class YPBasher extends ComponentPlugin {
072:
073: String user = "cougaar";
074: String pass = "cougaarPass";
075: static String sampleName = "Sample Co";
076: static String sampleName2 = "Second Co";
077:
078: IncrementalSubscription sub;
079: YPService yps;
080: YPProxy yp;
081: long count = 0L;
082: long total = 0L;
083:
084: private Object arg = null;
085:
086: public void setParameter(Object p) {
087: if (p != null) {
088: if (p instanceof Collection) {
089: Iterator it = ((Collection) p).iterator();
090: Object ma = it.next();
091: if (ma instanceof String) {
092: arg = (String) ma;
093: } else {
094: System.err.println("First parameter not a string! "
095: + ma);
096: }
097: } else {
098: System.err.println("Parameter not a Collection! " + p);
099: }
100: } else {
101: System.err
102: .println("YPTest requires a parameter which names a YPServer agent!");
103: }
104: }
105:
106: public void setYPService(YPService yps) {
107: yps = (YPService) getServiceBroker().getService(this ,
108: YPService.class, null);
109: this .yp = yps.getAutoYP("A");
110: }
111:
112: private Integer zing = new Integer(11);
113:
114: protected void setupSubscriptions() {
115: sub = (IncrementalSubscription) blackboard
116: .subscribe(new UnaryPredicate() {
117: public boolean execute(Object o) {
118: return o instanceof Integer;
119: }
120: });
121: blackboard.publishAdd(zing);
122: }
123:
124: public void execute() {
125: System.err.println("*");
126: if (arg.equals("Y")) {
127: for (int i = 0; i < 10; i++) {
128: bash();
129: }
130: } else {
131: bash();
132: }
133: blackboard.publishChange(zing);
134: }
135:
136: void bash() {
137: // issue the query
138: Vector names = new Vector();
139: names.add(new Name("S"));
140:
141: // Setting FindQualifiers to 'caseSensitiveMatch'
142: FindQualifiers findQualifiers = new FindQualifiers();
143: Vector qualifier = new Vector();
144: qualifier.add(new FindQualifier("caseSensitiveMatch"));
145: findQualifiers.setFindQualifierVector(qualifier);
146: long st = System.currentTimeMillis();
147: count++;
148: System.err.println("[" + arg + " Open " + count + "]");
149: YPFuture f = yp.find_business(names, null, null, null, null,
150: findQualifiers, 5);
151: // get result
152: //System.err.println("Closing query "+count); //+": "+fut
153: try {
154: Object o = f.get();
155: System.err.println("[" + arg + " Closed " + count + "]");
156: if (o instanceof BusinessList) {
157: BusinessList businessList = (BusinessList) o;
158:
159: Vector businessInfoVector = businessList
160: .getBusinessInfos().getBusinessInfoVector();
161: for (int i = 0; i < businessInfoVector.size(); i++) {
162: BusinessInfo businessInfo = (BusinessInfo) businessInfoVector
163: .elementAt(i);
164:
165: // Print name for each business
166: //System.err.println("report "+count+": business " + i + " = " + businessInfo.getNameString());
167: }
168: } else {
169: System.err
170: .println("Didn't get a BusinessList response: "
171: + o);
172: }
173: } catch (Exception e) {
174: System.err.println("Error reporting on " + f);
175: e.printStackTrace();
176: }
177:
178: long ft = System.currentTimeMillis();
179:
180: total = total + (ft - st);
181: double rate = (((double) count) / total) * 1000.0;
182: System.err.println("Basher rate=" + rate + "t/s");
183: }
184:
185: }
|