コード例 #1
0
 /**
  * Set the container and register this as an initializable in the container.
  *
  * @param container The container
  * @exception IllegalActionException If this attribute is not of the expected class for the
  *     container, or it has no name, or the attribute and container are not in the same workspace,
  *     or the proposed container would result in recursive containment.
  * @exception NameDuplicationException If the container already has an attribute with the name of
  *     this attribute that is of class SingletonConfigurableAttribute.
  */
 @Override
 public void setContainer(NamedObj container)
     throws IllegalActionException, NameDuplicationException {
   NamedObj oldContainer = getContainer();
   if (oldContainer instanceof Initializable) {
     ((Initializable) oldContainer).removeInitializable(this);
   }
   super.setContainer(container);
   if (container instanceof Initializable) {
     ((Initializable) container).addInitializable(this);
   }
 }
コード例 #2
0
ファイル: IDAttribute.java プロジェクト: sf577/Project
  /**
   * React to a change in an attribute. If the attribute is <i>name</i>, then change the name of the
   * container to match.
   *
   * @param attribute The attribute that changed.
   * @exception IllegalActionException If the change is not acceptable to this container (not thrown
   *     in this base class).
   */
  public void attributeChanged(Attribute attribute) throws IllegalActionException {
    if (attribute == name) {
      Nameable container = getContainer();

      try {
        container.setName(name.getExpression());
      } catch (NameDuplicationException e) {
        throw new IllegalActionException(
            this, e, "Cannot change the name of the container to match.");
      }
    } else {
      super.attributeChanged(attribute);
    }
  }
コード例 #3
0
ファイル: GiottoTimingManager.java プロジェクト: ptII/ptII
  /**
   * If the attribute is <i>seed</i> then create the base random number generator.
   *
   * @param attribute The attribute that changed.
   * @exception IllegalActionException If the change is not acceptable to this container (not thrown
   *     in this base class).
   */
  public void attributeChanged(Attribute attribute) throws IllegalActionException {
    if (attribute == seed) {
      long seedValue = ((LongToken) (seed.getToken())).longValue();

      if (seedValue != _generatorSeed) {
        _needNewGenerator = true;
      }
    }
    if (attribute == probabilityDistribution) {

    } else {
      super.attributeChanged(attribute);
    }
  }
コード例 #4
0
ファイル: IDAttribute.java プロジェクト: sf577/Project
 /** Update the modification date of this attribute. */
 public void updateContent() throws InternalErrorException {
   super.updateContent();
   _updateDate();
 }
