Esempio n. 1
0
  private void nextRunAge(long minAge, HttpServletResponse response) throws IOException {
    NameValuePair<Long> runAge = RunQ.getHandle().nextRunAge(minAge);

    if (runAge == null) {
      response.setStatus(HttpServletResponse.SC_NO_CONTENT);
      return;
    }

    StringBuilder output = new StringBuilder(128);
    output.append(runAge.name).append('\t').append(runAge.value);

    response.setContentType("txt/plain");
    response.setStatus(HttpServletResponse.SC_OK);
    OutputStream out = response.getOutputStream();
    out.write(output.toString().getBytes());
    out.flush();
    out.close();
  }
Esempio n. 2
0
  private void fetchNextRun(String runId, HttpServletResponse response)
      throws IOException, ClassNotFoundException {

    Run nextRun = null;
    for (; ; )
      try {
        nextRun = RunQ.getHandle().fetchNextRun(runId);
        break;
      } catch (RunEntryException e) {
      }

    if (nextRun == null) { // Queue empty
      logger.warning("Fetching run " + runId + ": No longer available!");
      response.setStatus(HttpServletResponse.SC_NO_CONTENT);
      return;
    }

    // Jar up the run.
    File jarFile = null;
    jarFile = jar(nextRun);

    // Send the run jar to the output stream
    long length = jarFile.length();
    int bufferSize = 1024 * 1024 * 128; // 128MB buffer limit
    if (length < bufferSize) bufferSize = (int) length;

    byte[] buffer = new byte[bufferSize];

    response.setStatus(HttpServletResponse.SC_OK);
    response.setContentType("application/java-archive");
    OutputStream out = response.getOutputStream();
    FileInputStream jarIn = new FileInputStream(jarFile);
    int readSize = 0;
    while ((readSize = jarIn.read(buffer)) != -1) out.write(buffer, 0, readSize);

    out.flush();
    out.close();

    // Update status locally
    nextRun.updateStatus(Run.RECEIVED);

    // Clear tmp file
    jarFile.delete();
  }