001/*
002 * Copyright (c) 2015 The Regents of the University of California.
003 * All rights reserved.
004 *
005 * '$Author: crawl $'
006 * '$Date: 2017-07-07 16:13:12 +0000 (Fri, 07 Jul 2017) $' 
007 * '$Revision: 34584 $'
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 */
029package org.kepler.provenance;
030
031import java.util.LinkedHashMap;
032import java.util.Map;
033
034import ptolemy.actor.Actor;
035import ptolemy.actor.FiringsRecordable;
036
037/** Base class for Recordings with simple firing semantics. The type
038 *  parameter is a id to identify different firings.
039 * 
040 *  @author Daniel Crawl
041 *  @version $Id: SimpleFiringRecording.java 34584 2017-07-07 16:13:12Z crawl $
042 * 
043 */
044public class SimpleFiringRecording<T> extends Recording {
045
046    public SimpleFiringRecording() throws RecordingException {
047        super();
048    }
049
050    /** Register an actor. */
051    @Override
052    public boolean regActor(Actor actor) throws RecordingException
053    {
054        if(actor instanceof FiringsRecordable)
055        {
056            FireState<T> fireState = new FireState<T>(actor, -1);
057            _fireStateTable.put(actor, fireState);
058        }
059
060        return true;
061    }
062
063    /** Always register the contents of the workflow. */
064    @Override
065    public boolean regContents() {
066        return true;
067    }
068
069    /** Called before registering workflow contents. */
070    @Override
071    public void specificationStart() throws RecordingException
072    {
073        super.specificationStart();
074
075        // always clear the fire state table since the id of actors
076        // can change between workflow executions due to the actor
077        // being renamed.
078        _fireStateTable.clear();
079    }
080
081
082    /** A table to map actor to its firing state object. */
083    protected final Map<Actor, FireState<T>> _fireStateTable =
084            new LinkedHashMap<Actor, FireState<T>>();
085}