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.classes;
018:
019: import org.griphyn.cPlanner.common.LogManager;
020:
021: import java.util.Map;
022: import java.util.HashMap;
023: import java.util.Iterator;
024:
025: /**
026: * A data class to store information about the various remote sites.
027: *
028: * @author Gaurang Mehta
029: * @author Karan Vahi
030: * @version $Revision: 50 $
031: *
032: * @see SiteInfo
033: */
034: public class PoolConfig {
035:
036: /**
037: * The map indexed by the site handle. Each value is a SiteInfo object,
038: * containing the information about a grid site.
039: */
040: private HashMap mSiteCatalog;
041:
042: /**
043: * The handle to the logging object.
044: */
045: private LogManager mLogger;
046:
047: /**
048: * The default constructor.
049: */
050: public PoolConfig() {
051: mLogger = LogManager.getInstance();
052: mSiteCatalog = new HashMap(20);
053: }
054:
055: /**
056: * Adds a SiteInfo object to the container. If an entry already exists with
057: * the same SiteID, it is overwritten.
058: *
059: * @param id the id of the site, usually the name of the site.
060: * @param site the <code>SiteInfo</code> object containing the information
061: * about the site.
062: */
063: public void add(String id, SiteInfo site) {
064: mSiteCatalog.put(id, site);
065: }
066:
067: /**
068: * Adds all the sites in a controlled fashion, to the existing map containing
069: * information about the sites. If an information about a site already
070: * exists, it is overwritten.
071: *
072: * @param sites a map indexed by siteid. Each value is a SiteInfo object.
073: */
074: public void add(PoolConfig sites) {
075: add(sites, true);
076: }
077:
078: /**
079: * Adds all the sites in a controlled fashion, to the existing map containing
080: * information about the sites.
081: *
082: * @param sites a map indexed by siteid. Each value is a SiteInfo object.
083: * @param overwrite resolves intersections, in case of a site already exists.
084: * If true, the orginal site information is overwritten with
085: * the new one. If false original site information remains.
086: *
087: */
088: public void add(PoolConfig sites, boolean overwrite) {
089: String id;
090: SiteInfo site;
091: boolean contains = false;
092: for (Iterator it = sites.getSites().entrySet().iterator(); it
093: .hasNext();) {
094: Map.Entry entry = (Map.Entry) it.next();
095: id = (String) entry.getKey();
096: site = (SiteInfo) entry.getValue();
097: contains = contains(id);
098: if (overwrite || !contains) {
099: add(id, site);
100: }
101: }
102: }
103:
104: /**
105: * Returns a boolean indicating if an entry for a Site with a particular id
106: * exists or not.
107: *
108: * @param id the id of the site, usually the name of the site.
109: *
110: * @return true if entry for the site exists, else false.
111: */
112: public boolean contains(String id) {
113: return mSiteCatalog.containsKey(id);
114: }
115:
116: /**
117: * Retrives the information about a site.
118: *
119: * @param siteID the id of the site, usually the name of the site.
120: * @return <code>SiteInfo</code> containing the site layout,
121: * else null in case of site not existing.
122: */
123: public SiteInfo get(String siteID) {
124: if (mSiteCatalog.containsKey(siteID)) {
125: return (SiteInfo) mSiteCatalog.get(siteID);
126: } else {
127: mLogger.log("Site '" + siteID
128: + "' does not exist in the Site Catalog.",
129: LogManager.ERROR_MESSAGE_LEVEL);
130: return null;
131: }
132: }
133:
134: /**
135: * Returns information about all the sites.
136: *
137: * @return a Map indexed by the site id (name of the site). Each value is a
138: * <code>SiteInfo</code> object.
139: */
140: public Map getSites() {
141: return mSiteCatalog;
142: }
143:
144: /**
145: * Returns the textual description of the contents of <code>PoolConfig</code>
146: * object in the multiline format.
147: *
148: * @return the textual description in multiline format.
149: */
150: public String toMultiLine() {
151: String output = "";
152: for (Iterator i = mSiteCatalog.keySet().iterator(); i.hasNext();) {
153: String poolid = (String) i.next();
154: //Karan Oct 13,2005
155: //This is moved to SiteInfo.toMultiLine()
156: //output += "pool " + poolid +
157: output += ((SiteInfo) mSiteCatalog.get(poolid))
158: .toMultiLine()
159: + "\n";
160: }
161: return output;
162: }
163:
164: /**
165: * Returns the XML description of the contents of <code>PoolConfig</code>
166: * object.
167: *
168: * @return the xml description.
169: */
170: public String toXML() {
171: String output = "";
172: for (Iterator i = mSiteCatalog.keySet().iterator(); i.hasNext();) {
173: String poolid = (String) i.next();
174: output += " <site handle=\"" + poolid + "\""
175: + ((SiteInfo) mSiteCatalog.get(poolid)).toXML();
176: }
177: // System.out.println(output);
178: return output;
179: }
180: }
|