コード例 #1
0
 /* (non-Javadoc)
  * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
  */
 public String getText(Object element) {
   if (element == null) return "";
   if (element instanceof GeneralAttribute) {
     GeneralAttribute.ATTRIBUTE_TYPE type = ((GeneralAttribute) element).getType();
     switch (type) {
       case NAME:
         return "Name";
       case TYPE:
         return "Type";
       case CLASS:
         return "Class";
     }
     return "";
   }
   final Attribute att = (Attribute) element;
   return att.getDisplayName();
 }
コード例 #2
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);
    }
  }