Package ptolemy.actor.util

Examples of ptolemy.actor.util.Time


        _actor = actor;
        _receiverList = new LinkedList();
        _receiverComparator = new ReceiverComparator(this);

        _setReceiverPriorities();
        _currentTime = new Time(actor.getDirector());
        _outputTime = new Time(actor.getDirector());
    }
View Full Code Here


     *  This method is not synchronized so the calling method should be.
     *  @param receiver The receiver that is causing this method to be invoked.
     */
    public void sendOutNullTokens(DDEReceiver receiver) {
        Iterator ports = _actor.outputPortList().iterator();
        Time time = getModelTime();

        while (ports.hasNext()) {
            IOPort port = (IOPort) ports.next();
            Receiver[][] receivers = port.getRemoteReceivers();

            for (int i = 0; i < receivers.length; i++) {
                for (int j = 0; j < receivers[i].length; j++) {
                    if (time
                            .compareTo(((DDEReceiver) receivers[i][j])._lastTime) > 0) {
                        ((DDEReceiver) receivers[i][j]).put(new NullToken(),
                                time);
                    }
                }
View Full Code Here

            PrioritizedTimedQueue prioritizedTimedQueue) {
        if (_receiverList == null) {
            _receiverList = new LinkedList();
        }

        Time time = prioritizedTimedQueue.getReceiverTime();

        if (time.getDoubleValue() == PrioritizedTimedQueue.IGNORE) {
            _ignoredReceivers = true;
        }

        if (!_receiverList.contains(prioritizedTimedQueue)) {
            // Add receiver to list with a touch of
            // optimization before actually sorting.
            if (time.getDoubleValue() > 0) {
                _receiverList.addFirst(prioritizedTimedQueue);
            } else {
                _receiverList.addLast(prioritizedTimedQueue);
            }
        }
View Full Code Here

                //Call fireAt to set the color back to white after the delay time.
                Director director = getDirector();
                double delayTime = ((DoubleToken) delay.getToken())
                        .doubleValue();
                Time time = director.getModelTime().add(delayTime);
                director.fireAt(this, time);
            } else if (getName().equals(routeTo) || (hops == 0)) {
                // Change the color of the icon to green.
                _circle2.fillColor.setToken("{0.0, 1.0, 0.0, 1.0}");

                CompositeEntity container = (CompositeEntity) getContainer();
                Entity destNode = container.getEntity(destination);
                Locatable destLocation = (Locatable) destNode.getAttribute(
                        "_location", Locatable.class);
                Locatable myLocation = (Locatable) this.getAttribute(
                        "_location", Locatable.class);

                if ((destLocation == null) || (myLocation == null)) {
                    throw new IllegalActionException(
                            "Cannot determine location for node "
                                    + destNode.getName() + ".");
                }

                Iterator nodes = _connectedNodes.iterator();
                double minDistance = _distanceBetween(destLocation, myLocation);
                String to = " ";
                boolean multi = ((BooleanToken) doublePath.getToken())
                        .booleanValue();
                double nextMinDistance = _distanceBetween(destLocation,
                        myLocation);
                String to2 = " ";

                while (nodes.hasNext()) {
                    Entity node = (Entity) nodes.next();
                    Locatable location = (Locatable) node.getAttribute(
                            "_location", Locatable.class);

                    if (location == null) {
                        throw new IllegalActionException(
                                "Cannot determine location for node "
                                        + node.getName() + ".");
                    }

                    double d = _distanceBetween(destLocation, location);

                    if (multi) {
                        if (d < minDistance) {
                            nextMinDistance = minDistance;
                            to2 = to;
                            minDistance = d;
                            to = node.getName();
                        } else if (d < nextMinDistance) {
                            nextMinDistance = d;
                            to2 = node.getName();
                        }
                    } else {
                        if (d < minDistance) {
                            minDistance = d;
                            to = node.getName();
                        }
                    }
                }

                // Request refiring after a certain amount of time specified
                // by the <i>delay<i> parameter.
                Director director = getDirector();
                Token[] values = { new DoubleToken(data),
                        new StringToken(destination), new StringToken(to),
                        new IntToken(hops + 1) };
                double delayTime = ((DoubleToken) delay.getToken())
                        .doubleValue();
                Time time = director.getModelTime().add(delayTime);

                if (_receptions == null) {
                    _receptions = new HashMap();
                }

                Double timeDouble = Double.valueOf(time.getDoubleValue());
                String[] labels = { "data", "destination", "routeTo", "hops" };
                RecordToken result = new RecordToken(labels, values);
                _receptions.put(timeDouble, result);

                director.fireAt(this, time);

                if (multi) {
                    Token[] values2 = { new DoubleToken(data),
                            new StringToken(destination), new StringToken(to2),
                            new IntToken(hops + 1) };

                    if (_receptions == null) {
                        _receptions = new HashMap();
                    }

                    RecordToken result2 = new RecordToken(labels, values2);
                    _receptions.put(timeDouble, result2);

                    director.fireAt(this, time.add(delayTime));
                }

                //output.send(0, result);
            }
        } else {
View Full Code Here

                        try {
                            if (((DDEReceiver) receivers[i][j])
                                    .getReceiverTime().getDoubleValue() != endTime) {
                                try {
                                    ((DDEReceiver) receivers[i][j]).put(null,
                                            new Time(getActor().getDirector(),
                                                    endTime));
                                } catch (IllegalActionException ex) {
                                    // If the time resolution of the
                                    // director is invalid, it should
                                    // have been caught before this.
View Full Code Here

        if (table != null) {
            Double dTime = (Double) table.get(actor);

            if (dTime != null) {
                try {
                    Time time = new Time(director, dTime.doubleValue());
                    _timeKeeper.setCurrentTime(time);
                } catch (IllegalActionException e) {
                    // If the time resolution of the director is invalid,
                    // it should have been caught before this.
                    throw new InternalErrorException(e);
View Full Code Here

        // hierarchy. The top level advances time, not lower levels.
        // The tree structure of a hierarchy ensures coherence.
        // This hack only works if there is exactly one "inside director."
        // See the Pendulum demo for a model that depends on this.
        try {
            return new Time(this, Double.POSITIVE_INFINITY);
        } catch (IllegalActionException e) {
            // If the time resolution of the director is invalid,
            // it should have been caught before this.
            throw new InternalErrorException(e);
        }
View Full Code Here

     @exception IllegalActionException If there is no director.
     */
    public void fire() throws IllegalActionException {
        super.fire();
        DEDirector dir = (DEDirector) getDirector();
        Time now = dir.getModelTime();

        if (set.hasToken(0)) {
            // reset timer
            double delay = ((DoubleToken) set.get(0)).doubleValue();

            if (delay > 0.0) {
                _expireTime = now.add(delay);
                dir.fireAt(this, _expireTime);
            } else {
                // disable timer
                _expireTime = new Time(dir, -1.0);
            }

            //System.out.println("Reset DETimer " + this.getFullName() +
            //        " to expire at " + _expireTime);
        } else if (now.equals(_expireTime)) {
            // timer expires
            expired.broadcast(_outToken);

            //System.out.println("DETimer " + this.getFullName() +
            //        " expires at " + getCurrentTime());
View Full Code Here

     @exception IllegalActionException If the initialize() of the parent
     *   class throws it.
     */
    public void initialize() throws IllegalActionException {
        super.initialize();
        _expireTime = new Time(getDirector(), -1.0);
    }
View Full Code Here

     */
    public void initialize() throws IllegalActionException {
        super.initialize();
        _firstFire = true;
        _msgNum = 0;
        _nextMsgTime = new Time(getDirector(), -1.0);

        //System.out.println("DEChannel " + getFullName() +
        //        " initializing at time " + getCurrentTime());
        DEDirector dir = (DEDirector) getDirector();
        Time now = dir.getModelTime();
        dir.fireAt(this, now.add(((DoubleToken) maxDelay.getToken())
                .doubleValue()
                * Math.random()));
    }
View Full Code Here

TOP

Related Classes of ptolemy.actor.util.Time

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.