001/* This star discards whatever it receives at the input
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 */
027package ptolemy.domains.pn.kernel.test;
028
029import ptolemy.actor.AtomicActor;
030import ptolemy.actor.CompositeActor;
031import ptolemy.actor.IOPort;
032import ptolemy.data.IntToken;
033import ptolemy.data.Token;
034import ptolemy.kernel.util.IllegalActionException;
035import ptolemy.kernel.util.NameDuplicationException;
036
037///////////////////////////////////////////////////////////////////
038//// PNSink
039
040/**
041
042 @author Mudit Goel
043 @version $Id$
044 @since Ptolemy II 0.2
045 @Pt.ProposedRating Red (cxh)
046 @Pt.AcceptedRating Red (cxh)
047 */
048public class TestSink extends AtomicActor {
049    /** Constructor Adds ports to the star
050     * @param container The container.
051     * @param name The name of this actor.
052     * @exception NameDuplicationException indicates that an attempt to add
053     *  two ports with the same name has been made
054     */
055    public TestSink(CompositeActor container, String name)
056            throws IllegalActionException, NameDuplicationException {
057        super(container, name);
058        _input = new IOPort(this, "input", true, false);
059    }
060
061    ///////////////////////////////////////////////////////////////////
062    ////                         public methods                    ////
063
064    /** Clear the record, and reset the iteration count to zero.
065     */
066    public void clear() {
067        _list = new StringBuffer(1024);
068    }
069
070    /** Writes successive integers to the output
071     */
072    @Override
073    public void fire() throws IllegalActionException {
074        Token data;
075
076        while (true) {
077            data = _input.get(0);
078            _list.append(((IntToken) data).intValue());
079
080            //System.out.println("Sink discarded "+data.intValue());
081        }
082    }
083
084    public static String getData() {
085        return _list.toString();
086    }
087
088    ///////////////////////////////////////////////////////////////////
089    ////                         private variables                 ////
090
091    /* Input port */
092    private IOPort _input;
093
094    private static StringBuffer _list = new StringBuffer(1024);
095}