Ejemplo n.º 1
0
 public void SendContent( Event evt, string name )
 {
     lock ( circleLock ) {
         try {
             brokers[ testIndex ].SendContent( evt, name );
         }
         catch ( Exception e ) {
             Console.WriteLine( "Error sending event: " + e.Message );
             int indexOfDeath = testIndex;
             testIndex++;
             InformOfDeath( indexOfDeath );
             brokers[ testIndex ].MakeLeader();
             SendContent( evt, name );
         }
     }
     /*foreach ( IBroker broker in brokers ) {
     try {
     broker.SendContent( evt, name );
     }
     catch ( Exception e ) {
     // Something went wrong with this broker
     // Remove broker
     // Foreach is not the best way to do this
     }
     }*/
 }
Ejemplo n.º 2
0
 public void AddEvent( string publisherName, Event evt )
 {
     if ( !dictionary.ContainsKey( publisherName ) ) {
         dictionary.Add( publisherName, new PublisherTopicRegister() );
     }
     dictionary[ publisherName ].AddEvent( evt );
 }
Ejemplo n.º 3
0
 public void AddEvent( Event evt )
 {
     lock ( mutex ) {
         if ( !dictionary.ContainsKey( evt.PublisherName ) ) {
             dictionary.Add( evt.PublisherName, new EventListFlooding() );
         }
         dictionary[ evt.PublisherName ].AddEvent( evt );
     }
 }
Ejemplo n.º 4
0
 public void AddEvent( Event evt )
 {
     //lock ( mutex ) {
         // Se nao tem registo do topic, criar
         list.Add( evt );
         Console.WriteLine( "Adding " + evt.EventCounter + " from " + evt.PublisherName + " topic " + evt.Topic );
         // Ordenar lista por numero de evento de topico
         list.Sort( ( t1, t2 ) => (t1.EventCounter - t2.EventCounter) );
     //}
 }
Ejemplo n.º 5
0
        public void ReceiveContent(Event evt)
        {
            lock (Subscriber.monitorLock)
            {
                while (Subscriber.frozen)
                {
                    Monitor.Wait(Subscriber.monitorLock);
                }
            }

            if (Subscriber.topics.Contains(evt.Topic) || Subscriber.IsSubTopic( evt.Topic )){
                new Task(() => { Subscriber.puppetMaster.Log("SubEvent " + Subscriber.name + ", " + evt.PublisherName + ", " + evt.Topic + ", " + evt.TopicEventNum); }).Start();
                System.Console.WriteLine("Topic: " + evt.Topic + " Content: " + evt.Content + " " + evt.EventCounter);
                // Subscriber.puppetMaster.Log("SubEvent " + Subscriber.name + " thing.");
            }
        }
Ejemplo n.º 6
0
        public static void SendContent(Event evt, String name)
        {
            //Console.WriteLine( lastSender + "  ->  " + Broker.groupName );

            if (Broker.routing == FileParsing.RoutingPolicy.Filter)
            {
                SendContentFiltering(evt, name);
            }

            else
            {
                string lastSender = evt.LastSenderName;
                evt.LastSenderName = Broker.groupName;

                // Flooding
                //Console.WriteLine( "Sending " + evt.EventCounter );
                foreach (NamedSubscriber subscriber in Broker.subscribers)
                {
                    Console.WriteLine( "Sending evt to sub: Topic: " + evt.Topic + " Pub: " + evt.PublisherName + " No: " + evt.TopicEventNum + " Last Sender: " + lastSender );
                    subscriber.subcriber.ReceiveContent(evt);
                }

                // No replication
                /*foreach ( NamedBroker broker in Broker.children)
                {
                    if ( broker.name != lastSender )
                    {
                        new Task(() => { broker.broker.SendContent(evt, Broker.name); }).Start();
                    }
                }*/

                // Replication
                foreach ( BrokerCircle broker in Broker.neighbourBrokers ) {
                    Console.WriteLine( "Sending evt to bro: Topic: " + evt.Topic + " Pub: " + evt.PublisherName + " No: " + evt.TopicEventNum + " Last Sender: " + lastSender  + " Bro: " + broker.name );
                    if ( broker.name != lastSender ) {
                        new Task( () => { broker.SendContent( evt, Broker.groupName ); } ).Start();
                    }
                }
            }
        }
Ejemplo n.º 7
0
        public void SendContentPub(Event evt, String name)
        {
            if (Broker.ordering == FileParsing.Ordering.Total)
            {
                evt.EventCounter = Broker.sequencer.GetNextSequenceNumber();
                //Console.WriteLine( "Sending event- " + "Seq: " + evt.EventCounter + " Topic: " + evt.TopicEventNum + " Pub: " + evt.PublisherName );
            }

            SendContent(evt, name);
        }
