Beispiel #1
0
  /** Returns a StringRepresentation with the status of the running threads in the thread pool. */
  private void handleProgress(Request req, Response resp, ArrayList<GWCTaskStatus> taskList)
      throws RestletException {

    Object[] tasks = taskList.toArray();

    StringBuilder strBld = new StringBuilder();
    strBld.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
    strBld.append("<Tasks>");

    XStream xs = new XStream();
    xs.omitField(GWCTask.class, "parsedType");
    xs.omitField(GWCTask.class, "state");
    xs.omitField(GWCTask.class, "sharedThreadCount");
    xs.omitField(GWCTask.class, "groupStartTime");
    xs.omitField(GWCTask.class, "storageBroker");

    xs.alias("GWCTaskStatus", GWCTaskStatus.class);

    for (int i = 0; i < tasks.length; i++) {
      GWCTaskStatus taskStatus = (GWCTaskStatus) tasks[i];
      Iterator<Entry<Long, GWCTask>> iter = seeder.getRunningTasksIterator();

      while (iter.hasNext()) {
        Entry<Long, GWCTask> entry = iter.next();
        GWCTask task = entry.getValue();
        if (task.getDbId() == taskStatus.getDbId()) {
          taskStatus.setTaskId(task.getTaskId());
          taskStatus.setThreadRunning(true);
          taskStatus.setTilesDone(task.getTilesDone());
          taskStatus.setTilesTotal(task.getTilesTotal());
          taskStatus.setTimeSpent(task.getTimeSpent());
          taskStatus.setTimeRemaing(task.getTimeRemaining());
        }
      }
      String task_xml = xs.toXML(taskStatus);
      strBld.append(task_xml);
    }

    strBld.append("</Tasks>");
    resp.setEntity(strBld.toString(), MediaType.TEXT_XML);
  }
Beispiel #2
0
  private void handleCancel(Request req, Response resp, ArrayList<GWCTaskStatus> taskList)
      throws RestletException {

    StringBuilder strBld = new StringBuilder();
    strBld.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
    strBld.append("<CancelResults>");

    Object[] tasks = taskList.toArray();
    for (int i = 0; i < tasks.length; i++) {
      GWCTaskStatus taskStatus = (GWCTaskStatus) tasks[i];
      strBld.append("<Task>");
      strBld.append("<dbId>" + taskStatus.getDbId() + "</dbId>");
      strBld.append("<CancelResult>");
      Iterator<Entry<Long, GWCTask>> iter = seeder.getRunningTasksIterator();
      while (iter.hasNext()) {
        Entry<Long, GWCTask> entry = iter.next();
        GWCTask task = entry.getValue();
        if (task.getDbId() == taskStatus.getDbId()) {
          taskStatus.setThreadRunning(true);
          taskStatus.setTaskId(task.getTaskId());
        }
      }
      if (!taskStatus.getThreadRunning()) {
        strBld.append("not running");
      } else {
        log.debug("terminating task with id = " + taskStatus.getTaskId());
        if (seeder.terminateGWCTask(taskStatus.getTaskId())) {
          strBld.append("true");
        } else {
          strBld.append("false");
        }
      }
      strBld.append("</CancelResult>");
      strBld.append("</Task>");
    }

    strBld.append("</CancelResults>");
    resp.setEntity(strBld.toString(), MediaType.TEXT_XML);
  }