001: /**
002: * This file or a portion of this file is licensed under the terms of
003: * the Globus Toolkit Public License, found at $PEGASUS_HOME/GTPL or
004: * http://www.globus.org/toolkit/download/license.html.
005: * This notice must appear in redistributions of this file
006: * with or without modification.
007: *
008: * Redistributions of this Software, with or without modification, must reproduce
009: * the GTPL in:
010: * (1) the Software, or
011: * (2) the Documentation or
012: * some other similar material which is provided with the Software (if any).
013: *
014: * Copyright 1999-2004
015: * University of Chicago and The University of Southern California.
016: * All rights reserved.
017: */package org.griphyn.cPlanner.engine;
018:
019: import org.griphyn.cPlanner.classes.PegasusFile;
020: import org.griphyn.cPlanner.classes.PlannerOptions;
021:
022: import org.griphyn.cPlanner.common.LogManager;
023: import org.griphyn.cPlanner.common.PegasusProperties;
024:
025: import org.griphyn.cPlanner.poolinfo.PoolInfoProvider;
026: import org.griphyn.cPlanner.poolinfo.PoolMode;
027:
028: import org.griphyn.common.catalog.TransformationCatalog;
029:
030: import java.util.ArrayList;
031: import java.util.Enumeration;
032: import java.util.Iterator;
033: import java.util.List;
034: import java.util.Vector;
035:
036: /**
037: * The class which is a superclass of all the various Engine classes. It
038: * defines common methods and member variables.
039: *
040: * @author Karan Vahi
041: * @author Gaurang Mehta
042: * @version $Revision: 243 $
043: *
044: */
045: public abstract class Engine {
046:
047: //constants
048: public static final String REGISTRATION_UNIVERSE = "registration";
049: public static final String TRANSFER_UNIVERSE = "transfer";
050:
051: /**
052: * The pool on which all the output data should be transferred.
053: */
054: protected static String mOutputPool;
055:
056: /**
057: * The object holding all the properties pertaining to Pegasus.
058: */
059: protected PegasusProperties mProps;
060:
061: /**
062: * The path to the file containing the pool information. By default it is
063: * $PEGASUS_HOME/etc/pool.config
064: */
065: protected String mPoolFile;
066:
067: /**
068: * The handle to the Transformation Catalog. It must be instantiated
069: * in the implementing class.
070: */
071: protected TransformationCatalog mTCHandle;
072:
073: /**
074: * The path to the file containing the pool information. By default it is
075: * $PEGASUS_HOME/etc/tc.data.
076: */
077: protected String mTCFile;
078:
079: /**
080: * The handle to the Pool Info Provider. It is instantiated in this class
081: */
082: protected PoolInfoProvider mPoolHandle;
083:
084: /**
085: * Contains the message which is to be logged by Pegasus.
086: */
087: protected String mLogMsg = new String();
088:
089: /**
090: * The Replica Location Index URL got from vds.rls.url property
091: */
092: protected String mRLIUrl = new String();
093:
094: /**
095: * Defines the read mode for transformation catalog. Whether we want to read all
096: * at once or as desired.
097: *
098: * @see org.griphyn.common.catalog.transformation.TCMode
099: */
100: protected String mTCMode;
101:
102: /**
103: * Specifies the implementing class for the pool interface. Contains
104: * the name of the class that implements the pool interface the
105: * user has asked at runtime.
106: */
107: protected String mPoolClass;
108:
109: /**
110: * The logging object which is used to log all the messages.
111: *
112: * @see org.griphyn.cPlanner.common.LogManager
113: */
114: protected LogManager mLogger = LogManager.getInstance();
115:
116: /**
117: * Contains the various options to the Planner as passed by the user at
118: * runtime.
119: */
120: protected PlannerOptions mPOptions;
121:
122: /**
123: * Default constructor.
124: *
125: * @param props the properties to be used.
126: */
127: public Engine(PegasusProperties props) {
128: mProps = props;
129: loadProperties();
130:
131: mPoolHandle = PoolMode.loadPoolInstance(mPoolClass, mPoolFile,
132: PoolMode.SINGLETON_LOAD);
133:
134: }
135:
136: /**
137: * Loads all the properties that are needed by the Engine classes.
138: */
139: public void loadProperties() {
140:
141: //get from the properties object
142: mPoolFile = mProps.getPoolFile();
143: mTCFile = mProps.getTCPath();
144: mRLIUrl = mProps.getRLIURL();
145: String rmode = mProps.getReplicaMode();
146: String tcmode = mProps.getTCMode();
147: String poolmode = mProps.getPoolMode();
148:
149: mPoolClass = PoolMode.getImplementingClass(poolmode);
150:
151: }
152:
153: /**
154: * Returns true if a particular String is in the Vector of strings.
155: *
156: * @param stringName the String which has to be searched for in the Vector.
157: * @param vector the Vector of Strings in which to search for a
158: * particular String.
159: *
160: * @return boolean on the basis of whether the String in Vector or not.
161: */
162: public boolean stringInVector(String stringName, Vector vector) {
163: Enumeration e = vector.elements();
164: while (e.hasMoreElements()) {
165: if (stringName.equalsIgnoreCase((String) e.nextElement())) {
166: return true;
167: }
168: }
169: return false;
170: }
171:
172: public boolean stringInList(String stringName, List list) {
173: if (list.contains(stringName)) {
174: return true;
175: } else {
176: return false;
177: }
178: }
179:
180: /**
181: * Returns true if a particular String is in the Vector of PegasusFile objects.
182: *
183: * @param stringName the String which has to be searched for in the Vector.
184: * @param vector the Vector of Strings in which to search for a particular
185: * String
186: *
187: * @return boolean on the basis of whether the String in Vector or not.
188: *
189: */
190: public boolean stringInPegVector(String stringName, Vector vector) {
191: Enumeration e = vector.elements();
192: while (e.hasMoreElements()) {
193: PegasusFile pf = (PegasusFile) e.nextElement();
194: if (stringName.equalsIgnoreCase(pf.getLFN())) {
195: return true;
196: }
197: }
198: return false;
199: }
200:
201: /**
202: * Adds elements (PegasusFile type) in a Vector to another Vector and
203: * returns the new Vector.
204: *
205: * @param from_vector the source
206: * @param to_vector the destination
207: *
208: * @return Vector of PegasusFile objects
209: */
210: public Vector addVector(Vector from_vector, Vector to_vector) {
211: Enumeration e = from_vector.elements();
212: Vector newVector = (Vector) to_vector.clone();
213:
214: while (e.hasMoreElements()) {
215: PegasusFile pf = (PegasusFile) e.nextElement();
216: newVector.addElement(pf);
217: /*String elem = new String((String)e.nextElement());
218: if(!stringInVector(elem,to_vector)){
219: newVector.addElement(elem);
220: }*/
221: }
222:
223: return newVector;
224: }
225:
226: /**
227: * It prints the contents of the Vector, with the first line being the heading.
228: *
229: * @param heading The heading you want to give to the text which is printed.
230: * @param vector The <code>Vector</code> whose elements you want to print.
231: */
232: public void printVector(String heading, Vector vector) {
233: mLogger.log(heading, LogManager.DEBUG_MESSAGE_LEVEL);
234: for (Iterator it = vector.iterator(); it.hasNext();) {
235: mLogger.log(it.next().toString(),
236: LogManager.DEBUG_MESSAGE_LEVEL);
237: }
238: }
239:
240: /**
241: * It prints the contents of the Vector, to a String with the first line being
242: * the heading.
243: *
244: * @param heading The heading you want to give to the text which is printed.
245: * @param vector The <code>Vector</code> whose elements you want to print.
246: *
247: * @return String
248: */
249: public String vectorToString(String heading, Vector vector) {
250: Enumeration e = vector.elements();
251: String st = heading;
252: while (e.hasMoreElements()) {
253: st += "\t" + e.nextElement();
254: }
255: return st;
256: }
257:
258: /**
259: * It appends the source list at the end of the destination list.
260: *
261: * @param dest the destination list
262: * @param source the source list
263: */
264: public void appendArrayList(ArrayList dest, ArrayList source) {
265:
266: Iterator iter = source.iterator();
267: while (iter.hasNext()) {
268: dest.add(iter.next());
269: }
270: }
271:
272: }
|