Beispiel #1
0
  // This is an overload of redetectCaptureDevices.  It is meant to only redetect devices for
  // one CaptureDeviceManager.  For instance discover NetworkEncoder devices
  public void redetectCaptureDevices(CaptureDeviceManager mgr) {
    if (Sage.DBG) System.out.println("MMC is re-doing the capture device detection on " + mgr);
    mgr.detectCaptureDevices(
        (CaptureDevice[]) globalEncoderMap.values().toArray(new CaptureDevice[0]));
    CaptureDevice[] newDevs = mgr.getCaptureDevices();

    if (Sage.DBG) System.out.println("devices detected=" + java.util.Arrays.asList(newDevs));
    updateCaptureDeviceObjects(newDevs);

    if (Sage.DBG) System.out.println("EncoderMap=" + globalEncoderMap);
    NetworkClient.distributeRecursivePropertyChange("mmc/encoders");
    Seeker.getInstance().kick();
    Scheduler.getInstance().kick(true);
  }
Beispiel #2
0
  public Parser(String input) throws ParsingException {
    this.input = input;

    final StringTokenizer st = new StringTokenizer(input);
    final int tokenCount = st.countTokens();
    if (tokenCount == 1) {
      // Try for a schedule name
      final String name = st.nextToken();
      final String cron = Scheduler.getInstance().getNamedSchedule(name);
      if (cron == null) {
        throw new ParsingException("Named schedule not found: " + name);
      }
      final Parser subParser = new Parser(cron);
      minutes = subParser.minutes;
      hours = subParser.hours;
      days = subParser.days;
      dates = subParser.dates;
      months = subParser.months;
      isYear = subParser.isYear;
      years = subParser.years;
      record = subParser.record;
    } else if (tokenCount == 6) {
      minutes = parseList(st.nextToken(), 0, 59);
      hours = parseList(st.nextToken(), 0, 23);
      days = parseList(st.nextToken(), 0, 7);
      dates = parseList(st.nextToken(), 1, 31);
      months = parseList(st.nextToken(), 1, 12);
      isYear = true;
      years = parseList(st.nextToken(), 0, 49);
      if (days[0] || days[7]) {
        // Both 0 and 7 are Sunday
        days[0] = true;
        days[7] = true;
      }

      record = new Record(minutes, hours, days, dates, months, years);
    } else {
      throw new ParsingException("Invalid number of tokens");
    }
    ba = null;
    tokenStream = null;
  }
Beispiel #3
0
public abstract class EventLoop {

  static final Scheduler scheduler = Scheduler.getInstance();

  long start;

  // The following stuff is reported in stats
  protected String causeOfTermination;
  protected long simTime;
  protected long realTime;

  protected void preSimulationLoop() {
    causeOfTermination = null;
    start = System.currentTimeMillis();
  };

  protected void postSimulationLoop() {
    if (causeOfTermination == null) causeOfTermination = "Max Simulation Time Reached";

    realTime = System.currentTimeMillis() - start;
    simTime = scheduler.now;
    System.out.println("NOW EXITING");

    // P.rint(causeOfTermination);
  }

  protected void prematureTermination(Throwable t) {
    causeOfTermination = t.getMessage();
    realTime = System.currentTimeMillis() - start;
    simTime = scheduler.now;

    // P.rint(causeOfTermination);
    // P.rint(t);
    t.printStackTrace();
  }

  protected void preEventExecution() {};

  protected abstract boolean postEventExecution();

  public boolean run() {
    try {
      preSimulationLoop();
      while (true) {
        Event e = scheduler.dequeue();
        if (e != null && scheduler.now < Conf.MAX_SIMULATION_TIME) {
          preEventExecution();
          e.handle();
          if (postEventExecution()) {
            break;
          }
        } else {
          break; // simulationEnded
        }
      }
      postSimulationLoop();
      return true;
    } catch (Throwable t) {
      prematureTermination(t);
      return false;
    }
  }
}