示例#1
0
 public T getContents(String name) {
   return contentsMap.get(name);
 }
示例#2
0
  @Override
  public void run() {

    while (true) {

      switch (playState) {
        case BUFFERING:
          bufferToNextPosition();
          break;

        case PLAYING:
          Date currDate = new Date();
          long elapsed = (int) ((currDate.getTime() - lastSliceRequestDate.getTime()) * playSpeed);
          this.lastSliceRequestDate = currDate;

          // Check if we've been truncated, and move forward if necessary
          if (totalElapsed < timeline.getFirstOffset()) {
            log.info(
                "Elapsed time ({}) occurs before the current timeline ({})",
                totalElapsed,
                timeline.getFirstOffset());

            long position = elapsed;
            boolean noMatch = true;
            while (noMatch) {
              if (position != timeline.getFirstOffset()) {
                position = timeline.getFirstOffset();
                try {
                  Thread.sleep(500);
                } catch (InterruptedException e) {
                  // Ignore
                }
              } else {
                noMatch = false;
              }
            }
            log.info("Will buffer to new position: {}", position);
            bufferAtPosition(position);
            break;
          }

          // Update actors and build a usage map
          Map<String, Integer> slotsUsedByUser = new HashMap<String, Integer>();
          Iterator<? extends Actor> i = getJobActors().values().iterator();
          while (i.hasNext()) {
            Actor actor = i.next();
            if (actor instanceof JobActor) {
              JobActor jobActor = (JobActor) actor;
              if (jobActor.defunct) {
                removeJobActor(jobActor.name, jobActor);
              } else {
                int slots = 1;
                if (jobActor.queued) {
                  // If a job is queued then it is represented by a single sprite, so we need the
                  // actual number of slots
                  GridJob job = state.getJobByFullId(jobActor.name);
                  if (job != null) {
                    slots = job.getSlots();
                  }
                }

                if (jobActor.getName().contains(":")) {
                  // Parse a jobId like this: 1275988.2828-4000:1
                  try {
                    Pattern p = Pattern.compile("(\\d+)\\.(\\d+)-(\\d+):(\\d+)");
                    Matcher m = p.matcher(jobActor.getName());
                    if (m.matches()) {
                      int start = Integer.parseInt(m.group(2));
                      int end = Integer.parseInt(m.group(3));
                      int interval = Integer.parseInt(m.group(4));
                      slots = (end - start) / interval;
                    }
                  } catch (Exception e) {
                    log.error("Error parsing jobId: " + jobActor.getName(), e);
                  }
                } else if (jobActor.getName().contains(",")) {
                  // Parse a jobId like this: 2968157.205,211
                  try {
                    Pattern p = Pattern.compile("(\\d+)\\.(\\d+),(\\d+)");
                    Matcher m = p.matcher(jobActor.getName());
                    if (m.matches()) {
                      int first = Integer.parseInt(m.group(2));
                      int second = Integer.parseInt(m.group(3));
                      // There are two jobs listed here, so we require twice the number of slots
                      slots *= 2;
                    }
                  } catch (Exception e) {
                    log.error("Error parsing jobId: " + jobActor.getName(), e);
                  }
                }

                String user = jobActor.getUsername();
                if (!slotsUsedByUser.containsKey(user)) {
                  slotsUsedByUser.put(user, 0);
                }
                if (!jobActor.queued) {
                  slotsUsedByUser.put(user, slotsUsedByUser.get(user) + slots);
                }
              }
            }
          }

          legend.retain(slotsUsedByUser);

          updateState(elapsed);

          break;

        case READY:
          break;

        case PAUSED:
          break;

        case END:
          return;

        default:
          log.error("Invalid play state: " + playState);
          break;
      }

      try {
        Thread.sleep(50);
      } catch (InterruptedException e) {
        // Ignore
      }
    }
  }
示例#3
0
 public PVector getLocation(String name) {
   return locationMap.get(name);
 }