public void AddBroker(BrokerCircle bro)
 {
     if (!brokers.Exists(n => n.name == bro.name))
     {
         brokers.Add(bro);
     }
 }
Exemple #2
0
        public void UnsubscribeBroker(string processname, string topic)
        {
            new Task(() => {
                lock (Broker.monitorLock) {
                    while (Broker.frozen)
                    {
                        Monitor.Wait(Broker.monitorLock);
                    }
                }

                if (Broker.leader)
                {
                    foreach (IBroker broker in Broker.replicaBrokers)
                    {
                        try {
                            broker.UnsubscribeBroker(processname, topic);
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine("Error somewhere: " + e.Message);
                        }
                    }
                }

                BrokerCircle bro = Broker.neighbourBrokers.Find(n => n.name == processname);
                if (bro != null)
                {
                    lock (Broker.subscriptionMutex) {
                        //  Console.WriteLine( "BRO " + processname + " just unsubscribed from " + topic );
                        Broker.subscriptionCircles.RemoveTopicBroker(topic, processname);

                        //if ( Broker.parent != null ) {
                        bool a = !Broker.topicSubscribers.HasTopic(topic);
                        bool b = !Broker.subscriptionCircles.HasTopic(topic);
                        if (a && b)
                        {
                            Broker.EraseRelatedEvents(topic);
                            if (Broker.leader)
                            {
                                foreach (BrokerCircle broker in Broker.neighbourBrokers)
                                {
                                    if (broker.name != processname)
                                    {
                                        broker.UnsubscribeBroker(Broker.groupName, topic);
                                    }
                                }
                                //coiso.broker.SendContent( evt );
                            }
                        }
                        //}
                    }
                }
            }).Start();
        }
Exemple #3
0
        public void RegisterBrokers( List<string> addresses )
        {
            // Subscriber doesn't need to know the broker's name
            BrokerCircle brokerCircle = new BrokerCircle( "" );
            int id = 0;
            foreach ( string address in addresses ) {
                brokerCircle.AddBroker( (IBroker)Activator.GetObject( typeof( IBroker ), address ), id );
                id++;
            }

            Subscriber.brokerCircle = brokerCircle;
        }
 public void AddTopicBroker( string topic, BrokerCircle bro )
 {
     BrokerCircleTopicList entry = FindTopic( topic );
     if ( entry != null ) {
         entry.AddBroker( bro );
         return;
     }
     entry = new BrokerCircleTopicList();
     entry.topic = topic;
     entry.AddBroker( bro );
     table.Add( entry );
 }
Exemple #5
0
        public void RegisterBrokers(List <string> addresses)
        {
            // Subscriber doesn't need to know the broker's name
            BrokerCircle brokerCircle = new BrokerCircle("");
            int          id           = 0;

            foreach (string address in addresses)
            {
                brokerCircle.AddBroker((IBroker)Activator.GetObject(typeof(IBroker), address), id);
                id++;
            }

            Subscriber.brokerCircle = brokerCircle;
        }
Exemple #6
0
        // Puppet Master
        public void RegisterChildReplication(List <string> addresses, string name)
        {
            BrokerCircle brokerCircle = new BrokerCircle(name);
            int          id           = 0;

            foreach (string address in addresses)
            {
                brokerCircle.AddBroker((IBroker)Activator.GetObject(typeof(IBroker), address), id);
                id++;
            }

            // Add circle to a list of neighbour circles
            Broker.neighbourBrokers.Add(brokerCircle);
        }
        public void AddTopicBroker(string topic, BrokerCircle bro)
        {
            BrokerCircleTopicList entry = FindTopic(topic);

            if (entry != null)
            {
                entry.AddBroker(bro);
                return;
            }
            entry       = new BrokerCircleTopicList();
            entry.topic = topic;
            entry.AddBroker(bro);
            table.Add(entry);
        }
Exemple #8
0
        public void SubscribeBroker(string processname, string topic)
        {
            new Task(() => {
                lock (Broker.monitorLock) {
                    while (Broker.frozen)
                    {
                        Monitor.Wait(Broker.monitorLock);
                    }
                }

                if (Broker.leader)
                {
                    foreach (IBroker broker in Broker.replicaBrokers)
                    {
                        try {
                            broker.SubscribeBroker(processname, topic);
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine("Error somewhere: " + e.Message);
                        }
                    }
                }

                BrokerCircle bro = Broker.neighbourBrokers.Find(n => n.name == processname);
                if (bro != null)
                {
                    lock (Broker.subscriptionMutex) {
                        //Console.WriteLine( "BRO " + processname + " just subscribed to " + topic );
                        Broker.subscriptionCircles.AddTopicBroker(topic, bro);

                        if (Broker.leader)
                        {
                            foreach (BrokerCircle broker in Broker.neighbourBrokers)
                            {
                                if (broker.name != processname)
                                {
                                    broker.SubscribeBroker(Broker.groupName, topic);
                                }
                            }
                            //coiso.broker.SendContent( evt );
                        }
                    }
                }
            }).Start();
        }
Exemple #9
0
        // Puppet Master
        public void RegisterChildReplication( List<string> addresses, string name )
        {
            BrokerCircle brokerCircle = new BrokerCircle( name );
            int id = 0;
            foreach ( string address in addresses ) {
                brokerCircle.AddBroker( (IBroker)Activator.GetObject( typeof( IBroker ), address ), id );
                id++;
            }

            // Add circle to a list of neighbour circles
            Broker.neighbourBrokers.Add( brokerCircle );
        }
 public void AddBroker( BrokerCircle bro )
 {
     if ( !brokers.Exists( n => n.name == bro.name ) ) {
         brokers.Add( bro );
     }
 }