001/*
002 @Copyright (c) 1998-2014 The Regents of the University of California.
003 All rights reserved.
004
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
008 above copyright notice and the following two paragraphs appear in all
009 copies 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.sdf.kernel.test;
028
029import ptolemy.actor.TypedAtomicActor;
030import ptolemy.actor.TypedIOPort;
031import ptolemy.data.IntToken;
032import ptolemy.data.expr.Parameter;
033import ptolemy.data.type.BaseType;
034import ptolemy.kernel.CompositeEntity;
035import ptolemy.kernel.util.IllegalActionException;
036import ptolemy.kernel.util.NameDuplicationException;
037
038/**
039 * This actor deterministically splits its input token stream into two
040 * streams.
041 * @author Steve Neuendorffer
042 * @version $Id$
043 * @since Ptolemy II 0.4
044 * @Pt.ProposedRating Red
045 * @Pt.AcceptedRating Red
046 */
047public class SDFTestSplit extends TypedAtomicActor {
048    public SDFTestSplit(CompositeEntity container, String name)
049            throws IllegalActionException, NameDuplicationException {
050        super(container, name);
051        input = new TypedIOPort(this, "input", true, false);
052        input_tokenConsumptionRate = new Parameter(input,
053                "tokenConsumptionRate", new IntToken(2));
054        input.setTypeEquals(BaseType.INT);
055
056        output1 = new TypedIOPort(this, "output1", false, true);
057        output1_tokenProductionRate = new Parameter(output1,
058                "tokenProductionRate", new IntToken(1));
059        output1.setTypeEquals(BaseType.INT);
060
061        output2 = new TypedIOPort(this, "output2", false, true);
062        output2_tokenProductionRate = new Parameter(output2,
063                "tokenProductionRate", new IntToken(1));
064
065        output2.setTypeEquals(BaseType.INT);
066    }
067
068    ///////////////////////////////////////////////////////////////////
069    ////                         public methods                    ////
070    public TypedIOPort input;
071
072    public TypedIOPort output1;
073
074    public TypedIOPort output2;
075
076    public Parameter input_tokenConsumptionRate;
077
078    public Parameter output1_tokenProductionRate;
079
080    public Parameter output2_tokenProductionRate;
081
082    /**
083     * Consume two tokens from the input.  Copy the first one to the port
084     * output1, and the second to the port output2
085     * @exception IllegalActionException if a contained method throws it.
086     */
087    @Override
088    public void fire() throws IllegalActionException {
089        IntToken message;
090
091        message = (IntToken) input.get(0);
092        output1.send(0, message);
093        message = (IntToken) input.get(0);
094        output2.send(0, message);
095    }
096}