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 java.util.*;
018: import java.io.Writer;
019: import java.io.IOException;
020:
021: /**
022: * This class encapsulates the exit code or reason of termination for
023: * a given job. The class itself contains the raw exit code. It also
024: * aggregates an instance of the JobStatus interface, which describes
025: * more clearly failure, regular execution, signal and suspension.
026: *
027: * @author Jens-S. Vöckler
028: * @author Yong Zhao
029: * @version $Revision: 50 $
030: */
031: public class Status extends Invocation // implements Cloneable
032: {
033: /**
034: * The raw exit code, unparsed and unprepared. There are several
035: * interpretation of the value. Usually, it is interpreted as
036: * unsigned 16 bit value. The high byte contains the exit code.
037: * The low byte has the core dump flag as MSB, and the rest denote
038: * the signal number. A value of -1 denotes a failure from the
039: * grid launcher before starting the job.
040: */
041: private int m_status;
042:
043: /**
044: * This member variable contains the real status of the job.
045: */
046: private JobStatus m_jobStatus;
047:
048: /**
049: * Default c'tor: Construct a hollow shell and allow further
050: * information to be added later.
051: */
052: public Status() {
053: m_status = 0;
054: m_jobStatus = null;
055: }
056:
057: /**
058: * Constructs a layer with the raw exit code.
059: * @param raw is the raw exit code to store.
060: */
061: public Status(int raw) {
062: m_status = raw;
063: m_jobStatus = null;
064: }
065:
066: /**
067: * Constructs the complete class with raw exit code
068: * and a status child describing the exit code.
069: * @param raw is the raw exit status
070: * @param status is the description of the kind of exit.
071: */
072: public Status(int raw, JobStatus status) {
073: m_status = raw;
074: m_jobStatus = status;
075: }
076:
077: /**
078: * Accessor
079: *
080: * @see #setStatus(int)
081: */
082: public int getStatus() {
083: return this .m_status;
084: }
085:
086: /**
087: * Accessor.
088: *
089: * @param status
090: * @see #getStatus()
091: */
092: public void setStatus(int status) {
093: this .m_status = status;
094: }
095:
096: /**
097: * Accessor
098: *
099: * @see #setJobStatus( JobStatus )
100: */
101: public JobStatus getJobStatus() {
102: return this .m_jobStatus;
103: }
104:
105: /**
106: * Accessor.
107: *
108: * @param jobStatus is an instance of the class describing
109: * the real reason for program termination on the remote end.
110: * @see #getJobStatus()
111: */
112: public void setJobStatus(JobStatus jobStatus) {
113: this .m_jobStatus = jobStatus;
114: }
115:
116: /**
117: * Converts the active state into something meant for human consumption.
118: * The method will be called when recursively traversing the instance
119: * tree.
120: *
121: * @param stream is a stream opened and ready for writing. This can also
122: * be a string stream for efficient output.
123: */
124: public void toString(Writer stream) throws IOException {
125: throw new IOException(
126: "method not implemented, please contact vds-support@griphyn.org");
127: }
128:
129: /**
130: * Dump the state of the current element as XML output. This function
131: * traverses all sibling classes as necessary, and converts the data
132: * into pretty-printed XML output. The stream interface should be able
133: * to handle large output efficiently.
134: *
135: * @param stream is a stream opened and ready for writing. This can also
136: * be a string stream for efficient output.
137: * @param indent is a <code>String</code> of spaces used for pretty
138: * printing. The initial amount of spaces should be an empty string.
139: * The parameter is used internally for the recursive traversal.
140: * If a <code>null</code> value is specified, no indentation nor
141: * linefeeds will be generated.
142: * @param namespace is the XML schema namespace prefix. If neither
143: * empty nor null, each element will be prefixed with this prefix,
144: * and the root element will map the XML namespace.
145: * @exception IOException if something fishy happens to the stream.
146: */
147: public void toXML(Writer stream, String indent, String namespace)
148: throws IOException {
149: String tag = (namespace != null && namespace.length() > 0) ? namespace
150: + ":status"
151: : "status";
152:
153: // open tag
154: if (indent != null && indent.length() > 0)
155: stream.write(indent);
156: stream.write('<');
157: stream.write(tag);
158: writeAttribute(stream, " raw=\"", Integer.toString(m_status));
159: stream.write(">");
160:
161: // dump content
162: String newindent = indent == null ? null : indent + " ";
163: if (m_jobStatus != null)
164: m_jobStatus.toXML(stream, newindent, namespace);
165: else
166: throw new RuntimeException("unknown state of job status");
167:
168: // close tag
169: stream.write("</");
170: stream.write(tag);
171: stream.write('>');
172: if (indent != null)
173: stream.write(System.getProperty("line.separator", "\r\n"));
174: }
175: }
|