/** * 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; } } }
/** {@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); }
/** * @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); } }
/** 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(); } }
/** * @see RequestHandlerStack#replaceAll(IRequestHandler) * @param handler */ public void replaceAllRequestHandlers(final IRequestHandler handler) { requestHandlerExecutor.replaceAll(handler); }
/** * @see RequestHandlerStack#next() * @return the handler scheduled to be executed after current by the executor */ public IRequestHandler getRequestHandlerScheduledAfterCurrent() { return requestHandlerExecutor.next(); }
/** * @see RequestHandlerStack#getActive() * @return active handler on executor */ public IRequestHandler getActiveRequestHandler() { return requestHandlerExecutor.getActive(); }