コード例 #5
0
ファイル: GiottoTimingManager.java プロジェクト: ptII/ptII
  /**
   * Specify the container. If the container is not the same as the previous container, then start
   * monitoring the new container.
   *
   * @param container The container to attach this attribute to..
   * @exception IllegalActionException If this attribute is not of the expected class for the
   *     container, or it has no name, or the attribute and container are not in the same workspace,
   *     or the proposed container would result in recursive containment.
   * @exception NameDuplicationException If the container already has an attribute with the name of
   *     this attribute.
   * @see #getContainer()
   */
  public void setContainer(final NamedObj container)
      throws IllegalActionException, NameDuplicationException {
    if (_debugging) {
      _debug("set container method called");
    }
    NamedObj previousContainer = getContainer();
    if (previousContainer == container) {
      return;
    }

    if ((previousContainer != null) && (previousContainer instanceof CompositeActor)) {
      // _piggybackContainer should be non-null, but we check anyway.
      if (_piggybackContainer != null) {
        _piggybackContainer.removePiggyback(_executable);
      }
      _executable = null;
      String name;
      try {
        workspace().getWriteAccess();
        List<Actor> entities = ((CompositeActor) previousContainer).deepEntityList();
        for (Actor entity : entities) {
          List<Attribute> paramList = ((Entity) entity).attributeList();
          for (Attribute param : paramList) {
            name = param.getDisplayName();
            if (name.equals("WCET") || name.equals("executionTime")) {
              // param.setPersistent(false);
            }
          }
        }
      } catch (Exception ex) { // this should later be replaced with a more specific exception
        throw new InternalErrorException(ex);
      } finally {
        workspace().doneTemporaryWriting();
      }
      if (_debugging) {
        _debug("I should remove all the attributes that were added here.");
      }
    }
    super.setContainer(container);

    if (container != null && container instanceof CompositeActor) {
      if (_executable == null) {

        _executable =
            new Executable() {

              public void initialize() throws IllegalActionException {
                if (_random == null || ((BooleanToken) resetOnEachRun.getToken()).booleanValue()) {
                  _createGenerator();
                }
                _needNew = true;
              }

              public boolean postfire() throws IllegalActionException {

                if (_debugging) {
                  _debug("I should now check to see if there are cumulative overruns");
                }
                _needNew = true;

                // here check to see if there were cumulative timing overruns

                if (_debugging) {
                  _debug(
                      "execution times are: "
                          + _totalObservedExecutionTime
                          + " period is: "
                          + _totalExpectedExecutionTime);
                }
                if (_totalObservedExecutionTime > _totalExpectedExecutionTime) {
                  if (_debugging) {
                    _debug("There was a timing overrun");
                  }
                  if (_debugging) {
                    _debug("There was a timing overrun");
                  }
                  handleModelError(
                      container,
                      new IllegalActionException(
                          container,
                          "total ExecutionTime  of ("
                              + _totalObservedExecutionTime
                              + ") is larger than Period of ("
                              + _totalExpectedExecutionTime
                              + ")  for actor "
                              + container.getDisplayName()));
                }
                _totalObservedExecutionTime = 0; // reset the observed time

                ChangeRequest request =
                    new ChangeRequest(
                        this,
                        "SetVariable change request",
                        true /*Although this not a structural change in my point of view
                             , we however for some reason need to specify it is, otherwise the GUI won't update.*/) {
                      protected void _execute() throws IllegalActionException {}
                    };
                // To prevent prompting for saving the model, mark this
                // change as non-persistent.
                request.setPersistent(false);
                requestChange(request);
                if (_debugging) {
                  _debug("Finished checking for overruns");
                }
                return true;
              }

              public void wrapup() {
                ChangeRequest request =
                    new ChangeRequest(this, "SetVariable change request", true) {
                      protected void _execute() throws IllegalActionException {}
                    };
                // To prevent prompting for saving the model, mark this
                // change as non-persistent.
                request.setPersistent(false);
                requestChange(request);
              }

              public void fire() throws IllegalActionException {
                if (!_readyToFire) {
                  return;
                }
                if (_debugging) {
                  _debug("Inside the fire method and the container is " + container);
                }
                if (_debugging) {
                  _debug("Fire method called in the quantity manager");
                }
                if (_needNewGenerator) {
                  _createGenerator();
                }

                if (_needNew) {
                  _generateRandomNumber();
                  _needNew = false;
                }

                if (!_readyToFire) {
                  return;
                }

                while ((_unitIndex < _schedule.size())) {

                  // Grab the next minor cycle (unit) schedule to execute.
                  Schedule unitSchedule = (Schedule) _schedule.get(_unitIndex);

                  Iterator scheduleIterator = unitSchedule.iterator();

                  while (scheduleIterator.hasNext()) {
                    Actor actor = ((Firing) scheduleIterator.next()).getActor();
                    if (_debugging) {
                      _debug("actor to be fired in this iteration has name " + actor.getFullName());
                    }

                    _myPhysicalTime =
                        actor.getDirector().getModelTime().getDoubleValue() + _overRunThusFar;

                    double actorWCET;
                    Attribute executionTime = ((Entity) actor).getAttribute("executionTime");

                    Attribute WCET = ((Entity) actor).getAttribute("WCET");
                    actorWCET = ((DoubleToken) ((Variable) WCET).getToken()).doubleValue();
                    double t =
                        _random.nextDouble()
                            * 2
                            * actorWCET; // I multiply by actorWCET in an attempt to scale
                    if (_debugging) {
                      _debug("simulated execution time is " + t);
                    }
                    _totalObservedExecutionTime += t;
                    if (t > actorWCET) {
                      _overRunThusFar += (t - actorWCET);
                      _myPhysicalTime += t; // (_overRunThusFar;
                      if (_debugging) {
                        _debug(
                            "the actor WCET estimate was "
                                + actorWCET
                                + " and the actual execution time was "
                                + t);
                        _debug(
                            "there was an error at model time "
                                + (actor.getDirector().getModelTime().getDoubleValue() + actorWCET)
                                + "physical time is actually "
                                + _myPhysicalTime);
                      }
                    }
                    Parameter dummyP = (Parameter) executionTime;
                    dummyP.setExpression(Double.toString(t));

                    if (_debugging) {
                      _debug(
                          "Done firing actor "
                              + actor
                              + " now going to check to see if it went over time.");
                    }
                  }

                  scheduleIterator = unitSchedule.iterator();

                  while (scheduleIterator.hasNext()) {
                    Actor actor1 = ((Firing) scheduleIterator.next()).getActor();

                    if (_debugging) {
                      _debug("Iterating " + ((NamedObj) actor1).getFullName());
                    }

                    if (actor1.iterate(1) == STOP_ITERATING) {
                      // FIXME: How to handle this?
                      // put the actor on a no-fire hashtable?
                      System.err.println(
                          "Warning: Giotto iterate returned "
                              + "STOP_ITERATING for actor \""
                              + actor1.getFullName()
                              + "\"");
                    }
                  }

                  _unitIndex++;
                }

                if (_unitIndex >= _schedule.size()) {
                  _unitIndex = 0;
                }
              }

              public boolean isFireFunctional() {
                return true;
              }

              public boolean isStrict() {
                return true;
              }

              public int iterate(int count) {
                return Executable.COMPLETED;
              }

              public boolean prefire() throws IllegalActionException {

                return true;
              }

              public void stop() {}

              public void stopFire() {}

              public void terminate() {}

              public void addInitializable(Initializable initializable) {}

              public void preinitialize() throws IllegalActionException {
                double wcet = 0;
                double _periodValue = 0;

                wcet = _getDirectorWCET(container);
                _periodValue = _getDirectorPeriod(container);

                // Next, construct the schedule.
                // FIXME: Note that mutations will not be supported since the
                // schedule is constructed only once.
                GiottoScheduler scheduler =
                    (GiottoScheduler)
                        ((GiottoDirector) ((CompositeActor) container).getDirector())
                            .getScheduler();
                _schedule = scheduler.getSchedule();
                // _unitTimeIncrement = scheduler._getMinTimeStep(_periodValue);

                if (_debugging) {
                  _debug(
                      "the WCET time seen by the director is "
                          + wcet
                          + " and the period is "
                          + _periodValue);
                }
                if (wcet > _periodValue) {

                  if (_debugging) {
                    _debug("throw an exception");
                  }
                  // this is the static check before execution
                  throw new IllegalActionException(
                      container,
                      "total WCET of ("
                          + wcet
                          + ") is larger than period ("
                          + _periodValue
                          + ") for actor "
                          + ((CompositeActor) (getContainer())).getDisplayName());
                } // end of if
                if (_debugging) {
                  _debug("at the end of preinitialize in the timing quantity manager.");
                }
              }

              public void removeInitializable(Initializable initializable) {}
            };
      }

      _piggybackContainer = (CompositeActor) container;
      _piggybackContainer.addPiggyback(_executable);
    }
  }