/// <summary> /// Invokes next processing body be it the next filter or handler (when all filters are iterated through). /// The filter implementors must call this method to pass WorkContext processing along the line. /// Does nothing if work is Aborted or Handled /// </summary> protected void InvokeNextWorker(WorkContext work, IList <WorkFilter> filters, int thisFilterIndex) { if (work == null) { return; } if (work.Aborted || work.Handled) { return; } var idxNext = thisFilterIndex + 1; if (idxNext < filters.Count) { filters[idxNext].FilterWork(work, filters, idxNext); } else { WorkHandler handler = m_Handler; if (handler != null)//if we are under Handler already then call the handler directly { handler.HandleWork(work); } else //if we are under dispatcher then call dipatcher to locate and invoke the matching handler { m_Dispatcher.InvokeHandler(work, out handler); } } }
/// <summary> /// Unregisters handler and returns true if the named instance has been removed /// Note: it is possible to call this method on active server that is - remove handlers while serving requests /// </summary> public bool UnRegisterHandler(WorkHandler handler) { if (handler == null) { return(false); } if (handler.Dispatcher != this) { throw new WaveException(StringConsts.WRONG_DISPATCHER_HANDLER_UNREGISTRATION_ERROR.Args(handler)); } return(m_Handlers.Unregister(handler)); }
/// <summary> /// Finds appropriate handler and invokes it. Returns the appropriate handler or null if work was aborted or already handled. /// Throws if appropriate handler was not found /// </summary> public virtual void InvokeHandler(WorkContext work, out WorkHandler handler) { if (!work.Aborted && !work.Handled) { handler = GetWorkHandler(work); if (handler == null) { throw HTTPStatusException.NotFound_404(StringConsts.NO_HANDLER_FOR_WORK_ERROR.Args(work.About)); } handler.FilterAndHandleWork(work); return; } handler = null; }
/// <summary> /// Handles processing exception by calling ErrorFilter.HandleException(work, error). /// All parameters except ERROR can be null - which indicates error that happened during WorkContext dispose /// </summary> public virtual void HandleException(WorkContext work, WorkFilter filter, WorkHandler handler, Exception error) { try { if (m_InstrumentationEnabled) { Interlocked.Increment(ref m_stat_ServerHandleException); } //work may be null (when WorkContext is already disposed) if (work != null) { ErrorFilter.HandleException(work, error, m_ErrorShowDumpMatches, m_ErrorLogMatches); } else { Log(MessageType.Error, StringConsts.SERVER_DEFAULT_ERROR_WC_NULL_ERROR + error.ToMessageWithType(), "HandleException()", error); } } catch (Exception error2) { if (m_LogHandleExceptionErrors) { try { Log(MessageType.Error, StringConsts.SERVER_DEFAULT_ERROR_HANDLER_ERROR + error2.ToMessageWithType(), "HandleException.catch()", error2, pars: new { OriginalError = error.ToMessageWithType() }.ToJSON() ); } catch {} } } }
/// <summary> /// Dispatches work into appropriate handler passing through filters. /// The default implementation processes requests on the calling thread and disposes WorkContext deterministically /// </summary> public virtual void Dispatch(WorkContext work) { WorkFilter filter = null; WorkHandler handler = null; try { var filters = m_Filters.OrderedValues.ToList().AsReadOnly();//captures context filter = filters.FirstOrDefault(); if (filter != null) { filter.FilterWork(work, filters, 0); } else { InvokeHandler(work, out handler); } } catch (Exception error) { work.LastError = error; HandleException(work, filter, handler, error); } finally { try { if (!work.NoDefaultAutoClose) { work.Dispose(); } } catch (Exception error) { HandleException(null, null, null, error); } } }
private WorkHandler m_ParentHandler; internal void ___setParentHandler(WorkHandler parent) { m_ParentHandler = parent;}
/// <summary> /// Handles processing exception by calling ErrorFilter.HandleException(work, error). /// All parameters except ERROR can be null - which indicates error that happened during WorkContext dispose /// </summary> public virtual void HandleException(WorkContext work, WorkFilter filter, WorkHandler handler, Exception error) { try { if (m_InstrumentationEnabled) Interlocked.Increment(ref m_Stat_ServerHandleException); //work may be null (when WorkContext is already disposed) if (work!=null) ErrorFilter.HandleException(work, error, m_ErrorShowDumpMatches, m_ErrorLogMatches); else Log(MessageType.Error, StringConsts.SERVER_DEFAULT_ERROR_WC_NULL_ERROR + error.ToMessageWithType(), "HandleException()", error); } catch(Exception error2) { if (m_LogHandleExceptionErrors) try { Log(MessageType.Error, StringConsts.SERVER_DEFAULT_ERROR_HANDLER_ERROR + error2.ToMessageWithType(), "HandleException.catch()", error2, pars: new { OriginalError = error.ToMessageWithType() }.ToJSON() ); } catch{} } }
private WorkHandler m_ParentHandler; internal void ___setParentHandler(WorkHandler parent) { m_ParentHandler = parent; }
public CustomFilter(WorkHandler handler, IConfigSectionNode confNode) : base(handler, confNode) { configureMatches(confNode); }
public CustomFilter(WorkHandler handler, string name, int order) : base(handler, name, order) { }
protected WorkFilter(WorkHandler handler, IConfigSectionNode confNode) : this(handler.NonNull(text: ".ctor(handler==null)").Dispatcher, confNode) { m_Handler = handler; this.__setComponentDirector(handler); }
protected WorkFilter(WorkHandler handler, string name, int order) : this(handler.NonNull(text: ".ctor(handler==null)").Dispatcher, name, order) { m_Handler = handler; this.__setComponentDirector(handler); }
/// <summary> /// Handles processing exception - this implementation uses server-wide behavior. /// All parameters except ERROR can be null - which indicates error that happened during WorkContext dispose /// </summary> public virtual void HandleException(WorkContext work, WorkFilter filter, WorkHandler handler, Exception error) { ComponentDirector.HandleException(work, filter, handler, error); }
protected WorkFilter(WorkHandler handler, IConfigSectionNode confNode) : this(handler.NonNull(text : ".ctor(handler==null)").Dispatcher, confNode) { m_Handler = handler; this.__setComponentDirector(handler); }
protected WorkFilter(WorkHandler handler, string name, int order) : this(handler.NonNull(text : ".ctor(handler==null)").Dispatcher, name, order) { m_Handler = handler; this.__setComponentDirector(handler); }