Ejemplo n.º 8
0
        //Broker
        public void SendContent(Event evt, String name)
        {
            //new Task(() =>
            //{
                lock (Broker.monitorLock)
                {
                    while (Broker.frozen)
                    {
                        Monitor.Wait(Broker.monitorLock);
                    }
                }

                if (Broker.leader)
                {
                    foreach(var broker in Broker.replicaBrokers)
                    {
                        try {
                            broker.SendContent(evt, name);
                        }
                            catch (Exception e)
                        {
                            Console.WriteLine("Error somewhere: " + e.Message);
                        }
                    }
                }

                if (Broker.ordering == FileParsing.Ordering.Fifo)
                {
                    lock (Broker.subscriptionMutex)
                    {
                        if (Broker.routing == FileParsing.RoutingPolicy.Filter)
                        {
                            // FILTERING: TOPIC EVENT COUNTER
                            Broker.publisherTopics.AddEvent(evt.PublisherName, evt);

                            PublisherTopicRegister pRegister = Broker.publisherTopics.GetPublisherTopic(evt.PublisherName);

                            foreach (Event orderedEvent in pRegister.GetLastOrderedEvents(evt.Topic))
                            {
                                //Console.WriteLine( "Send" );
                                if (Broker.leader)
                                {
                                    Broker.SendContent(orderedEvent, name);

                                    if (Broker.logging == FileParsing.LoggingLevel.Full)
                                    {
                                        new Task(() => { Broker.puppetMaster.Log("BroEvent " + Broker.name + " " + orderedEvent.PublisherName + " " + orderedEvent.Topic + " " + orderedEvent.TopicEventNum); }).Start();
                                    }
                                }
                            }
                        }
                        else
                        {
                            // FLOODING: EVENT COUNTER
                            Broker.publisherEvents.AddEvent(evt);

                            EventListFlooding eList = Broker.publisherEvents.GetEventList(evt.PublisherName);
                            //lock ( eList.mutex ) {
                            foreach (Event orderedEvent in eList.GetOrderedEventsUpToDate())
                            {
                                if (Broker.leader)
                                {
                                    Broker.SendContent(orderedEvent, name);

                                    // Console.WriteLine( "orderedEvent.EventCounter: " + orderedEvent.EventCounter );
                                    if (Broker.logging == FileParsing.LoggingLevel.Full)
                                    {
                                        new Task(() => { Broker.puppetMaster.Log("BroEvent " + Broker.name + ", " + orderedEvent.PublisherName + ", " + orderedEvent.Topic + ", " + orderedEvent.TopicEventNum); }).Start();
                                    }
                                }
                            }
                        }

                    }
                }
                else if(Broker.ordering == FileParsing.Ordering.Total)
                {
                    lock (Broker.subscriptionMutex)
                    {
                        if (Broker.routing == FileParsing.RoutingPolicy.Filter)
                        {
                        }
                        //flooding
                        else
                        {
                            //lock ( Broker.totalOrderEvents.mutex ) {
                                Broker.totalOrderEvents.AddEvent( evt );
                                foreach ( Event orderedEvent in Broker.totalOrderEvents.GetOrderedEventsUpToDate() ) {
                                if (Broker.leader)
                                {
                                    Broker.SendContent(orderedEvent, name);

                                    // Console.WriteLine( "orderedEvent.EventCounter: " + orderedEvent.EventCounter );
                                    if (Broker.logging == FileParsing.LoggingLevel.Full)
                                    {
                                        new Task(() => { Broker.puppetMaster.Log("BroEvent " + Broker.name + ", " + orderedEvent.PublisherName + ", " + orderedEvent.Topic + ", " + orderedEvent.TopicEventNum); }).Start();
                                    }

                                }
                                }
                            //}
                        }
                    }
                }
                else
                {
                    if (Broker.leader)
                    {
                        Broker.SendContent(evt, name);
                        if (Broker.logging == FileParsing.LoggingLevel.Full)
                        {
                            new Task(() => { Broker.puppetMaster.Log("BroEvent " + Broker.name + ", " + evt.PublisherName + ", " + evt.Topic + ", " + evt.TopicEventNum); }).Start();
                        }
                    }
                }
               // }).Start();
        }
Ejemplo n.º 9
0
        public static void SendContentFiltering( Event evt, String name )
        {
            string lastSender = evt.LastSenderName;
            evt.LastSenderName = Broker.groupName;

            var subs = topicSubscribers.FindAllSubscribers( evt.Topic );
            foreach ( NamedSubscriber sub in subs ) {
                try {
                    sub.subcriber.ReceiveContent( evt );
                }
                catch ( Exception e ) {
                    Console.WriteLine( "Exception to susbcriber: " + e.Message );
                }
            }

            // No replication
            /*var bros = topicBrokers.FindAllBrokers( evt.Topic );
            foreach ( NamedBroker bro in bros ) {
                //bro.broker.SendContent( evt );
                new Task( () => { bro.broker.SendContent( evt, Broker.name ); } ).Start();
            }*/

            // Replication
            var bros = subscriptionCircles.FindAllBrokers( evt.Topic );
            foreach ( BrokerCircle bro in bros ) {
                if ( bro.name != lastSender ) {
                    new Task( () => { bro.SendContent( evt, Broker.groupName ); } ).Start();
                }
            }
        }
Ejemplo n.º 10
0
        public void AddEvent( Event evt )
        {
            //lock ( mutex ) {
                // Se nao tem registo do topic, criar
                if ( !topics.ContainsKey( evt.Topic ) ) {
                    topics.Add( evt.Topic, new OrderedTopicEvent( evt.TopicEventNum ) );
                }
                if ( evt.TopicEventNum < topics[ evt.Topic ].lastEvent ) {
                    // Discard
                    return;
                }
                topics[ evt.Topic ].list.Add( evt );

                // Ordenar lista por numero de evento de topico
                topics[ evt.Topic ].list.Sort( ( t1, t2 ) => (t1.TopicEventNum - t2.TopicEventNum) );
            //}
        }