001: /*
002: * This file or a portion of this file is licensed under the terms of
003: * the Globus Toolkit Public License, found in file GTPL, or at
004: * http://www.globus.org/toolkit/download/license.html. This notice must
005: * appear in redistributions of this file, with or without modification.
006: *
007: * Redistributions of this Software, with or without modification, must
008: * reproduce the GTPL in: (1) the Software, or (2) the Documentation or
009: * some other similar material which is provided with the Software (if
010: * any).
011: *
012: * Copyright 1999-2004 University of Chicago and The University of
013: * Southern California. All rights reserved.
014: */
015: package org.griphyn.vdl.invocation;
016:
017: import org.griphyn.common.util.Currently;
018: import java.util.*;
019: import java.text.DecimalFormat;
020: import java.io.Writer;
021: import java.io.IOException;
022:
023: /**
024: * This class is contains the record from each jobs that ran in every
025: * invocation.
026: *
027: * @author Jens-S. Vöckler
028: * @author Yong Zhao
029: * @version $Revision: 50 $
030: */
031: public class Job extends Invocation // implements Cloneable
032: {
033: /**
034: * This is the tag to produce the job for. Usually, it is one of
035: * "mainjob", "prejob", "postjob", or "cleanup".
036: */
037: private String m_tag;
038:
039: /**
040: * Start time of this job.
041: */
042: private Date m_start;
043:
044: /**
045: * Duration of the job.
046: */
047: private double m_duration;
048:
049: /**
050: * Process id assigned to the job.
051: */
052: private int m_pid;
053:
054: /**
055: * Resource usage of this job.
056: */
057: private Usage m_usage;
058:
059: /**
060: * Exit condition of the job.
061: */
062: private Status m_status;
063:
064: /**
065: * Stat call of the executable.
066: */
067: private StatCall m_executable;
068:
069: /**
070: * Command-line arguments.
071: */
072: private Arguments m_arguments;
073:
074: public Job(String tag) {
075: m_tag = tag;
076: m_usage = null;
077: m_status = null;
078: m_executable = null;
079: m_arguments = null;
080: }
081:
082: /**
083: * Accessor
084: *
085: * @see #setTag(String)
086: */
087: public String getTag() {
088: return this .m_tag;
089: }
090:
091: /**
092: * Accessor.
093: *
094: * @param tag
095: * @see #getTag()
096: */
097: public void setTag(String tag) {
098: this .m_tag = tag;
099: }
100:
101: /**
102: * Accessor
103: *
104: * @see #setStart(Date)
105: */
106: public Date getStart() {
107: return this .m_start;
108: }
109:
110: /**
111: * Accessor.
112: *
113: * @param start
114: * @see #getStart()
115: */
116: public void setStart(Date start) {
117: this .m_start = start;
118: }
119:
120: /**
121: * Accessor
122: *
123: * @see #setDuration(double)
124: */
125: public double getDuration() {
126: return this .m_duration;
127: }
128:
129: /**
130: * Accessor.
131: *
132: * @param duration
133: * @see #getDuration()
134: */
135: public void setDuration(double duration) {
136: this .m_duration = duration;
137: }
138:
139: /**
140: * Accessor
141: *
142: * @see #setPID(int)
143: */
144: public int getPID() {
145: return this .m_pid;
146: }
147:
148: /**
149: * Accessor.
150: *
151: * @param pid
152: * @see #getPID()
153: */
154: public void setPID(int pid) {
155: this .m_pid = pid;
156: }
157:
158: /**
159: * Accessor
160: *
161: * @see #setUsage(Usage)
162: */
163: public Usage getUsage() {
164: return this .m_usage;
165: }
166:
167: /**
168: * Accessor.
169: *
170: * @param usage
171: * @see #getUsage()
172: */
173: public void setUsage(Usage usage) {
174: this .m_usage = usage;
175: }
176:
177: /**
178: * Accessor
179: *
180: * @see #setStatus(Status)
181: */
182: public Status getStatus() {
183: return this .m_status;
184: }
185:
186: /**
187: * Accessor.
188: *
189: * @param status
190: * @see #getStatus()
191: */
192: public void setStatus(Status status) {
193: this .m_status = status;
194: }
195:
196: /**
197: * Accessor
198: *
199: * @see #setExecutable(StatCall)
200: */
201: public StatCall getExecutable() {
202: return this .m_executable;
203: }
204:
205: /**
206: * Accessor.
207: *
208: * @param executable
209: * @see #getExecutable()
210: */
211: public void setExecutable(StatCall executable) {
212: this .m_executable = executable;
213: }
214:
215: /**
216: * Accessor
217: *
218: * @see #setArguments(Arguments)
219: */
220: public Arguments getArguments() {
221: return this .m_arguments;
222: }
223:
224: /**
225: * Accessor.
226: *
227: * @param arguments
228: * @see #getArguments()
229: */
230: public void setArguments(Arguments arguments) {
231: this .m_arguments = arguments;
232: }
233:
234: /**
235: * Converts the active state into something meant for human consumption.
236: * The method will be called when recursively traversing the instance
237: * tree.
238: *
239: * @param stream is a stream opened and ready for writing. This can also
240: * be a string stream for efficient output.
241: */
242: public void toString(Writer stream) throws IOException {
243: throw new IOException(
244: "method not implemented, please contact vds-support@griphyn.org");
245: }
246:
247: /**
248: * Dumps the state of the current element as XML output. This function
249: * traverses all sibling classes as necessary, and converts the data
250: * into pretty-printed XML output. The stream interface should be able
251: * to handle large output efficiently.
252: *
253: * @param stream is a stream opened and ready for writing. This can also
254: * be a string stream for efficient output.
255: * @param indent is a <code>String</code> of spaces used for pretty
256: * printing. The initial amount of spaces should be an empty string.
257: * The parameter is used internally for the recursive traversal.
258: * @param namespace is the XML schema namespace prefix. If neither
259: * empty nor null, each element will be prefixed with this prefix,
260: * and the root element will map the XML namespace.
261: * @exception IOException if something fishy happens to the stream.
262: */
263: public void toXML(Writer stream, String indent, String namespace)
264: throws IOException {
265: String newline = System.getProperty("line.separator", "\r\n");
266: DecimalFormat d = new DecimalFormat("#.###");
267: String tag = (namespace != null && namespace.length() > 0) ? namespace
268: + ":" + m_tag
269: : m_tag;
270:
271: // open tag
272: if (indent != null && indent.length() > 0)
273: stream.write(indent);
274: stream.write('<');
275: stream.write(tag);
276: writeAttribute(stream, " start=\"", Currently.iso8601(false,
277: true, true, m_start));
278: writeAttribute(stream, " duration=\"", d.format(m_duration));
279: writeAttribute(stream, " pid=\"", Integer.toString(m_pid));
280: stream.write('>');
281: if (indent != null)
282: stream.write(newline);
283:
284: // dump content
285: String newindent = indent == null ? null : indent + " ";
286: m_usage.toXML(stream, newindent, namespace);
287: m_status.toXML(stream, newindent, namespace);
288: m_executable.toXML(stream, newindent, namespace);
289: m_arguments.toXML(stream, newindent, namespace);
290:
291: // close tag
292: if (indent != null && indent.length() > 0)
293: stream.write(indent);
294: stream.write("</");
295: stream.write(tag);
296: stream.write('>');
297: if (indent != null)
298: stream.write(newline);
299: }
300: }
|