Package ptolemy.actor

Examples of ptolemy.actor.IOPort


        ConstVariableModelAnalysis analysis = ConstVariableModelAnalysis
                .getAnalysis(this);
        CompositeActor model = (CompositeActor) getContainer();

        for (Iterator ports = model.portList().iterator(); ports.hasNext();) {
            IOPort port = (IOPort) ports.next();

            if (!(port instanceof ParameterPort)) {
                if (port.isInput()) {
                    _declareReconfigurationDependencyForRefinementRateVariables(
                            analysis, port, "tokenConsumptionRate");
                }

                if (port.isOutput()) {
                    _declareReconfigurationDependencyForRefinementRateVariables(
                            analysis, port, "tokenProductionRate");
                    _declareReconfigurationDependencyForRefinementRateVariables(
                            analysis, port, "tokenInitProduction");
                }
View Full Code Here


        List list = new LinkedList();

        Iterator insidePorts = port.deepInsidePortList().iterator();

        while (insidePorts.hasNext()) {
            IOPort insidePort = (IOPort) insidePorts.next();
            Variable variable = DFUtilities.getRateVariable(insidePort,
                    parameterName);

            if (variable != null) {
                list.add(variable);
View Full Code Here

        // Get all of its input ports of the current refinement actor.
        Iterator refineInPorts = actor.inputPortList().iterator();

        while (refineInPorts.hasNext()) {
            IOPort refineInPort = (IOPort) refineInPorts.next();

            // Get all of the input ports this port is linked to on
            // the outside (should only consist of 1 port).
            Iterator inPortsOutside = refineInPort.deepConnectedInPortList()
                    .iterator();

            if (!inPortsOutside.hasNext()) {
                throw new IllegalActionException("Current "
                        + "state's refining actor has an input port not"
                        + "connected to an input port of its container.");
            }

            while (inPortsOutside.hasNext()) {
                IOPort inputPortOutside = (IOPort) inPortsOutside.next();

                // Check if the current port is contained by the
                // container of the current refinement.
                ComponentEntity thisPortContainer = (ComponentEntity) inputPortOutside
                        .getContainer();

                if (thisPortContainer.getFullName().equals(
                        refineInPortContainer.getFullName())) {
                    // set the outside port rate equal to the port rate
View Full Code Here

        if (propertyName.equals("multiport") && isIOPort) {
            // Special properties that affect the behaviour of a port
            // NOTE: UNDO: Consider refactoring these clauses
            // to remove the duplicate values
            // The previous value is needed to generate undo MoML
            IOPort currentIOPort = (IOPort) _current;

            // The mere presense of a named property "multiport"
            // makes the enclosing port a multiport, unless it
            // has value false.
            // Get the previous value to use when generating the
            // undo MoML
            boolean previousValue = currentIOPort.isMultiport();

            // Default for new value is true, unless it is explicitly false.
            boolean newValue = true;

            if ((value != null) && value.trim().toLowerCase().equals("false")) {
                newValue = false;
            }

            // If this object is a derived object, then its I/O status
            // cannot be changed.
            if ((_current.getDerivedLevel() < Integer.MAX_VALUE)
                    && (((IOPort) _current).isMultiport() != newValue)) {
                throw new IllegalActionException(_current,
                        "Cannot change whether this port is "
                                + "a multiport. That property is fixed by "
                                + "the class definition.");
            }

            ((IOPort) _current).setMultiport(newValue);

            // Propagate.
            Iterator derivedObjects = _current.getDerivedList().iterator();

            while (derivedObjects.hasNext()) {
                IOPort derived = (IOPort) derivedObjects.next();
                derived.setMultiport(newValue);
            }

            _pushContext();
            _current = _current.getAttribute(propertyName);
            _namespace = _DEFAULT_NAMESPACE;

            // Handle undo
            if (_undoEnabled) {
                _undoContext.appendUndoMoML("<property name=\"" + propertyName
                        + "\" value=\"");

                // Use what was there before.
                _undoContext.appendUndoMoML(previousValue + "\" >\n");

                // Continue undoing and also use an end tag as a
                // property can contain other properties
                _undoContext.setChildrenUndoable(true);
                _undoContext.appendClosingUndoMoML("</property>\n");
            }
        } else if (propertyName.equals("output") && isIOPort) {
            // Special properties that affect the behaviour of a port
            // NOTE: UNDO: Consider refactoring these clauses
            // to remove the duplicate values
            // The previous value is needed to generate undo MoML
            IOPort currentIOPort = (IOPort) _current;

            // Get the previous value to use when generating the
            // undo MoML
            boolean previousValue = currentIOPort.isOutput();

            // Default for new value is true, unless it is explicitly false.
            boolean newValue = true;

            if ((value != null) && value.trim().toLowerCase().equals("false")) {
                newValue = false;
            }

            // If this object is a derived object, then its I/O status
            // cannot be changed.
            if ((_current.getDerivedLevel() < Integer.MAX_VALUE)
                    && (((IOPort) _current).isOutput() != newValue)) {
                throw new IllegalActionException(_current,
                        "Cannot change whether this port is "
                                + "an output. That property is fixed by "
                                + "the class definition.");
            }

            ((IOPort) _current).setOutput(newValue);

            // Propagate.
            Iterator derivedObjects = _current.getDerivedList().iterator();

            while (derivedObjects.hasNext()) {
                IOPort derived = (IOPort) derivedObjects.next();
                derived.setOutput(newValue);
            }

            _pushContext();

            _current = _current.getAttribute(propertyName);
            _namespace = _DEFAULT_NAMESPACE;

            // Handle undo
            if (_undoEnabled) {
                _undoContext.appendUndoMoML("<property name=\"" + propertyName
                        + "\" value=\"");

                // Use what was there before
                _undoContext.appendUndoMoML(previousValue + "\" >\n");

                // Continue undoing and also use an end tag as a
                // property can contain other properties
                _undoContext.setChildrenUndoable(true);
                _undoContext.appendClosingUndoMoML("</property>\n");
            }
        } else if (propertyName.equals("input") && isIOPort) {
            // Special properties that affect the behaviour of a port
            // NOTE: UNDO: Consider refactoring these clauses
            // to remove the duplicate values
            // The previous value is needed to generate undo MoML
            IOPort currentIOPort = (IOPort) _current;

            // Get the previous value to use when generating the
            // undo MoML
            boolean previousValue = currentIOPort.isInput();

            // Default for new value is true, unless it is explicitly false.
            boolean newValue = true;

            if ((value != null) && value.trim().toLowerCase().equals("false")) {
                newValue = false;
            }

            // If this object is a derived object, then its I/O status
            // cannot be changed.
            if ((_current.getDerivedLevel() < Integer.MAX_VALUE)
                    && (((IOPort) _current).isInput() != newValue)) {
                throw new IllegalActionException(_current,
                        "Cannot change whether this port is "
                                + "an input. That property is fixed by "
                                + "the class definition.");
            }

            ((IOPort) _current).setInput(newValue);

            // Propagate.
            Iterator derivedObjects = _current.getDerivedList().iterator();

            while (derivedObjects.hasNext()) {
                IOPort derived = (IOPort) derivedObjects.next();
                derived.setInput(newValue);
            }

            _pushContext();
            _current = _current.getAttribute(propertyName);
            _namespace = _DEFAULT_NAMESPACE;

            // Handle undo
            if (_undoEnabled) {
                _undoContext.appendUndoMoML("<property name=\"" + propertyName
                        + "\" value=\"");

                // Use what was there before
                _undoContext.appendUndoMoML(previousValue + "\" >\n");

                // Continue undoing and also use an end tag as a
                // property can contain other properties
                _undoContext.setChildrenUndoable(true);
                _undoContext.appendClosingUndoMoML("</property>\n");
            }
        } else {
            // Ordinary attribute.
            NamedObj property = null;

            if (_current != null) {
                property = _current.getAttribute(propertyName);
            }

            Class newClass = null;

            if (className != null) {
                try {
                    newClass = Class.forName(className, true, _classLoader);
                } catch (NoClassDefFoundError ex) {
                    throw new XmlException("Failed to find class '" + className
                            + "'", _currentExternalEntity(), _getLineNumber(),
                            _getColumnNumber(), ex);
                } catch (SecurityException ex) {
                    // An applet might throw this.
                    throw new XmlException("Failed to find class '" + className
                            + "'", _currentExternalEntity(), _getLineNumber(),
                            _getColumnNumber(), ex);
                }
            }

            // If there is a previous property with this name
            // (property is not null), then we check that the
            // property is an instance of the specified class.
            // If it is, then we set the value of the property.
            // Otherwise, we try to replace it, something that
            // will only work if it is a singleton (it might throw
            // NameDuplicationException).
            boolean previouslyExisted = (property != null);

            // Even if the object previously existed, if the
            // class does not match, we may create a new object.
            boolean createdNew = false;

            // Also need the previous value, if any, to generate undo MoML.
            String oldClassName = null;
            String oldValue = null;

            if (previouslyExisted) {
                oldClassName = property.getClass().getName();

                if (property instanceof Settable) {
                    Settable settable = (Settable) property;
                    oldValue = settable.getExpression();
                }
            }

            if (!previouslyExisted
                    || ((newClass != null) && !newClass.isInstance(property))) {
                // The following will result in a
                // NameDuplicationException if there is a previous
                // property and it is not a singleton.
                try {
                    // No previously existing attribute with this name,
                    // or the class name of the previous entity doesn't
                    // match.
                    if (newClass == null) {
                        newClass = Attribute.class;
                    }

                    // An attribute is not usually a top-level element,
                    // but it might be (e.g. when editing icons).
                    if (_current == null) {
                        // If we want to be able to edit icons, we
                        // have to allow this.
                        // Invoke the constructor.
                        Object[] arguments = new Object[2];
                        arguments[0] = _workspace;
                        arguments[1] = propertyName;
                        property = _createInstance(newClass, arguments);
                        _toplevel = property;
                    } else {
                        // First check that there will be no name collision
                        // when this is propagated. Note that we need to
                        // include all derived objects, irrespective of whether
                        // they are locally changed.
                        List derivedList = _current.getDerivedList();
                        Iterator derivedObjects = derivedList.iterator();

                        while (derivedObjects.hasNext()) {
                            NamedObj derived = (NamedObj) derivedObjects.next();
                            Attribute other = derived
                                    .getAttribute(propertyName);

                            if ((other != null)
                                    && !(other instanceof Singleton)) {
                                throw new IllegalActionException(
                                        _current,
                                        "Cannot create attribute because a subclass or instance "
                                                + "contains an attribute with the same name: "
                                                + derived.getAttribute(
                                                        propertyName)
                                                        .getFullName());
                            }
                        }
View Full Code Here

        // Get all of the current refinement's output ports.
        Iterator refineOutPorts = actor.outputPortList().iterator();

        while (refineOutPorts.hasNext()) {
            IOPort refineOutPort = (IOPort) refineOutPorts.next();

            Iterator outPortsOutside = refineOutPort.deepConnectedOutPortList()
                    .iterator();

            while (outPortsOutside.hasNext()) {
                IOPort outputPortOutside = (IOPort) outPortsOutside.next();

                // Check if the current port is contained by the
                // container of the current refinment.
                ComponentEntity thisPortContainer = (ComponentEntity) outputPortOutside
                        .getContainer();

                if (thisPortContainer.getFullName().equals(
                        refineOutPortContainer.getFullName())) {
                    // set the outside port rate equal to the port rate
View Full Code Here

            Iterator ports = portList().iterator();

            _inputTokensHolder.clear();

            while (ports.hasNext()) {
                IOPort port = (IOPort) ports.next();

                // Store all tokens contained by input ports of this actor
                // because connecting ports will result in creating receivers
                // again and all tokens in the original receivers will be lost.
                if (port.isInput()) {
                    int width = port.getWidth();
                    Receiver[][] receivers = port.getReceivers();
                    Token[][] tokens = new Token[width][0];

                    for (int channel = 0; channel < width; channel++) {
                        int size = ((QueueReceiver) receivers[channel][0])
                                .size();
                        tokens[channel] = new Token[size];

                        for (int count = 0; count < size; count++) {
                            tokens[channel][count] = port.get(channel);
                        }
                    }

                    _inputTokensHolder.put(port, tokens);
                }

                // Connect the corresponding ports of both actors.
                IOPort matchingPort = (IOPort) clone.getPort(port.getName());
                IORelation relation = (IORelation) newRelation("r_" + i++);
                port.link(relation);
                matchingPort.link(relation);

                if (port.isMultiport()) {
                    relation.setWidth(port.getWidth());
                }
            }
View Full Code Here

     */
    private int _getTokenConsumptionRate(Receiver receiver)
            throws IllegalActionException {
        int tokenConsumptionRate;

        IOPort port = receiver.getContainer();
        Variable rateVariable = null;
        Token token = null;
        Receiver[][] portReceivers = null;

        // If DDF domain is inside another domain and the
        // receiver is contained by an opaque output port...
        // The default production rate is -1 which means all
        // tokens in the receiver are transferred to the outside.
        if (port.isOutput()) {
            rateVariable = DFUtilities.getRateVariable(port,
                    "tokenProductionRate");
            portReceivers = port.getInsideReceivers();

            if (rateVariable == null) {
                return -1;
            } else {
                token = rateVariable.getToken();

                if (token == null) {
                    return -1;
                }
            }
        }

        if (port.isInput()) {
            rateVariable = DFUtilities.getRateVariable(port,
                    "tokenConsumptionRate");
            portReceivers = port.getReceivers();

            if (rateVariable == null) {
                return 1;
            } else {
                token = rateVariable.getToken();
View Full Code Here

     */
    private void _setOutputPortRate() throws IllegalActionException {
        Iterator outputPorts = outputPortList().iterator();

        while (outputPorts.hasNext()) {
            IOPort outputPort = (IOPort) outputPorts.next();
            int[] productionRate = new int[outputPort.getWidthInside()];

            // If there are more inside channels than outside channels,
            // it sets default rates of these extra inside channels to
            // be -1 which then won't cause an upstream actor to be
            // deferrable because any tokens on these extra channels
            // are discarded.
            Arrays.fill(productionRate, -1);

            Receiver[][] farReceivers = outputPort.getRemoteReceivers();

            for (int i = 0; i < farReceivers.length; i++) {
                if (i < outputPort.getWidthInside()) {
                    for (int j = 0; j < farReceivers[i].length; j++) {
                        QueueReceiver farReceiver = (QueueReceiver) farReceivers[i][j];
                        int rate = _getTokenConsumptionRate(farReceiver);

                        // According to the definition of deferrability,
                        // we need to find the minimum rate associated with
                        // this channel. -1 is actually the largest rate in
                        // some sense.
                        if (productionRate[i] < 0) {
                            productionRate[i] = rate;
                        } else if ((rate >= 0) && (rate < productionRate[i])) {
                            productionRate[i] = rate;
                        }
                    }
                }
            }

            IntToken[] productionRateToken = new IntToken[outputPort
                    .getWidthInside()];

            for (int i = 0; i < outputPort.getWidthInside(); i++) {
                productionRateToken[i] = new IntToken(productionRate[i]);
            }

            // Since this is output port, we look for token production rate
            // instead of token consumption rate.
View Full Code Here

     */
    private void _transferInputs() throws IllegalActionException {
        Iterator inputPorts = inputPortList().iterator();

        while (inputPorts.hasNext()) {
            IOPort inputPort = (IOPort) inputPorts.next();
            Token[][] tokens = (Token[][]) _inputTokensHolder.get(inputPort);

            for (int channel = 0; channel < inputPort.getWidth(); channel++) {
                for (int j = 0; j < tokens[channel].length; j++) {
                    inputPort.sendInside(channel, tokens[channel][j]);
                }
            }
        }
    }
View Full Code Here

     */
    private void _transferOutputs() throws IllegalActionException {
        Iterator outputPorts = outputPortList().iterator();

        while (outputPorts.hasNext()) {
            IOPort outputPort = (IOPort) outputPorts.next();

            for (int i = 0; i < outputPort.getWidthInside(); i++) {
                while (outputPort.hasTokenInside(i)) {
                    outputPort.send(i, outputPort.getInside(i));
                }
            }
        }
    }
View Full Code Here

TOP

Related Classes of ptolemy.actor.IOPort

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.