001/* 002 * Copyright (c) 2004-2010 The Regents of the University of California. 003 * All rights reserved. 004 * 005 * '$Author: welker $' 006 * '$Date: 2010-05-06 05:21:26 +0000 (Thu, 06 May 2010) $' 007 * '$Revision: 24234 $' 008 * 009 * Permission is hereby granted, without written agreement and without 010 * license or royalty fees, to use, copy, modify, and distribute this 011 * software and its documentation for any purpose, provided that the above 012 * copyright notice and the following two paragraphs appear in all copies 013 * of this software. 014 * 015 * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY 016 * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 017 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF 018 * THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF 019 * SUCH DAMAGE. 020 * 021 * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, 022 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 023 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE 024 * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF 025 * CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, 026 * ENHANCEMENTS, OR MODIFICATIONS. 027 * 028 */ 029 030package org.kepler.actor.job; 031 032import org.apache.commons.logging.Log; 033import org.apache.commons.logging.LogFactory; 034import org.kepler.job.Job; 035 036import ptolemy.actor.TypedAtomicActor; 037import ptolemy.actor.TypedIOPort; 038import ptolemy.data.BooleanToken; 039import ptolemy.data.ObjectToken; 040import ptolemy.data.StringToken; 041import ptolemy.data.expr.Parameter; 042import ptolemy.data.type.BaseType; 043import ptolemy.kernel.CompositeEntity; 044import ptolemy.kernel.util.IllegalActionException; 045import ptolemy.kernel.util.NameDuplicationException; 046 047////////////////////////////////////////////////////////////////////////// 048//// JobGetRealJobID 049 050/** 051 * <p> 052 * Get the real (given back the jobManager as a handle) JobID of a submitted Job 053 * </p> 054 * 055 * <p> 056 * This actor uses the Job class get the jobID of a submitted job. It is useful 057 * only if you want to do weird things based on the real jobID of your submitted 058 * job (e.g edit files or go to remote site and commit something nasty there). 059 * </p> 060 * 061 * <p> 062 * The input should be a previously submitted job. i.e. the output from a 063 * JobSubmitter. 064 * </p> 065 * <p> 066 * The ouput is the jobID of type String. If the job is null object or it was 067 * not submitted, this actor throws an IllegalActionException. 068 * </p> 069 * 070 * @author Norbert Podhorszki 071 * @version $Id: JobGetRealJobID.java 24234 2010-05-06 05:21:26Z welker $ 072 * @since Ptolemy II 5.0.1 073 */ 074public class JobGetRealJobID extends TypedAtomicActor { 075 /** 076 * Construct an actor with the given container and name. 077 * 078 * @param container 079 * The container. 080 * @param name 081 * The name of this actor. 082 * @exception IllegalActionException 083 * If the actor cannot be contained by the proposed 084 * container. 085 * @exception NameDuplicationException 086 * If the container already has an actor with this name. 087 */ 088 public JobGetRealJobID(CompositeEntity container, String name) 089 throws NameDuplicationException, IllegalActionException { 090 super(container, name); 091 092 // Uncomment the next line to see debugging statements 093 // addDebugListener(new ptolemy.kernel.util.StreamListener()); 094 job = new TypedIOPort(this, "job", true, false); 095 job.setTypeEquals(BaseType.OBJECT); 096 new Parameter(job, "_showName", BooleanToken.FALSE); 097 098 // Output: real JobID as string 099 jobID = new TypedIOPort(this, "jobID", false, true); 100 jobID.setTypeEquals(BaseType.STRING); 101 new Parameter(jobID, "_showName", BooleanToken.TRUE); 102 103 } 104 105 /*********************************************************** 106 * ports and parameters 107 */ 108 109 /** 110 * A submitted job This port is an output port of type Object. 111 */ 112 public TypedIOPort job; 113 114 /** 115 * Real jobID of the job that came from the job manager as a handle when the 116 * job was submitted. Useful only if you want to do weird things based on 117 * the real jobID of your submitted job (e.g edit files or go to remote site 118 * and commit something nasty there). This port is an output port of type 119 * String. 120 */ 121 public TypedIOPort jobID; 122 123 /*********************************************************** 124 * public methods 125 */ 126 127 /** 128 * fire 129 * 130 * @exception IllegalActionException 131 * Not thrown. 132 */ 133 public void fire() throws IllegalActionException { 134 super.fire(); 135 136 ObjectToken jobToken = (ObjectToken) job.get(0); 137 Job _job = (Job) jobToken.getValue(); 138 String _jobID = ""; 139 140 try { 141 if (_job == null) 142 throw new Exception("JobGetRealJobID: Job is null"); 143 144 if (_job.status == null) 145 throw new Exception( 146 "JobGetRealJobID: This job was not submitted or has been lost somehow in the meantime."); 147 148 _jobID = _job.status.jobID; 149 if (isDebugging) 150 log.debug("Real ID of job " + _job.getJobID() + ": " + _jobID); 151 152 } catch (Exception ex) { 153 log.error(ex); 154 ex.printStackTrace(); 155 throw new IllegalActionException("JobGetRealJobID Error: " + ex.toString()); 156 } 157 158 jobID.send(0, new StringToken(_jobID)); 159 160 } 161 162 private static final Log log = LogFactory.getLog(JobGetRealJobID.class 163 .getName()); 164 private static final boolean isDebugging = log.isDebugEnabled(); 165 166}