001/*
002 * Copyright (c) 2004-2010 The Regents of the University of California.
003 * All rights reserved.
004 *
005 * '$Author: welker $'
006 * '$Date: 2010-05-06 05:21:26 +0000 (Thu, 06 May 2010) $' 
007 * '$Revision: 24234 $'
008 * 
009 * Permission is hereby granted, without written agreement and without
010 * license or royalty fees, to use, copy, modify, and distribute this
011 * software and its documentation for any purpose, provided that the above
012 * copyright notice and the following two paragraphs appear in all copies
013 * of this software.
014 *
015 * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
016 * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
017 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
018 * THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
019 * SUCH DAMAGE.
020 *
021 * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
022 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
023 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
024 * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
025 * CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
026 * ENHANCEMENTS, OR MODIFICATIONS.
027 *
028 */
029
030package org.cipres.kepler;
031
032// Ptolemy package
033import ptolemy.actor.TypedAtomicActor;
034import ptolemy.actor.TypedIOPort;
035import ptolemy.data.StringToken;
036import ptolemy.data.type.BaseType;
037import ptolemy.kernel.CompositeEntity;
038import ptolemy.kernel.util.IllegalActionException;
039import ptolemy.kernel.util.NameDuplicationException;
040
041//////////////////////////////////////////////////////////////////////////
042//// Initializer
043/**
044 * The Initializer actor initializes the Registry of CORBA services used in
045 * CIPRes software package.
046 * 
047 * @author Zhijie Guan
048 * @version $Id: Initializer.java 24234 2010-05-06 05:21:26Z welker $
049 */
050
051public class Initializer extends TypedAtomicActor {
052
053        /**
054         * Construct an Initializer actor with the given container and name.
055         * 
056         * @param container
057         *            The container.
058         * @param name
059         *            The name of this actor.
060         * @exception IllegalActionException
061         *                If the entity cannot be contained by the proposed
062         *                container.
063         * @exception NameDuplicationException
064         *                If the container already has an actor with this name.
065         */
066
067        public Initializer(CompositeEntity container, String name)
068                        throws NameDuplicationException, IllegalActionException {
069                super(container, name);
070
071                // construct the output port outputTrigger
072                outputTrigger = new TypedIOPort(this, "outputTrigger", false, true);
073                outputTrigger.setDisplayName("Trigger");
074                // Set the type constraint.
075                outputTrigger.setTypeEquals(BaseType.GENERAL);
076
077                _attachText("_iconDescription", "<svg>\n" + "<rect x=\"0\" y=\"0\" "
078                                + "width=\"60\" height=\"20\" " + "style=\"fill:white\"/>\n"
079                                + "</svg>\n");
080
081        }
082
083        // /////////////////////////////////////////////////////////////////
084        // // ports and parameters ////
085
086        /**
087         * A trigger signal is sent out through this output port to other actors
088         * that need to use CIPRes CORBA registry. The signal is sent out only after
089         * the CORBA registry is initialized successfully in this actor. This port
090         * is an output port of type GENERAL.
091         */
092        public TypedIOPort outputTrigger = null;
093
094        // /////////////////////////////////////////////////////////////////
095        // // functional variables ////
096
097        // /////////////////////////////////////////////////////////////////
098        // // public methods ////
099
100        /**
101         * Send out a token to indicate that the intialization is successful.
102         * 
103         * @exception IllegalActionException
104         *                If it is thrown by the send() method sending out the
105         *                token.
106         */
107        public void fire() throws IllegalActionException {
108                super.fire();
109
110                // Here comes the initialization of the facilitator
111                // the facilitator should be initialized before any CORBA services is
112                // called
113                String APPLICATION_NAME = "cipres.application";
114                try {
115                        org.cipres.communication.Facilitator.initialize(APPLICATION_NAME);
116                } catch (Exception e) {
117                        e.printStackTrace();
118                }
119
120                // fill this StringToken with a string message.
121                // Since no actor is going to read this message, (this is only a trigger
122                // signal)
123                // it doesn't matter what is put in this message.
124                StringToken trigger = new StringToken("Initialization finished!");
125                outputTrigger.send(0, trigger);
126        }
127
128        /**
129         * Post fire the actor. Return false to indicated that the process has
130         * finished. If it returns true, the process will continue indefinitely.
131         */
132        public boolean postfire() {
133                return false;
134        }
135}