public IMessageResponse Execute() { if (Subject.Queue.Count == 0) { return(MessageResult.Empty); } var ctx = (MessageResult)Subject.Queue.Dequeue(); var handlers = Subject.Subscriber.Observers; if (handlers.Count == 0) { OnCompleted(ctx); } else { var e = new MessageEventArgs(ctx); ListnerManager.OnSending(e); if (e.Context.Response.Canceled) { ListnerManager.OnSent(e); OnCompleted(ctx); return(ctx); } Dispatch(ctx); } return(ctx); }
bool DoExecute(MessageResult ctx, IObserverHandler <IMessage> handler, AtomicInteger barrier) { var e = new MessageReceivingEventArgs(ctx, handler.Target); try { ListnerManager.OnReceiving(e); if (!e.Ignored) { ctx.results.Add(DelegateInvoker.Invoke <IMessage>(handler, ctx.Request.Sender, ctx.Request.ToMessage())); } return(true); } catch (Exception ex) { var re = new MessageExceptionEventArgs(ctx, ex); ListnerManager.OnReceivingException(re); ctx.InnerExceptions.Add(ex); return(!re.Canceled); } finally { barrier--; if (barrier == 0) { ListnerManager.OnReceived(new MessageEventArgs(ctx)); ListnerManager.OnSent(e); OnCompleted(ctx); } else { ListnerManager.OnReceived(new MessageEventArgs(ctx)); } e = null; } }