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 027 */ 028package ptolemy.domains.sdf.kernel.test; 029 030import ptolemy.actor.TypedAtomicActor; 031import ptolemy.actor.TypedIOPort; 032import ptolemy.data.IntToken; 033import ptolemy.data.expr.Parameter; 034import ptolemy.data.type.BaseType; 035import ptolemy.kernel.CompositeEntity; 036import ptolemy.kernel.util.IllegalActionException; 037import ptolemy.kernel.util.NameDuplicationException; 038 039/////////////////////////////////////////////////////////////////// 040//// SDFTestJoin 041 042/** 043 * A deterministic merge of two token streams. 044 * @author Stephen Neuendorffer 045 * @version $Id$ 046 * @since Ptolemy II 0.4 047 * @Pt.ProposedRating Red 048 * @Pt.AcceptedRating Red 049 */ 050public class SDFTestJoin extends TypedAtomicActor { 051 public SDFTestJoin(CompositeEntity container, String name) 052 throws IllegalActionException, NameDuplicationException { 053 super(container, name); 054 input1 = new TypedIOPort(this, "input1", true, false); 055 input1_tokenConsumptionRate = new Parameter(input1, 056 "tokenConsumptionRate", new IntToken(1)); 057 input1.setTypeEquals(BaseType.GENERAL); 058 059 input2 = new TypedIOPort(this, "input2", true, false); 060 input2_tokenConsumptionRate = new Parameter(input2, 061 "tokenConsumptionRate", new IntToken(1)); 062 input2.setTypeEquals(BaseType.GENERAL); 063 064 output = new TypedIOPort(this, "output", false, true); 065 output_tokenProductionRate = new Parameter(output, 066 "tokenProductionRate", new IntToken(2)); 067 068 output.setTypeEquals(BaseType.GENERAL); 069 } 070 071 /////////////////////////////////////////////////////////////////// 072 //// public methods //// 073 public TypedIOPort input1; 074 075 public TypedIOPort input2; 076 077 public TypedIOPort output; 078 079 public Parameter input1_tokenConsumptionRate; 080 081 public Parameter input2_tokenConsumptionRate; 082 083 public Parameter output_tokenProductionRate; 084 085 /** Fire the actor. 086 * Copy one token from input1 to the output and then copy one token 087 * from input2 to the output. 088 * @exception IllegalActionException If a contained method throws it. 089 */ 090 @Override 091 public void fire() throws IllegalActionException { 092 IntToken message; 093 094 message = (IntToken) input1.get(0); 095 output.send(0, message); 096 message = (IntToken) input2.get(0); 097 output.send(0, message); 098 } 099}