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.kepler.job.Job;
033
034import ptolemy.actor.TypedAtomicActor;
035import ptolemy.actor.TypedIOPort;
036import ptolemy.data.BooleanToken;
037import ptolemy.data.ObjectToken;
038import ptolemy.data.StringToken;
039import ptolemy.data.expr.Parameter;
040import ptolemy.data.type.BaseType;
041import ptolemy.kernel.CompositeEntity;
042import ptolemy.kernel.util.IllegalActionException;
043import ptolemy.kernel.util.NameDuplicationException;
044
045//////////////////////////////////////////////////////////////////////////
046//// JobFileFetcher
047
048/**
049 * <p>
050 * Get the job file info of a submitted Job
051 * </p>
052 * 
053 * <p>
054 * This actor uses the Job class to ask for the the job file info (file path + file name) of a submitted job.
055 * </p>
056 * 
057 * <p>
058 * The input should be a previously submitted job. i.e. the output from a
059 * JobSubmitter.
060 * </p>
061 * 
062 * <p>
063 * The output is the the job file info (file path + file name) of the job:
064 * </p>
065 * <p>
066 * If not such job exists, the result will be also the Error status.
067 * </p>
068 * 
069 * 
070 * @author Jianwu Wang
071 * @version $Id: JobFileFetcher.java 24234 2010-05-06 05:21:26Z welker $
072 * @since Ptolemy II 7
073 */
074public class JobFileFetcher 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 JobFileFetcher(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                jobIn = new TypedIOPort(this, "jobIn", true, false);
095                jobIn.setTypeEquals(BaseType.OBJECT);
096                new Parameter(jobIn, "_showName", BooleanToken.FALSE);
097
098                // Output: job file name of the submitted job
099                jobFileName = new TypedIOPort(this, "jobFileName", false, true);
100                jobFileName.setTypeEquals(BaseType.STRING);
101                new Parameter(jobFileName, "_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 jobIn;
113
114        /**
115         */
116        public TypedIOPort jobFileName;
117
118
119        /***********************************************************
120         * public methods
121         */
122
123        /**
124         * fire
125         * 
126         * @exception IllegalActionException
127         *                Not thrown.
128         */
129        public void fire() throws IllegalActionException {
130                super.fire();
131                ObjectToken jobToken = (ObjectToken) jobIn.get(0);
132                Job job = (Job) jobToken.getValue();
133                String fileName = job.getSubmitFile();
134                if (fileName != null)
135                        jobFileName.send(0, new StringToken (fileName));
136                else
137                        {
138                                throw new IllegalActionException("Can't get file Job info, probably the submitted job for input is not correct.");
139                        }
140        }
141}