Exemplo n.º 1
0
        private void flooding(int en, PublishMessage receivedMessage, PublishMessage sendingMessage)
        {
            lock (_childSites)
            {
                foreach (var site in _childSites)
                {

                    lock (site)
                    {
                        if (site.name != receivedMessage.originSite)
                        {
                            foreach (var broker in site.brokers)
                            {
                                PublishDelegate d = new PublishDelegate(broker.publish);
                                d.BeginInvoke(sendingMessage, null, null);
                                log(en, string.Format("[Flooding] to child site {0}", site.name));
                                if (_loggingLevel == LoggingLevel.full)
                                    c.reportEvent(EventType.BroEvent, getURI(), receivedMessage.publisherURI, receivedMessage.topic, receivedMessage.seqnum);
                            }
                        }
                    }
                }
            }

            lock (_parentSiteLock)
            {
                if (_parentSite != null && _parentSite.name != receivedMessage.originSite)
                {
                    foreach (Broker broker in _parentSite.brokers)
                    {
                        PublishDelegate d = new PublishDelegate(broker.publish);
                        log(en, string.Format("[Flooding] to parent site {0}", _parentSite.name));
                        d.BeginInvoke(sendingMessage, null, null);
                        if (_loggingLevel == LoggingLevel.full)
                            c.reportEvent(EventType.BroEvent, getURI(), sendingMessage.publisherURI, sendingMessage.topic, receivedMessage.seqnum);
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void filter(int en, PublishMessage receivedMessage, PublishMessage sendingMessage)
        {
            log(en, "[Filter] Routing");
            var sentSites = new List<string>();
            lock (_topicSites)
            {
                foreach (var subscribedTopic in _topicSites.Keys)
                {
                    if (!equivalentTopic(receivedMessage.topic, subscribedTopic))
                        continue;
                    foreach (var site_name in _topicSites[subscribedTopic])
                    {
                        if (site_name == receivedMessage.originSite)
                            continue;
                        if (sentSites.Contains(site_name))
                        {
                            continue;
                        }
                        sentSites.Add(site_name);

                        var site = _nameToSite[site_name];
                        if (_orderingPolicy == OrderingPolicy.fifo)
                        {
                            //translate seq_num of the message to send to child_sites
                            lock (_siteToFifoStruct)
                            {
                                if (!_siteToFifoStruct.ContainsKey(site_name))
                                {
                                    _siteToFifoStruct.Add(site_name, new List<FIFOstruct>());
                                }
                                int index = _siteToFifoStruct[site_name].FindIndex(item => item._publhisherURI == sendingMessage.publisherURI);
                                if (index < 0)
                                {
                                    // element does not exists
                                    _siteToFifoStruct[site_name].Add(new FIFOstruct(receivedMessage.publisherURI, 0));
                                    //getIndex Now
                                    index = _siteToFifoStruct[site_name].FindIndex(item => item._publhisherURI == sendingMessage.publisherURI);
                                }
                                var fifo = _siteToFifoStruct[site_name][index];
                                sendingMessage.seqnum = fifo._seq_num;
                                log(en, string.Format("[Filter][FIFO] For site {2}, mapping seqnum from {0} to {1}",
                                    receivedMessage.seqnum, sendingMessage.seqnum, site_name));
                                fifo._seq_num++;
                            }
                        }

                        lock (site)
                        {
                            foreach (var broker in site.brokers)
                            {
                                PublishDelegate d = new PublishDelegate(broker.publish);
                                if (_orderingPolicy == OrderingPolicy.total)
                                {
                                    log(en, "Routing: received " + receivedMessage);
                                    log(en, "Routing sending " + sendingMessage);
                                    d.BeginInvoke(sendingMessage, null, null);
                                    log(en, string.Format("[Filter][TOTAL] routed to site {0}", site.name));
                                }
                                else if (_orderingPolicy == OrderingPolicy.fifo)
                                {
                                    d.BeginInvoke(sendingMessage, null, null);
                                    log(en, string.Format("[Filter][FIFO] routed to site {0}", site.name));
                                }
                                else
                                {
                                    d.BeginInvoke(sendingMessage, null, null);
                                    log(en, string.Format("[FILTER][NO ORDER] routed to {0}", site.name));
                                }
                                if (_loggingLevel == LoggingLevel.full)
                                    c.reportEvent(EventType.BroEvent, getURI(), sendingMessage.publisherURI, sendingMessage.topic, receivedMessage.seqnum);
                            }
                        }

                    }
                }
            }
        }
Exemplo n.º 3
0
        public void readExe_scriptFile(string path)
        {
            string[] lines = System.IO.File.ReadAllLines(path);
            LogInterface log = (LogInterface)Activator.GetObject(typeof(LogInterface), "tcp://localhost:8086/PuppetMasterLog");
            foreach (string s in lines)
            {
                if (s.StartsWith("Publisher"))
                {
                    log.scriptLog(s);

                    string[] words = s.Split(' ');
                    //Publisher processname Publish numberofevents Ontopic topicname Interval x ms.
                    PubInterface pub = (PubInterface)Activator.GetObject(typeof(PubInterface), "tcp://localhost:" + pname_port[words[1]] + "/PMPublish");

                    PublishDelegate RemoteDel = new PublishDelegate(pub.publish);
                    AsyncCallback RemoteCallBack = new AsyncCallback(PublishCallBack);
                    IAsyncResult RemAr = RemoteDel.BeginInvoke(words[3], words[5], words[7], routing,order,eventNumber,logMode, RemoteCallBack, null);

                    eventNumber = eventNumber + Int32.Parse(words[3]);
                }

                if (s.StartsWith("Subscriber"))
                {

                    log.scriptLog(s);

                    string[] words = s.Split(' ');
                    SubInterface subint = (SubInterface)Activator.GetObject(typeof(SubInterface), "tcp://localhost:" + pname_port[words[1]] + "/MPMSubUnsub");

                    if (s.Contains("Unsubscribe"))
                    {
                        subint.unsubscribe(words[3]);
                    }
                    else
                    {
                        subint.subscribe(words[3]);
                    }

                }
                if (s.Equals("Status"))
                {
                    string url;
                    foreach (KeyValuePair<string, int> n in pname_port)
                    {
                        switch (pname_type[n.Key])
                        {
                            case "broker":
                                url = "tcp://localhost:" + pname_port[n.Key] + "/BrokerCommunication";
                                BrokerReceiveBroker b = (BrokerReceiveBroker)Activator.GetObject(typeof(BrokerReceiveBroker), url);
                                b.status();

                                break;
                            case "publisher":

                                url = "tcp://localhost:" + pname_port[n.Key] + "/PMPublish";
                                PubInterface p = (PubInterface)Activator.GetObject(typeof(PubInterface), url);
                                p.status();

                                break;
                            case "subscriber":

                                url = "tcp://localhost:" + pname_port[n.Key] + "/MPMSubUnsub";
                                SubInterface sub = (SubInterface)Activator.GetObject(typeof(SubInterface), url);
                                sub.status();

                                break;
                        }
                    }
                }
                if (s.StartsWith("Wait"))
                {
                    log.scriptLog(s);

                    string[] words = s.Split(' ');
                    System.Threading.Thread.Sleep(Int32.Parse(words[1]));
                }
            }
        }