Пример #1
0
        public void forwardFilter(Message m, string brokerName)
        {
            Console.WriteLine("ForwardFilter received from broker -> {0}", brokerName);

            foreach (KeyValuePair<string, List<string>> t in lstSubsTopic)
            {
                foreach (var sub in t.Value)//percorrer lista de subs
                {
                    if (m.Topic.Equals(sub))
                    {
                        Console.WriteLine("Eu notifiquie o sub interessado");
                        SubscriberNotify not = (SubscriberNotify)Activator.GetObject(typeof(SubscriberNotify), t.Key + "/Notify");
                        not.notify(m);
                    }
                }
            }

            Dictionary<Broker, List<string>> lst = new Dictionary<Broker, List<string>>(routingTable);
            //eliminar remetente da routing table
            foreach (KeyValuePair<Broker, List<string>> par in routingTable)
            {
                if (par.Key.Name.Equals(brokerName))
                {
                    lst.Remove(par.Key);
                }
            }

            foreach (KeyValuePair<Broker, List<string>> t in routingTable)
            {
                if (t.Value.Contains(m.Topic))
                { //ha alguem na routing table que quer este topico
                    string urlRemote = t.Key.URL.Substring(0, t.Key.URL.Length - 11);//retirar XXXX/broker
                    int port = 9000;

                    int mult = Int32.Parse("" + t.Key.Site[t.Key.Site.Length - 1]);
                    urlRemote += (port + (mult * 100) + 1).ToString() + "/";

                    //Console.WriteLine("Filtering vizinho em {0}", urlRemote);
                    BrokerReceiveBroker bro = (BrokerReceiveBroker)Activator.GetObject(typeof(BrokerReceiveBroker), urlRemote + "BrokerCommunication");
                    try
                    {
                        FilterFloodRemoteAsyncDelegate RemoteDel = new FilterFloodRemoteAsyncDelegate(bro.forwardFilter);
                        AsyncCallback RemoteCallBack = new AsyncCallback(FilterFloodRemoteAsyncCallBack);
                        IAsyncResult RemAr = RemoteDel.BeginInvoke(m, name, RemoteCallBack, null);

                        LogInterface log = (LogInterface)Activator.GetObject(typeof(LogInterface), "tcp://localhost:8086/PuppetMasterLog");
                        log.log(this.name, m.author, m.Topic, 0, "broker");

                    }
                    catch (SocketException)
                    {
                        Console.WriteLine("Could not locate server");
                    }
                }
            }
        }
Пример #2
0
        public void forwardFlood(Message m, string brokerName)
        {
            //Console.WriteLine("Inicio num novo broker vindo de ->> {0}", brokerName);

            foreach (KeyValuePair<string, List<string>> t in lstSubsTopic)
            {
                foreach (var sub in t.Value)//percorrer lista de subs
                {
                    if (m.Topic.Equals(sub))
                    {
                        SubscriberNotify not = (SubscriberNotify)Activator.GetObject(typeof(SubscriberNotify), t.Key + "/Notify");
                        not.notify(m);
                    }
                }
            }

            List<Broker> lst = new List<Broker>(lstVizinhos);
            //eliminar remetente da lista
            for (int i = 0; i < lst.Count; i++)
            {
                if (lst[i].Name.Equals(brokerName))
                {
                    //Console.WriteLine("Removi o {0} da lista de vizinhos", lst[i].Name);
                    lst.Remove(lst[i]);
                }
            }

            //propagar para os outros todos
            foreach (var viz in lst)
            {
                string urlRemote = viz.URL.Substring(0, viz.URL.Length - 11);//retirar XXXX/broker
                int port = 9000;

                int mult = Int32.Parse("" + viz.Site[viz.Site.Length - 1]);
                urlRemote += (port + (mult * 100) + 1).ToString() + "/";

                //Console.WriteLine("Flooding vizinho em {0}", urlRemote);
                BrokerReceiveBroker bro = (BrokerReceiveBroker)Activator.GetObject(typeof(BrokerReceiveBroker), urlRemote + "BrokerCommunication");
                try
                {
                    FilterFloodRemoteAsyncDelegate RemoteDel = new FilterFloodRemoteAsyncDelegate(bro.forwardFlood);
                    AsyncCallback RemoteCallBack = new AsyncCallback(FilterFloodRemoteAsyncCallBack);
                    IAsyncResult RemAr = RemoteDel.BeginInvoke(m, name, RemoteCallBack, null);

                    LogInterface log = (LogInterface)Activator.GetObject(typeof(LogInterface), "tcp://localhost:8086/PuppetMasterLog");
                    log.log(this.name, m.author, m.Topic, 0,"broker");

                }
                catch (SocketException)
                {
                    Console.WriteLine("Could not locate server");
                }
            }
        }
