Пример #1
0
 public BrokerRemote(PuppetMaster pm, string uri, string name, string site, string addr)
 {
     _uri = uri;
     _serviceName = name;
     _pm = pm;
     _site = site;
     _orderingPolicy = OrderingPolicy.fifo;
     _routingPolicy = RoutingPolicy.flooding;
     seq = 0;
     _coordinatorURI = addr;
     // c = (ICoordinator)Activator.GetObject(typeof(ICoordinator), addr);
 }
Пример #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (ConfigurationManager.AppSettings["faultTolerance"] == "false")
                faultTolerance = false;
            else if (ConfigurationManager.AppSettings["faultTolerance"] == "true")
                faultTolerance = true;
            else
                MessageBox.Show("Error on fault config");

            StreamWriter writetext = new StreamWriter(ConfigurationManager.AppSettings["logs"], false);
            writetext.Write("");
            writetext.Close();

            myaddr = ConfigurationManager.AppSettings["myaddr"];
            int myport = Int32.Parse(parseURI(myaddr)[2]);
            TcpChannel channel = new TcpChannel(myport);
            ChannelServices.RegisterChannel(channel, true);
            CoordinatorRem c = new CoordinatorRem(this);
            RemotingServices.Marshal(c, "CoordinatorRem", typeof(CoordinatorRem));

            site_site = new Dictionary<string, Site>();
            site_parents = new Dictionary<string, string>();
            site_childs = new Dictionary<string, List<string>>();
            site_brokers = new Dictionary<String, List<Broker>>();
            site_publishers = new Dictionary<String, List<Publisher>>();
            site_subscribers = new Dictionary<String, List<Subscriber>>();
            all_brokers = new Dictionary<String, Broker>();
            all_publishers = new Dictionary<String, Publisher>();
            all_subscribers = new Dictionary<String, Subscriber>();
            uri_processname = new Dictionary<String, String>();
            rout = RoutingPolicy.flooding;
            ord = OrderingPolicy.fifo;
            log = LoggingLevel.light;

            //load proxyies of pms
            getPMs();
            string configFile = ConfigurationManager.AppSettings["config"];

            if (!File.Exists(configFile))
            {
                MessageBox.Show("config.file not found " + Path.GetFullPath(configFile));
                return;
            }

            string[] lines = System.IO.File.ReadAllLines(configFile);

            foreach (string line in lines)
            {
                if (line.StartsWith("//")) continue;
                string[] keywords = line.Split(' ');
                var type = keywords[0];
                if (type == "RoutingPolicy" && keywords.Length >= 2)
                {
                    if (keywords[1] == "filter")
                        rout = RoutingPolicy.filter;
                    else if (keywords[1] == "flooding") { }
                    else
                        MessageBox.Show("Wrong Routing format!");
                }
                else if (type == "LoggingLevel" && keywords.Length >= 2)
                {
                    if (keywords[1] == "full")
                        log = LoggingLevel.full;
                    else if (keywords[1] == "light") { }
                    else
                        MessageBox.Show("Wrong Logging format!");
                }
                else if (type == "Ordering" && keywords.Length >= 2)
                {
                    if (keywords[1] == "NO")
                        ord = OrderingPolicy.no;
                    else if (keywords[1] == "TOTAL")
                        ord = OrderingPolicy.total;
                    else if (keywords[1] == "FIFO") { }
                    else
                        MessageBox.Show("Wrong Ordering format!");

                }
                else if (type == "Site" && keywords.Length >= 4)
                {

                    //Example "Site site0 Parent none"
                    //"Site site1 Parent site0"
                    var parent_site = keywords[3];
                    var site_name = keywords[1];

                    if (parent_site == "none")
                    {
                        site_root = site_name;
                    }
                    else
                    {
                        site_parents.Add(site_name, parent_site);

                        if (!site_childs.ContainsKey(parent_site))
                            site_childs.Add(parent_site, new List<string>());
                        site_childs[parent_site].Add(site_name);
                    }

                }
                else if (type == "Process" && keywords.Length >= 8)
                {
                    //Process subscriber0 Is subscriber On site0 URL tcp://localhost:3337/sub

                    string uri = keywords[7];
                    string ip = parseURI(uri)[1];
                    string port = parseURI(uri)[2];
                    string serviceName = parseURI(uri)[3];
                    string process_type = keywords[3];
                    string site = keywords[5];
                    string processName = keywords[1];

                    switch (process_type)
                    {
                        case "publisher":
                            //create
                            Publisher p = pms[ip].createPublisher(processName, serviceName, site, Int32.Parse(port), myaddr);
                            //associate
                            all_publishers.Add(processName, p);
                            //add it to site publishers
                            if (!site_publishers.ContainsKey(site))
                                site_publishers.Add(site, new List<Publisher>());
                            site_publishers[site].Add(p);
                            if (ip == "localhost")
                                uri = uri.Replace("localhost", LocalIPAddress().ToString());
                            uri_processname.Add(uri, processName);
                            break;
                        case "broker":
                            Broker b = pms[ip].createBroker(processName, serviceName, site, Int32.Parse(port), myaddr);
                            List<Broker> temp = new List<Broker>() { b };
                            if (faultTolerance)
                            {
                                Broker b1 = pms[ip].createBroker(processName + "_1", serviceName, site, Int32.Parse(port) + 500, myaddr);
                                temp.Add(b1);
                                Broker b2 = pms[ip].createBroker(processName + "_2", serviceName, site, Int32.Parse(port) + 600, myaddr);
                                temp.Add(b2);
                            }
                            all_brokers.Add(processName, b);
                            site_brokers.Add(site, temp);
                            site_site.Add(site, new Site() { name = site, brokers = temp });
                            if (ip == "localhost")
                                uri = uri.Replace("localhost", LocalIPAddress().ToString());
                            uri_processname.Add(uri, processName);
                            break;
                        case "subscriber":
                            Subscriber s = pms[ip].createSubscriber(processName, serviceName, site, Int32.Parse(port), myaddr);
                            all_subscribers.Add(processName, s);
                            if (!site_subscribers.ContainsKey(site))
                                site_subscribers.Add(site, new List<Subscriber>());
                            site_subscribers[site].Add(s);
                            if (ip == "localhost")
                                uri = uri.Replace("localhost", LocalIPAddress().ToString());
                            uri_processname.Add(uri, processName);
                            break;
                        default:
                            MessageBox.Show("Error parsing config.file!");
                            break;
                    }

                }
                else
                    MessageBox.Show("Error parsing config.file! at line:\n" + string.Format("'{0}'", line));
            }
            foreach (KeyValuePair<string, List<Broker>> entry in site_brokers)
            {
                foreach (Broker b in entry.Value)
                {
                    b.setRoutingPolicy(rout);
                    b.setOrderingPolicy(ord);
                    b.setLoggingLevel(log);
                }

            }

            foreach (KeyValuePair<string, Subscriber> entry in all_subscribers)
            {
                entry.Value.setOrderingPolicy(ord);
            }

            foreach (var entry in all_publishers)
            {
                entry.Value.setOrderingPolicy(ord);
            }
            foreach (Broker b in site_brokers[site_root])
            {
                b.setIsRoot();
                b.setMySite(site_site[site_root]);
            }

            //Set publishers brokers
            foreach (KeyValuePair<string, List<Publisher>> entry in site_publishers)
            {
                foreach (Broker b in site_brokers[entry.Key])
                    b.setPublishers(entry.Value);

                foreach (Publisher p in entry.Value)
                    p.setSite(site_site[entry.Key]);

            }
            // Set subscriber brokers
            foreach (KeyValuePair<string, List<Subscriber>> entry in site_subscribers)
            {
                foreach (Broker b in site_brokers[entry.Key])
                    b.setSubscribers(entry.Value);
                foreach (Subscriber s in entry.Value)
                    s.setSite(site_site[entry.Key]);

            }

            //Set parents and childs
            foreach (KeyValuePair<string, List<Broker>> entry in site_brokers)
            {
                string site = entry.Key;
                foreach (Broker b in entry.Value)
                {
                    if (site_childs.ContainsKey(site))
                    {
                        List<Site> childs = new List<Site>();
                        foreach (string str in site_childs[site])
                        {
                            if (site_site.ContainsKey(str)) // empty sites
                                childs.Add(site_site[str]);
                        }
                        b.setChildren(childs);
                    }
                    if (site != site_root)
                    {
                        string ps = site_parents[site];
                        b.setParent(site_site[ps]);
                    }
                }
            }
        }
Пример #3
0
 public void setOrderingPolicy(OrderingPolicy p)
 {
     _orderingPolicy = p;
 }
Пример #4
0
 public BrokerRemote(BrokerForm form, PuppetMaster pm, string uri, string name, string site, string addr, string processName)
 {
     _form = form;
     _uri = uri;
     _serviceName = name;
     _site = site;
     _orderingPolicy = OrderingPolicy.fifo;
     _routingPolicy = RoutingPolicy.flooding;
     _coordinatorURI = addr;
     _processName = processName;
 }