Esempio n. 1
0
  /** {@inheritDoc} */
  @Override
  public void run() {

    while (requests != null) {

      /* Not processing a request. */
      currentRequest = null;

      /* Take a new request from the queue, waiting for one if none is available yet. */
      try {
        currentRequest = requests.take();
      }

      /* Interrupted? Well, try again! */
      catch (InterruptedException ignored) {
        continue;
      }

      /* Process the request. */
      try {
        ui.process(currentRequest.getRequest());
      }

      /* Uncaught exception occurred during the request. */
      catch (Throwable e) {
        e.initCause(currentRequest.getCause());
        logger.err(e, "Unexpected error occurred.");
      }
    }
  }
Esempio n. 2
0
  /**
   * Add a request to the stack of requests to execute in the update thread.
   *
   * @param uiRequest The request to execute in the update thread.
   */
  public void request(Request uiRequest) {

    UpdateRequest newRequest =
        new UpdateRequest(
            uiRequest,
            new RuntimeException(
                Locale.explain("err.originates")
                    + Thread.currentThread().getName())); // $NON-NLS-1$

    /* Don't process a request if the next pending or currently executing request is the same. */
    if (newRequest.equals(currentRequest) || requests.contains(newRequest)) return;

    /* Add this request to the request list. */
    synchronized (requests) {
      try {
        if (!requests.offer(newRequest, 500, TimeUnit.MILLISECONDS))
          throw new InterruptedException("Maximum wait time elapsed.");
      } catch (InterruptedException e) {
        logger.err(e, "err.updateQueueFull", newRequest);
      }
    }
  }