}
}
// 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) {