Пример #3
0
        public void forwardFlood(Message m, string brokerName, int eventNumber, int order, int logMode)
        {
            if (!isLeader)//se não és lider
            {
                //TODO - adicionar à lista de msg , retirar msg se já foi enviada e recebida.
                return;
            }
            string pubTopic = m.author + "%" + m.Topic;
            if (order == 1)//FIFO
            {

                lock (myLock)
                {
                    if (!seqPub.ContainsKey(m.author))
                    {//publisher nao publicou nada
                        seqPub.Add(m.author, 1);//actualizar numSeq deste pub
                    }

                    if (!pubCount.ContainsKey(pubTopic))//publisher nao publicou nada neste topico
                    {
                        pubCount.Add(pubTopic, 1);
                    }

                    if (m.SeqNum == seqPub[m.author])//msg esperada para aquele publisher
                    {
                        foreach (KeyValuePair<string, List<string>> t in lstSubsTopic)
                        {
                            if (searchTopicList(m.Topic, t.Value))//ha match de topicos
                            {

                                Console.WriteLine("Eu notifiquie o sub interesado, numeroSeq da msg ---> {0}", m.SeqNum);
                                SubscriberNotify not = (SubscriberNotify)Activator.GetObject(typeof(SubscriberNotify), t.Key + "/Notify");
                                not.notify(m, eventNumber);
                            }
                        }
                        //ja notifiquei quem tinha a notificar com esta publicacao
                        seqPub[m.author]++;
                        pubCount[pubTopic]++;
                    }
                    else
                    { //nao e a msg esperada

                        Console.WriteLine("{0} - Esperado {1} ----- {2} Recebido", pubTopic, seqPub[m.author], m.SeqNum);
                        lstMessage.Add(m);
                        lstMessage = SortList(lstMessage);
                    }

                    //iterar sobre lista de espera para ver se posso mandar alguma coisa
                    for (int j = 0; j < lstMessage.Count; )
                    {
                        int next = seqPub[m.author];// e o proximo numSeq que estou a espera para aquele autor

                        Console.WriteLine("Estou a iterar a procura do {0} para <{1}>", next, pubTopic);
                        foreach (Message mi in lstMessage) Console.Write("a: " + mi.author + ",n: " + mi.SeqNum + "#");
                        Console.WriteLine("");
                        if (lstMessage[j].author.Equals(m.author) && lstMessage[j].SeqNum == next)
                        {//msg na lista de espera e do mesmo autor, e tambem e a que estava a espera
                            foreach (KeyValuePair<string, List<string>> t in lstSubsTopic)
                            {
                                if (searchTopicList(lstMessage[j].Topic, t.Value))//ha match de topicos para um sub meu
                                {
                                    Console.WriteLine("Durante a iteracao Eu notifiquie o sub interesado, numeroSeq da msg ---> {0}", lstMessage[j].SeqNum);
                                    SubscriberNotify not = (SubscriberNotify)Activator.GetObject(typeof(SubscriberNotify), t.Key + "/Notify");
                                    not.notify(lstMessage[j], eventNumber);
                                }
                            }
                            Console.Write("antes de descartar mensagem : " + lstMessage[j].SeqNum + " #");
                            lstMessage.Remove(lstMessage[j]);

                            j = 0; // voltar ao início da lista
                            seqPub[m.author]++;
                            pubCount[pubTopic]++;
                            Console.WriteLine("seq actual: " + seqPub[m.author]);
                        }
                        else
                        {
                            j++; //continuar a iterar }
                        }
                    }
                }
            }
            else {
                foreach (KeyValuePair<string, List<string>> t in lstSubsTopic)
                {
                    if (searchTopicList(m.Topic, t.Value))//ha match de topicos
                    {
                        Console.WriteLine("Eu notifiquie o sub interesado, numeroSeq da msg ---> {0}", m.SeqNum);
                        SubscriberNotify not = (SubscriberNotify)Activator.GetObject(typeof(SubscriberNotify), t.Key + "/Notify");
                        not.notify(m, eventNumber);
                    }
                }
                //ja notifiquei quem tinha a notificar com esta publicacao
                //seqPub[m.author]++;
                //pubCount[pubTopic]++;
            }

            //PROPAGATION TIME

            List<Broker> lst = new List<Broker>(lstVizinhos);
            //eliminar remetente da lista
            for (int i = 0; i < lst.Count; i++)
            {
                if (lst[i].Name.Equals(brokerName))
                {
                    //Console.WriteLine("Removi o {0} da lista de vizinhos", lst[i].Name);
                    lst.Remove(lst[i]);
                }
            }

            //propagar para os outros todos

            foreach (var viz in lst)
            {
                string urlRemote = viz.URL.Substring(0, viz.URL.Length - 6);//retirar XXXX/broker

                Console.WriteLine("Flooding MSG <<<<{0}>>>>  #seq {1} para o vizinho em {2}", pubTopic, m.SeqNum, urlRemote);
                BrokerReceiveBroker bro = (BrokerReceiveBroker)Activator.GetObject(typeof(BrokerReceiveBroker), urlRemote + "BrokerCommunication");
                try
                {
                    if (logMode == 1)
                    {
                        LogInterface log = (LogInterface)Activator.GetObject(typeof(LogInterface), "tcp://localhost:8086/PuppetMasterLog");
                        log.log(this.name, m.author, m.Topic, eventNumber, "broker");
                    }
                    FilterFloodRemoteAsyncDelegate RemoteDel = new FilterFloodRemoteAsyncDelegate(bro.forwardFlood);
                    AsyncCallback RemoteCallBack = new AsyncCallback(FilterFloodRemoteAsyncCallBack);
                    IAsyncResult RemAr = RemoteDel.BeginInvoke(m, name, eventNumber, order, logMode, RemoteCallBack, null);
                }
                catch (SocketException)
                {
                    Console.WriteLine("Could not locate server");
                }
            }
        }