001/* Interface for objects that can be initialized.
002
003 Copyright (c) 2007-2013 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.actor;
028
029import ptolemy.kernel.util.IllegalActionException;
030
031///////////////////////////////////////////////////////////////////
032//// Initializable
033
034/**
035 This interface defines a subset of the <i>action methods</i> for initialization
036 and wrapup. It should be implemented by objects that do not need to invoked
037 during runtime, but should be invoked in preinitialize() (exactly once,
038 prior to type resolution), in initialize() (which could happen repeatedly during
039 execution), or wrapup() (exactly once, at the end of execution).
040
041 @author Edward A. Lee
042 @version $Id$
043 @since Ptolemy II 6.1
044 @Pt.ProposedRating Green (eal)
045 @Pt.AcceptedRating Red (cxh)
046 */
047public interface Initializable {
048
049    ///////////////////////////////////////////////////////////////////
050    ////                         public methods                    ////
051
052    /** Add the specified object to the set of objects whose
053     *  preinitialize(), initialize(), and wrapup()
054     *  methods should be invoked upon invocation of the corresponding
055     *  methods of this object.
056     *  @param initializable The object whose methods should be invoked.
057     *  @see #removeInitializable(Initializable)
058     */
059    public void addInitializable(Initializable initializable);
060
061    /** Begin execution of the actor.  This is invoked exactly once
062     *  after the preinitialization phase.  Since type resolution is done
063     *  in the preinitialization phase, along with topology changes that
064     *  may be requested by higher-order function actors, an actor
065     *  can produce output data and schedule events in the initialize()
066     *  method.
067     *
068     *  @exception IllegalActionException If execution is not permitted.
069     */
070    public void initialize() throws IllegalActionException;
071
072    /** This method should be invoked exactly once per execution
073     *  of a model, before any of these other methods are invoked.
074     *  For actors, this is invoked prior to type resolution and
075     *  may trigger changes in the topology, changes in the
076     *  type constraints.
077     *
078     *  @exception IllegalActionException If initializing is not permitted.
079     */
080    public void preinitialize() throws IllegalActionException;
081
082    /** Remove the specified object from the set of objects whose
083     *  preinitialize(), initialize(), and wrapup()
084     *  methods should be invoked upon invocation of the corresponding
085     *  methods of this object. If the specified object is not
086     *  on the list, do nothing.
087     *  @param initializable The object whose methods should no longer be invoked.
088     *  @see #addInitializable(Initializable)
089     */
090    public void removeInitializable(Initializable initializable);
091
092    /** This method is invoked exactly once per execution
093     *  of an application.  None of the other action methods should be
094     *  be invoked after it.  It finalizes an execution, typically closing
095     *  files, displaying final results, etc.  When this method is called,
096     *  no further execution should occur.
097     *
098     *  @exception IllegalActionException If wrapup is not permitted.
099     */
100    public void wrapup() throws IllegalActionException;
101}