Пример #1
0
  /**
   * Request the given resource from this job frontend's class loader.
   *
   * @param theJobBackend Job Backend that is calling this method.
   * @param resourceName Resource name.
   * @exception IOException Thrown if an I/O error occurred.
   */
  public synchronized void requestResource(JobBackendRef theJobBackend, String resourceName)
      throws IOException {
    // To hold resource content.
    byte[] content = null;

    // Get resource content. If resource not found, content is null.
    if (myResourceCache.contains(resourceName)) {
      // Get resource content from cache.
      content = myResourceCache.getNoWait(resourceName);
    } else {
      // Get resource content from class loader, save it in cache.
      InputStream stream = getClass().getClassLoader().getResourceAsStream(resourceName);
      if (stream != null) {
        content = new ByteSequence(stream).toByteArray();
      }
      myResourceCache.put(resourceName, content);
    }

    // Send resource to job backend.
    theJobBackend.reportResource(this, resourceName, content);
  }