Package ptolemy.actor.util

Examples of ptolemy.actor.util.Time


    public void initialize() throws IllegalActionException {
        if (_isEmbedded()) {
            _outsideTime = ((CompositeActor) getContainer())
                    .getExecutiveDirector().getModelTime();
        } else {
            _outsideTime = new Time(this);
            _nextIterationTime = new Time(this);
        }

        super.initialize();
        _realStartTime = System.currentTimeMillis();

        if (_isEmbedded() && !_interruptQueue.isEmpty()) {
            Time nextPureEventTime = _interruptQueue.get().timeStamp();
            _requestFiringAt(nextPureEventTime);
        }

        _displaySchedule("", 0.0, ScheduleListener.RESET_DISPLAY);
    }
View Full Code Here


            }
        }

        // cache the current time for calculation of elapsed time of
        // started tasks, or, the checkpoint time.
        Time cachedCurrentTime = getModelTime();

        // Synchronized to outside time to process DEEvents and TMEvents.
        setModelTime(_outsideTime);

        if (_debugging) {
            _debug("The size of the eventQueue " + _eventQueue.size());
        }

        if (!_eventQueue.isEmpty()) {
            TMEvent event = (TMEvent) _eventQueue.get();

            if (event.hasStarted()) {
                if (_debugging) {
                    _debug("deduct "
                            + getModelTime().subtract(cachedCurrentTime)
                                    .getDoubleValue(),
                            " from processing time of event", event.toString());
                }

                event.timeProgress(getModelTime().subtract(cachedCurrentTime)
                        .getDoubleValue());

                // Finish the tasks if it ends at this time.
                // We do it here to ensure that it is done before
                // the transfer input from composite actors.
                // setCurrentTime(_outsideTime);
                if (_debugging) {
                    _debug("The remaining processing time is "
                            + event.processingTime());
                }

                if (Math.abs(event.processingTime()) < 1e-10) {
                    if (_debugging) {
                        _debug(getName(), "finish processing ", event
                                .toString());
                    }

                    _eventQueue.take();

                    Actor actor = event.actor();
                    actor.fire();

                    // Actor stops executing, i.e. finishing
                    _displaySchedule(((Nameable) actor).getName(),
                            getModelTime().getDoubleValue(),
                            ScheduleListener.TASK_SLEEPING);
                    _displaySchedule();

                    // Should handle dead actors.
                    if (!actor.postfire()) {
                        _disableActor(actor);
                    }
                } else {
                    if (_debugging) {
                        _debug(getName(), "still needs processing time as "
                                + event.processingTime());
                    }
                }
            }
        }

        // check the interupt queue:
        while (!_interruptQueue.isEmpty()) {
            DEEvent interruptEvent = _interruptQueue.get();
            Time timeStamp = interruptEvent.timeStamp();

            if (timeStamp.compareTo(_outsideTime) < 0) {
                // This should never happen.
                throw new IllegalActionException(this,
                        "external input in the past: " + "input time stamp is "
                                + timeStamp + "current time in TM is "
                                + getModelTime());
            } else if (timeStamp.compareTo(_outsideTime) == 0) {
                _interruptQueue.take();

                Actor actor = interruptEvent.actor();

                if (actor != null) {
View Full Code Here

    ////                         private methods                   ////
    // Remove useless parameters inherited from DEDirector, and set
    // different defaults.
    private void _initParameters() {
        try {
            _startTime = new Time(this);
            _stopTime = new Time(this, Double.POSITIVE_INFINITY);

            startTime = new Parameter(this, "startTime", new DoubleToken(
                    _startTime.getDoubleValue()));
            startTime.setTypeEquals(BaseType.DOUBLE);
            stopTime = new Parameter(this, "stopTime", new DoubleToken(
View Full Code Here

        }

        Director director = getDirector();

        if (director != null) {
            director.fireAt(this, new Time(director));
        } else {
            throw new IllegalActionException(this, "No director");
        }
    }
View Full Code Here

     */
    public void fire() throws IllegalActionException {
        super.fire();

        // Get the current time and period.
        Time currentTime = getDirector().getModelTime();

        // Indicator whether we've reached the next event.
        _boundaryCrossed = false;

        _tentativeCurrentOutputIndex = _currentOutputIndex;

        output.send(0, _getValue(_tentativeCurrentOutputIndex));

        // In case current time has reached or crossed a boundary to the
        // next output, update it.
        if (currentTime.compareTo(_nextFiringTime) == 0) {
            _tentativeCurrentOutputIndex++;

            if (_tentativeCurrentOutputIndex >= _length) {
                _tentativeCurrentOutputIndex = 0;
            }
View Full Code Here

    public void initialize() throws IllegalActionException {
        super.initialize();
        _tentativeCurrentOutputIndex = 0;
        _currentOutputIndex = 0;

        Time currentTime = getDirector().getModelTime();
        _nextFiringTime = currentTime;

        if (((BooleanToken) fireAtStart.getToken()).booleanValue()) {
            getDirector().fireAt(this, currentTime);
        } else {
View Full Code Here

     *  in executing getNextToken().
     */
    public void fire() throws IllegalActionException {
        super.fire();
        StringToken token = null;
        Time time;

        while (true) {
            token = (StringToken) getNextToken();
            time = getDirector().getModelTime();

View Full Code Here

                // protected, but not accessible here.
                // Note, WallClockTime._getCurrentTime() returns a double,
                // which we are going to compare against model time,
                // so we create a Time object that accounts for the
                // precision of the director.
                Time firingTime = new Time(director, _getCurrentTime());

                Time currentTime = director.getModelTime();

                if (firingTime.compareTo(currentTime) < 0) {
                    // This shouldn't happen, but it will prevent us
                    // from enqueuing events in the past
                    firingTime = currentTime;
View Full Code Here

    public void fire() throws IllegalActionException {
        super.fire();

        if (_receptions != null) {
            // We may be getting fired because of an impending event.
            Time currentTime = getDirector().getModelTime();
            Double timeDouble = Double.valueOf(currentTime.getDoubleValue());
            Reception reception = (Reception) _receptions.get(timeDouble);

            if (reception != null) {
                // The time matches a pending reception.
                _receptions.remove(timeDouble);
View Full Code Here

            // called only if the receiver is in range at the
            // initiation of the transmission.
            WirelessIOPort destination = (WirelessIOPort) receiver
                    .getContainer();
            double distance = _distanceBetween(sender, destination);
            Time time = director.getModelTime().add(distance / speed);

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

            Double timeDouble = Double.valueOf(time.getDoubleValue());
            Reception reception = new Reception();
            reception.token = token;
            reception.sender = sender;
            reception.receiver = receiver;
            reception.properties = properties;
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.