/// <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> /// 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); } } }
protected WorkFilter(WorkHandler handler, IConfigSectionNode confNode) : this(handler.NonNull(name : ".ctor(handler==null)").Dispatcher, confNode) { m_Handler = handler; this.__setComponentDirector(handler); }
protected WorkFilter(WorkHandler handler, string name, int order) : this(handler.NonNull(name : ".ctor(handler==null)").Dispatcher, name, order) { m_Handler = handler; this.__setComponentDirector(handler); }
private WorkHandler m_ParentHandler; internal void ___setParentHandler(WorkHandler parent) { m_ParentHandler = parent; }
protected WorkFilter(WorkHandler handler, IConfigSectionNode confNode) : base(handler) { ctor(handler.NonNull(name: ".ctor(handler==null)").Dispatcher, confNode); m_Handler = handler; }
protected WorkFilter(WorkHandler handler, string name, int order) : base(handler) { ctor(handler.NonNull(name: ".ctor(handler==null)").Dispatcher, name, order); m_Handler = 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); }