001: /*
002: * <copyright>
003: *
004: * Copyright 1997-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: * THIS SOFTWARE IS MODIFIED FOR TESTING QUO_ULTRALLOG INTEGRATION
026: */
027:
028: package org.cougaar.lib.quo.performance;
029:
030: import java.io.FileWriter;
031: import java.io.IOException;
032: import java.util.Vector;
033:
034: import org.cougaar.planning.plugin.legacy.SimplePlugin;
035:
036: /**
037: * This COUGAAR Plugin performs the common task as reading all the parameters
038: * and getting the values that may be common to all the child Plugins
039: */
040:
041: public class CommonUtilPlugin extends SimplePlugin {
042:
043: /**
044: * parsing the plugIn arguments and setting the values
045: */
046: protected String getParameterValue(Vector p, String param) {
047: String strParam = null;
048: for (int i = 0; i < p.size(); i++) {
049: String s = (String) p.elementAt(i);
050: if (s.indexOf(param) != -1) {
051: strParam = s.substring(s.indexOf("=") + 1, s.length());
052: }
053: }
054:
055: return strParam;
056: }
057:
058: protected int getParameterIntValue(Vector p, String param) {
059: int returnVal = -1;
060: String str = getParameterValue(p, param);
061: if (str != null)
062: returnVal = Integer.parseInt(str);
063:
064: return returnVal;
065: }
066:
067: protected boolean getParameterBooleanValue(Vector p, String param) {
068: boolean returnVal = false;
069: String str = getParameterValue(p, param);
070: if (str != null) {
071: if (str.equals("true"))
072: returnVal = true;
073: }
074: return returnVal;
075: }
076:
077: /**
078: * This Plugin has no subscriptions so this method does nothing
079: */
080: protected void execute() {
081: }
082:
083: protected void setupSubscriptions() {
084: Vector p = getParameters();
085: }
086:
087: public void debug(boolean DEBUG, String message) {
088: if (DEBUG) //default to stdout
089: //System.out.println(formatMessage(message));
090: System.out.println(message);
091: }
092:
093: public void log(boolean LOG, String out, FileWriter fw,
094: String message) {
095: try {
096: if (LOG) {//default to stdout
097: if (out != null) {
098: fw = new FileWriter(out, true);
099: fw.write(message + "\n");
100: fw.close();
101: } else
102: System.out.println(message);
103: }
104: } catch (IOException ie) {
105: ie.printStackTrace();
106: }//catch
107:
108: }
109:
110: public String formatMessage(String msg[]) {
111: String delimiter = "'";
112: String returnMsg = msg[0] + delimiter;
113: for (int i = 1; i < msg.length; i++) {
114: returnMsg = returnMsg + "," + msg[i];
115: }
116: return returnMsg;
117: }
118:
119: public void consumeCPU(int times) {
120: int slurp = 0;
121: for (int i = 0; i < times; i++) {
122: slurp++;
123: }
124: }
125:
126: public byte[] alterMessageSize(int val) {
127: byte[] bytes = new byte[val];
128: for (int i = 0; i < val; i++)
129: bytes[i] = 42;
130: return bytes;
131: }
132:
133: public void breakFromLoop(int count, int MAXCOUNT) {
134: if ((count == MAXCOUNT + 1) & (MAXCOUNT != -1))
135: // break;
136: System.exit(1);
137: }
138:
139: public void waitFor(int time) {
140: try {
141: Thread.sleep(time);
142: } catch (InterruptedException e) {
143: System.out.println(e);
144: }
145: }
146: }
|