Exemplo n.º 1
0
  /* (non-Javadoc)
   * @see java.lang.Runnable#run()
   */
  public void run() {

    //		log.debug("running");

    setRunning(true);

    while (true) {

      ResourceRequest request = null;
      boolean reserved = false;

      if (queue.isEmpty()) {
        setRunning(false);
        //				log.debug("finished");
        return;
      }

      request = (ResourceRequest) queue.firstElement();

      reserved = manager.requestResources(request);
      if (reserved) {
        queue.remove(request);
        notifyResourceWaiter(request);
        log.info("grantResources: " + request.getRrId());
      } else {
        waitForResources();
      }
    }
  }
Exemplo n.º 2
0
  /** @param request */
  private void notifyResourceWaiter(ResourceRequest request) {

    ResourceWaiter waiter = null;

    waiter = request.getResourceWaiter();
    if (waiter != null) {
      waiter.grantResource(request.getRrId());
    } else {
      // no resourcewaiter - free resources - log error
      log.error(
          "No reference to ResourceWaiter for rrId:"
              + request.getRrId()
              + " - releasing resources.");
      try {
        manager.releaseResources(request.getRrId());
      } catch (ResourceManagerException e) {
        log.error("Problem freeing resources - I give up", e);
      }
      return;
    }
  }