001/* An actor that handles an HttpRequest by producing an output and waiting for an 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 027 */ 028 029package ptolemy.domains.de.test; 030 031import ptolemy.actor.Director; 032import ptolemy.actor.TypedAtomicActor; 033import ptolemy.actor.TypedIOPort; 034import ptolemy.actor.util.Time; 035import ptolemy.data.BooleanToken; 036import ptolemy.data.type.BaseType; 037import ptolemy.domains.de.kernel.DEDirector; 038import ptolemy.kernel.CompositeEntity; 039import ptolemy.kernel.util.IllegalActionException; 040import ptolemy.kernel.util.NameDuplicationException; 041 042/** A test actor to test the cancelFireAt() method of the director. 043 * 044 * @author Edward A. Lee 045 * @version $Id$ 046 * @since Ptolemy II 10.0 047 * @Pt.ProposedRating Red (ltrnc) 048 * @Pt.AcceptedRating Red (ltrnc) 049 */ 050public class CancelFireAtTest extends TypedAtomicActor { 051 052 /** Create an instance of the actor. 053 * @param container The container 054 * @param name The name. 055 * @exception IllegalActionException If the superclass throws it. 056 * @exception NameDuplicationException If the super 057 */ 058 public CancelFireAtTest(CompositeEntity container, String name) 059 throws IllegalActionException, NameDuplicationException { 060 super(container, name); 061 062 // Ports 063 out = new TypedIOPort(this, "out", false, true); 064 out.setTypeEquals(BaseType.BOOLEAN); 065 } 066 067 /////////////////////////////////////////////////////////////////// 068 //// ports and parameters //// 069 070 /** The output. 071 */ 072 public TypedIOPort out; 073 074 /////////////////////////////////////////////////////////////////// 075 //// public methods //// 076 077 /** Send true to the output and cancel the firing at times 1.0 and 3.0. 078 * @exception IllegalActionException If sending the 079 * outputs fails. 080 */ 081 @Override 082 public synchronized void fire() throws IllegalActionException { 083 // The methods of the servlet are invoked in another 084 // thread, so we synchronize on this actor for mutual exclusion. 085 super.fire(); 086 out.send(0, BooleanToken.TRUE); 087 DEDirector director = (DEDirector) getDirector(); 088 director.cancelFireAt(this, new Time(director, 1.0), 1); 089 director.cancelFireAt(this, new Time(director, 3.0)); 090 } 091 092 /** Schedule firings at times 0, 1, 2, 3, 4. 093 * @exception IllegalActionException If the superclass throws it. 094 */ 095 @Override 096 public void initialize() throws IllegalActionException { 097 super.initialize(); 098 Director director = getDirector(); 099 director.fireAt(this, new Time(director, 0.0)); 100 director.fireAt(this, new Time(director, 1.0)); 101 director.fireAt(this, new Time(director, 2.0)); 102 director.fireAt(this, new Time(director, 3.0)); 103 director.fireAt(this, new Time(director, 4.0)); 104 } 105}