Ejemplo n.º 1
0
  /**
   * Executes a request handler and fires pre/post listener methods
   *
   * @param handler
   */
  private void execute(IRequestHandler handler) {
    Args.notNull(handler, "handler");

    try {
      listeners.onRequestHandlerResolved(this, handler);
      requestHandlerExecutor.execute(handler);
      listeners.onRequestHandlerExecuted(this, handler);
    } catch (RuntimeException e) {
      IRequestHandler replacement = requestHandlerExecutor.resolveHandler(e);
      if (replacement != null) {
        execute(replacement);
      } else {
        throw e;
      }
    }
  }
Ejemplo n.º 2
0
  /** {@inheritDoc} */
  @Override
  public void scheduleRequestHandlerAfterCurrent(IRequestHandler handler) {
    // just delegating the call to {@link IRequestHandlerExecutor} and invoking listeners
    requestHandlerExecutor.schedule(handler);

    // only forward calls to the listeners when handler is null
    if (handler != null) listeners.onRequestHandlerScheduled(this, handler);
  }
Ejemplo n.º 3
0
  /**
   * @param handler
   * @param retryCount
   */
  private void executeExceptionRequestHandler(final IRequestHandler handler, final int retryCount) {
    scheduleRequestHandlerAfterCurrent(null);

    try {
      requestHandlerExecutor.execute(handler);
    } catch (Exception e) {
      if (retryCount > 0) {
        IRequestHandler next = handleException(e);
        if (next != null) {
          executeExceptionRequestHandler(next, retryCount - 1);
          return;
        }
      }
      log.error("Error during processing error message", e);
    }
  }
Ejemplo n.º 4
0
  /** Called after request processing is complete, usually takes care of detaching state */
  public void onDetach() {
    try {
      onEndRequest();
      listeners.onEndRequest(this);
    } catch (RuntimeException e) {
      log.error("Exception occurred during onEndRequest", e);
    }

    try {
      requestHandlerExecutor.detach();
    } finally {
      listeners.onDetach(this);
    }

    if (Session.exists()) {
      Session.get().detach();
    }
  }
Ejemplo n.º 5
0
 /**
  * @see RequestHandlerStack#replaceAll(IRequestHandler)
  * @param handler
  */
 public void replaceAllRequestHandlers(final IRequestHandler handler) {
   requestHandlerExecutor.replaceAll(handler);
 }
Ejemplo n.º 6
0
 /**
  * @see RequestHandlerStack#next()
  * @return the handler scheduled to be executed after current by the executor
  */
 public IRequestHandler getRequestHandlerScheduledAfterCurrent() {
   return requestHandlerExecutor.next();
 }
Ejemplo n.º 7
0
 /**
  * @see RequestHandlerStack#getActive()
  * @return active handler on executor
  */
 public IRequestHandler getActiveRequestHandler() {
   return requestHandlerExecutor.getActive();
 }