public void Receive(Event e) { this.BlockWhileFrozen(); lock (this) { if (ordering.Equals("TOTAL")) { if (!repeated.IsRepeated(e.SequenceNumber, e.Publisher)) { freezer.Add(e); } } else { if (!repeated.IsRepeated(e.SequenceNumber, e.Publisher)) { Console.WriteLine("Publisher: {0} Topic: {1} SN: {2}", e.Publisher, e.Topic, e.GetSequenceNumber()); logServer.LogAction("SubEvent " + name + " " + e.Publisher + " " + e.Topic + " " + e.SequenceNumber); } } } }
// Private methods private void ProcessPublish(Object o) { this.BlockWhileFrozen(); int sn; PublishDTO dto = o as PublishDTO; for (int i = 0; i < dto.NumEvents; i++) { lock (this) { sn = sequenceNumber++; logServer.LogAction("PubEvent " + name + ", " + name + ", " + dto.Topic + ", " + sn); brokerSite.Diffuse(new Event(this.name, this.siteName, dto.Topic, "content", sn)); } Thread.Sleep(dto.Interval); } }
// Private methods private void Diffuse(Object o) { this.BlockWhileFrozen(); Event e = o as Event; order.Deliver(e.Publisher, e.SequenceNumber); // Send the event to interested Brokers if (loggingLevel.Equals("full")) { logServer.LogAction("BroEvent " + brokerName + " " + e.Publisher + " " + e.Topic + " " + e.SequenceNumber); } Event newEvent = this.router.Diffuse(e); // Send the event to Subscribers who want it ICollection <NodePair <ISubscriber> > subscribersToSend = Data.SubscribersFor(e.Topic); foreach (var subscriberPair in subscribersToSend) { subscriberPair.Node.Receive(newEvent); } order.ConfirmDeliver(e); }