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.workflow;
016:
017: import java.util.*;
018: import org.griphyn.common.util.Currently;
019:
020: /**
021: * This class is the container for a job state record.<p>
022: *
023: * When constructing a job from piece-meal, please note that setting the
024: * job's state will automatically set the job's last modification time
025: * to the current time. If this is not desired, you must set the
026: * modification time after setting the state. However, none of the
027: * constructors will set the modification to the current time (yet).
028: *
029: * @author Jens-S. Vöckler
030: * @author Mike Wilde
031: * @version $Revision: 50 $
032: */
033: public class JobStateEntry implements Workflow, Cloneable {
034: /**
035: * primary key: which workflow do we belong to. If -1 then unknown.
036: */
037: private long m_wfid = -1;
038:
039: /**
040: * primary key: unique job identifier within the workflow
041: */
042: private String m_id;
043:
044: /**
045: * the Condor state of the job.
046: */
047: private String m_state;
048:
049: /**
050: * the last modification time of the job state.
051: */
052: private Date m_mtime;
053:
054: /**
055: * the resource where the job ran, may be unspecified.
056: */
057: private String m_site = null;
058:
059: /**
060: * Creates and returns a copy of this object.
061: * @return a new instance.
062: */
063: public Object clone() {
064: JobStateEntry result = new JobStateEntry(getWorkflowID(),
065: getID());
066: result.setState(getState());
067: result.setModificationTime(getModificationTime());
068: result.setSite(getSite());
069: return result;
070: }
071:
072: /**
073: * Default contructor.
074: */
075: public JobStateEntry() {
076: // empty
077: }
078:
079: /**
080: * Constructs an other empty class.
081: *
082: * @param wfid is the workflow primary key
083: */
084: public JobStateEntry(long wfid) {
085: m_wfid = wfid;
086: }
087:
088: /**
089: * Constructs an other empty class.
090: *
091: * @param wfid is the workflow primary key
092: * @param jobid is the job identifier within the workflow
093: */
094: public JobStateEntry(long wfid, String jobid) {
095: m_wfid = wfid;
096: m_id = jobid;
097: }
098:
099: /**
100: * Constructs an other empty class. It will set the workflow identifier
101: * to -1 to indicate no connection.
102: *
103: * @param jobid is the job identifier within the workflow
104: */
105: public JobStateEntry(String jobid) {
106: m_wfid = -1;
107: m_id = jobid;
108: }
109:
110: /**
111: * Accessor
112: *
113: * @see #setWorkflowID(long)
114: * @return this job's workflow identifier.
115: */
116: public long getWorkflowID() {
117: return this .m_wfid;
118: }
119:
120: /**
121: * Accessor.
122: *
123: * @param wfid is the new workflow id as positive number.
124: * @see #getWorkflowID()
125: */
126: public void setWorkflowID(long wfid) {
127: if (wfid < 0)
128: throw new RuntimeException("negative workflow id");
129: this .m_wfid = wfid;
130: }
131:
132: /**
133: * Accessor
134: *
135: * @see #setID(String)
136: * @return the job identifier
137: */
138: public String getID() {
139: return this .m_id;
140: }
141:
142: /**
143: * Accessor.
144: *
145: * @param id is the new job id, must not be <code>null</code>.
146: * @see #getID()
147: */
148: public void setID(String id) {
149: if (id == null)
150: throw new NullPointerException();
151: this .m_id = id;
152: }
153:
154: /**
155: * Accessor
156: *
157: * @see #setState(String)
158: * @return the Condor job state string with some extensions.
159: */
160: public String getState() {
161: return this .m_state;
162: }
163:
164: /**
165: * Accessor. As a side effect, setting the job state will
166: * set the current modification time to the current time.
167: *
168: * @param state is the new Condor job state, must not be
169: * <code>null</code>.
170: * @see #getState()
171: */
172: public void setState(String state) {
173: if (state == null)
174: throw new NullPointerException();
175: this .m_state = state;
176: this .m_mtime = new Date();
177: }
178:
179: /**
180: * Accessor
181: *
182: * @see #setModificationTime(Date)
183: * @return the last modification time of any of this job's state.
184: */
185: public Date getModificationTime() {
186: return this .m_mtime;
187: }
188:
189: /**
190: * Accessor.
191: *
192: * @param mtime is the new last modification time of this job, must
193: * not be <code>null</code>.
194: * @see #getModificationTime()
195: */
196: public void setModificationTime(Date mtime) {
197: if (mtime == null)
198: throw new NullPointerException();
199: this .m_mtime = mtime;
200: }
201:
202: /**
203: * Accessor
204: *
205: * @see #setSite(String)
206: */
207: public String getSite() {
208: return this .m_site;
209: }
210:
211: /**
212: * Accessor.
213: *
214: * @param site is the new remote site, may be <code>null</code>.
215: * @see #getSite()
216: */
217: public void setSite(String site) {
218: this .m_site = site;
219: }
220:
221: /**
222: * Constructs a simple line of all internal data points. Adjust
223: * to your requirements - this is an example, only.
224: *
225: * @return a line containing all internal data.
226: */
227: public String toString() {
228: StringBuffer result = new StringBuffer(80);
229:
230: result.append(Long.toString(m_wfid)).append('|');
231: result.append(m_id).append('|');
232: result.append(m_state).append('|');
233: result.append(Currently.iso8601(false, true, false, m_mtime))
234: .append('|');
235: result.append(m_site == null ? "NULL" : m_site);
236:
237: return result.toString();
238: }
239: }
|