001/*
002 * Copyright (c) 2002-2010 The Regents of the University of California.
003 * All rights reserved.
004 *
005 * '$Author: crawl $'
006 * '$Date: 2015-08-24 22:47:39 +0000 (Mon, 24 Aug 2015) $' 
007 * '$Revision: 33633 $'
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.srb;
031
032import edu.sdsc.grid.io.srb.SRBFileSystem;
033import ptolemy.actor.TypedAtomicActor;
034import ptolemy.actor.TypedIOPort;
035import ptolemy.data.ObjectToken;
036import ptolemy.data.type.BaseType;
037import ptolemy.kernel.CompositeEntity;
038import ptolemy.kernel.util.IllegalActionException;
039import ptolemy.kernel.util.NameDuplicationException;
040
041//////////////////////////////////////////////////////////////////////////
042//// SRBDisconnect
043/**
044 * This actor reads an SRB file.
045 * 
046 * @author Bing Zhu & Efrat Jaeger
047 * @version $Id: SRBDisconnect.java 33633 2015-08-24 22:47:39Z crawl $
048 * @since Ptolemy II 3.0.2
049 */
050public class SRBDisconnect extends TypedAtomicActor {
051
052        /**
053         * Construct an actor with the given container and name.
054         * 
055         * @param container
056         *            The container.
057         * @param name
058         *            The name of this actor.
059         * @exception IllegalActionException
060         *                If the actor cannot be contained by the proposed
061         *                container.
062         * @exception NameDuplicationException
063         *                If the container already has an actor with this name.
064         */
065        public SRBDisconnect(CompositeEntity container, String name)
066                        throws NameDuplicationException, IllegalActionException {
067
068                super(container, name);
069
070                SRBFileSystem = new TypedIOPort(this, "SRBFileSystem", true, false);
071                trigger = new TypedIOPort(this, "trigger", true, false);
072                trigger.setMultiport(true);
073
074                // Set the type constraint.
075                SRBFileSystem.setTypeEquals(BaseType.GENERAL);
076                trigger.setTypeEquals(BaseType.GENERAL);
077
078                _attachText(
079                                "_iconDescription",
080                                "<svg>\n"
081                                                + "<text x=\"0\" y=\"30\""
082                                                + "style=\"font-size:40; fill:blue; font-family:Verdana font-style:italic; font-weight:bold\">"
083                                                + "SRB</text>\n" + "</svg>\n");
084
085        }
086
087        // /////////////////////////////////////////////////////////////////
088        // // ports and parameters ////
089
090        /**
091         * Connection reference
092         */
093        public TypedIOPort SRBFileSystem;
094
095        public TypedIOPort trigger;
096
097        // /////////////////////////////////////////////////////////////////
098        // // public methods ////
099
100        /**
101         * Closes the SRB connection.
102         */
103        public void fire() throws IllegalActionException {
104                for (int i = 0; i < trigger.getWidth(); i++) { // make sure all the
105                                                                                                                // processes have
106                                                                                                                // terminated before
107                                                                                                                // closing the
108                                                                                                                // connection.
109                        if (trigger.hasToken(i)) {
110                                trigger.get(i);
111                        }
112                }
113                SRBFileSystem srbFileSystem = (SRBFileSystem) ((ObjectToken) SRBFileSystem
114                                .get(0)).getValue();
115                srbFileSystem = SRBUtil.closeConnection(srbFileSystem);
116        }
117
118        /**
119         * Post fire the actor. Return false to indicate that the process has
120         * finished.
121         */
122        public boolean postfire() {
123                return false; // FIX ME
124        }
125}