001/* An atomic actor for testing.
002
003 Copyright (c) 1997-2014 The Regents of the University of California.
004 All rights reserved.
005 Permission is hereby granted, without written agreement and without
006 license or royalty fees, to use, copy, modify, and distribute this
007 software and its documentation for any purpose, provided that the above
008 copyright notice and the following two paragraphs appear in all copies
009 of this software.
010
011 IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
012 FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
013 ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
014 THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
015 SUCH DAMAGE.
016
017 THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
018 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
019 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
020 PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
021 CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
022 ENHANCEMENTS, OR MODIFICATIONS.
023
024 PT_COPYRIGHT_VERSION_2
025 COPYRIGHTENDKEY
026
027 */
028package ptolemy.actor.test;
029
030import ptolemy.actor.AtomicActor;
031import ptolemy.actor.CompositeActor;
032import ptolemy.kernel.util.IllegalActionException;
033import ptolemy.kernel.util.NameDuplicationException;
034
035///////////////////////////////////////////////////////////////////
036//// TestActor
037
038/**
039 A TestActor is a simple atomic actor that is used for testing the actor
040 package. It overrides the action methods with methods that record their
041 invocation in a list.
042
043 @author Edward A. Lee, Mudit Goel
044 @version $Id$
045 @since Ptolemy II 0.2
046 @Pt.ProposedRating Yellow (eal)
047 @Pt.AcceptedRating Red (cxh)
048 */
049public class TestActor extends AtomicActor {
050    /** Create a new actor in the specified container with the specified
051     *  name.  The name must be unique within the container or an exception
052     *  is thrown. The container argument must not be null, or a
053     *  NullPointerException will be thrown.
054     *
055     *  @param container The container.
056     *  @param name The name of this actor within the container.
057     *  @exception IllegalActionException If the entity cannot be contained
058     *   by the proposed container (see the setContainer() method).
059     *  @exception NameDuplicationException If the name coincides with
060     *   an entity already in the container.
061     */
062    public TestActor(CompositeActor container, String name)
063            throws IllegalActionException, NameDuplicationException {
064        super(container, name);
065    }
066
067    ///////////////////////////////////////////////////////////////////
068    ////                         public methods                    ////
069
070    /** Clear the record, and reset the iteration count to zero.
071     */
072    public static void clear() {
073        _actions = new StringBuffer(1024);
074    }
075
076    /** Record the firing.
077     *  @exception IllegalActionException If the super class throws it.
078     */
079    @Override
080    public void fire() throws IllegalActionException {
081        super.fire();
082        _actions.append(getFullName() + ".fire\n");
083    }
084
085    /** Get the record.
086     */
087    public static String getRecord() {
088        return _actions.toString();
089    }
090
091    /** Record the initialization.
092     *  @exception IllegalActionException If the parent class throws it.
093     */
094    @Override
095    public void initialize() throws IllegalActionException {
096        super.initialize();
097        _actions.append(getFullName() + ".initialize\n");
098    }
099
100    /** Record the invocation, then return true.
101     */
102    @Override
103    public boolean postfire() {
104        _actions.append(getFullName() + ".postfire\n");
105        return true;
106    }
107
108    /** Record the invocation, then return true.
109     */
110    @Override
111    public boolean prefire() {
112        _actions.append(getFullName() + ".prefire\n");
113        return true;
114    }
115
116    /** Record the invocation.
117     */
118    @Override
119    public void wrapup() {
120        _actions.append(getFullName() + ".wrapup\n");
121    }
122
123    ///////////////////////////////////////////////////////////////////
124    ////                         private variables                 ////
125    // The list of action method invocations.
126    private static StringBuffer _actions = new StringBuffer(1024);
127}