static void Main(string[] args) { Console.WriteLine("@broker !!! porto -> {0}", args[0]); string[] arguments = args[0].Split(';');//arguments[0]->port; arguments[1]->url; arguments[2]->nome; arguments[3]->site; int vizinhos = arguments.Length - 5;//numero de vizinhos List<Broker> lstaux = new List<Broker>(); //iniciar lista de vizinhos for (int i = 4; i < vizinhos + 4; i++) { string[] atr = arguments[i].Split('%');//atr[0]-site, atr[1]-url, atr[2]-nome Broker b = new Broker(atr[1], atr[2], atr[0]); lstaux.Add(b); } TcpChannel channel = new TcpChannel(Int32.Parse(arguments[0])); ChannelServices.RegisterChannel(channel, true); BrokerCommunication brokerbroker = new BrokerCommunication(lstaux, arguments[2]); RemotingServices.Marshal(brokerbroker, "BrokerCommunication", typeof(BrokerCommunication)); MPMBrokerCmd processCmd = new MPMBrokerCmd(); RemotingServices.Marshal(processCmd, "MPMProcessCmd", typeof(MPMBrokerCmd)); Console.ReadLine(); }
static void Main(string[] args) { // Console.WriteLine("@broker !!! porto -> {0}", args[0]); string[] arguments = args[0].Split(';');//arguments[0]->port; arguments[1]->url; arguments[2]->nome; arguments[3]->site; arguments[4]->replicas; int vizinhos = arguments.Length - 6;//numero de vizinhos List<Broker> lstaux = new List<Broker>(); //iniciar lista de vizinhos for (int i = 5; i < vizinhos + 5; i++) { string[] atr = arguments[i].Split('%');//atr[0]-name, atr[1]-site, atr[2]-url Broker b = new Broker(atr[2], atr[0], atr[1]); lstaux.Add(b); } string aux = arguments[4].Substring(0,arguments[4].Length -1); // retirar # do fim da string "replica#replica#" string[] rep =aux.Split('#'); List<string> replicas = new List<string>(); //iniciar lista de replicas foreach(var r in rep){ replicas.Add(r); } TcpChannel channel = new TcpChannel(Int32.Parse(arguments[0])); ChannelServices.RegisterChannel(channel, true); BrokerCommunication brokerbroker = new BrokerCommunication(lstaux, arguments[2], replicas, arguments[0] ); RemotingServices.Marshal(brokerbroker, "BrokerCommunication", typeof(BrokerCommunication)); MPMBrokerCmd processCmd = new MPMBrokerCmd(); RemotingServices.Marshal(processCmd, "MPMProcessCmd", typeof(MPMBrokerCmd)); Console.ReadLine(); }
public void createProcess(TreeNode site, string role, string name, string s, string url) { string aux = "LocalPMcreateProcess @ url -> " + url + " site -> " + s; Console.WriteLine(aux); if (role.Equals("broker")) { Broker b = new Broker(url, name, s); site.setBroker(b); string port = (portCounter++).ToString(); //Process.Start() ProcessStartInfo startInfo = new ProcessStartInfo(@"C:\DAD\PubSub_v3.1\Broker\bin\Debug\Broker.exe"); string[] args = { port, url, name, s }; startInfo.Arguments = String.Join(";", args); Process p = new Process(); p.StartInfo = startInfo; p.Start(); } if (role.Equals("subscriber")) { Subscriber sub = new Subscriber(url, name, s); //site.addSubscriber(sub); string port = (portCounter++).ToString(); ProcessStartInfo startInfo = new ProcessStartInfo(@"C:\DAD\PubSub_v3.1\Subscriber\bin\Debug\Subscriber.exe"); string[] args = { port, url, name, s }; startInfo.Arguments = String.Join(";", args); Process p = new Process(); p.StartInfo = startInfo; p.Start(); } if (role.Equals("publisher")) { Publisher p = new Publisher(url, name, s/*, site.getBroker()*/); //site.addPublisher(p); string port = (portCounter++).ToString(); ProcessStartInfo startInfo = new ProcessStartInfo(@"C:\DAD\PubSub_v3.1\Publisher\bin\Debug\Publisher.exe"); string[] args = { port, url, name, s }; startInfo.Arguments = String.Join(";", args); Process pro = new Process(); pro.StartInfo = startInfo; pro.Start(); } }
//chamada pelos brokers private void floodMsg(Message aux, Broker broker) { foreach (KeyValuePair<Subscriber, string> t in lstSubsTopic) { if (aux.Topic.Equals(t.Value)) { notify(t.Key, aux); } } List<Broker> lst = lstVizinhos; lst.Remove(broker); //propagar para os outros todos foreach (var viz in lst) { floodMsg(aux, this); } }
public void createProcess(TreeNode site, string role, string name, string s, string url) { string aux = "PMcreateProcess @ " + site.ID + " role " + role; MessageBox.Show(aux); if (role.Equals("broker")) { Broker b = new Broker(url, name, s); site.setBroker(b); } if (role.Equals("subscriber")) { Subscriber sub = new Subscriber(url, name, s); site.addSubscriber(sub); } if (role.Equals("publisher")) { Publisher p = new Publisher(url, name, s,site.getBroker()); site.addPublisher(p); } }
public void quickRead(string v, TreeNode root) { string[] lines = System.IO.File.ReadAllLines(v); int siteCount = 0; foreach (string line in lines) { if (line.Contains("LoggingLevel")) { string[] words = line.Split(' ');//words[1] - metodo de log if (words[1].Equals("full")) { logMode = 1; } } if (line.Contains("RoutingPolicy")) { string[] words = line.Split(' ');//words[1] - metodo de routing if(words[1].Equals("filter")){ routing = 1; } } if (line.Contains("Ordering")) { string[] words = line.Split(' ');//words[1] - metodo de ordem if(words[1].Equals("NO")){ order = 0; } if (words[1].Equals("TOTAL")) { order = 2; } } if (line.Contains("Parent")){ string[] words = line.Split(' ');//words[1]-filho, words[3]-pai int mult = 9000 + (siteCount*100); site_port.Add(words[1], mult); siteCount++; } if (line.Contains("Is broker")) { string[] words = line.Split(' '); //words[1]-name, words[5]-site, words[7]-url TreeNode t = site_treeNode[words[5]]; //actualizar estruturas pname_port[words[1]] = site_port[words[5]] + 1; site_port[words[5]]++; Broker aux = new Broker(words[1], words[5], words[7]); node_broker.Add(t, aux); } if (line.Contains("Is publisher")) { string[] words = line.Split(' '); //words[1]-name, words[5]-site, words[7]-url TreeNode t = site_treeNode[words[5]]; //actualizar pname_port[words[1]] = site_port[words[5]] + 1; site_port[words[5]]++; } if (line.Contains("Is subscriber")) { string[] words = line.Split(' '); //words[1]-name, words[5]-site, words[7]-url TreeNode t = site_treeNode[words[5]]; //actualizar pname_port[words[1]] = site_port[words[5]] + 1; site_port[words[5]]++; } } }
public void setBroker(Broker b) { broker = b; }
private Broker broker; //broker do seu site #endregion Fields #region Constructors public Publisher(string u, string n, string s, Broker b) : base(u, n, s) { broker = b; }
public void quickRead(string v, TreeNode root) { string[] lines = System.IO.File.ReadAllLines(v); int siteCount = 0; foreach (string line in lines) { if (line.Contains("LoggingLevel")) { string[] words = line.Split(' ');//words[1] - metodo de log if (words[1].Equals("full")) { logMode = 1; } } if (line.Contains("RoutingPolicy")) { string[] words = line.Split(' ');//words[1] - metodo de routing if(words[1].Equals("filtering")){ routing = 1; } } if (line.Contains("Ordering")) { string[] words = line.Split(' ');//words[1] - metodo de ordem if(words[1].Equals("NO")){ order = 0; } if (words[1].Equals("TOTAL")) { order = 2; } } if (line.Contains("Parent")){ string[] words = line.Split(' ');//words[1]-filho, words[3]-pai int mult = 9000 + (siteCount*100); site_port.Add(words[1], mult); siteCount++; } if (line.Contains("is broker")) { string[] words = line.Split(' '); //words[1]-name, words[5]-site, words[7]-url TreeNode t = site_treeNode[words[5]]; //actualizar estruturas pname_type.Add(words[1], "broker"); string[] z = words[7].Split(':');//z[0]->tcp;z[1]->//localhost;z[2]->XXXX/broker string[] y = z[2].Split('/'); int port = Int32.Parse(y[0]); pname_port[words[1]] = port; Broker aux = new Broker(words[7], words[1], words[5]); // se o site já existe adicionar novo broker à lista if (node_broker.ContainsKey(t)) { node_broker[t].Add(aux); } else { node_broker.Add(t, new List<Broker> { aux }); } } if (line.Contains("is publisher")) { string[] words = line.Split(' '); //words[1]-name, words[5]-site, words[7]-url TreeNode t = site_treeNode[words[5]]; //actualizar pname_type.Add(words[1], "publisher"); string[] z = words[7].Split(':');//z[0]->tcp;z[1]->//localhost;z[2]->XXXX/broker string[] y = z[2].Split('/'); int port = Int32.Parse(y[0]); pname_port[words[1]] = port; } if (line.Contains("is subscriber")) { string[] words = line.Split(' '); //words[1]-name, words[5]-site, words[7]-url TreeNode t = site_treeNode[words[5]]; //actualizar pname_type.Add(words[1], "subscriber"); string[] z = words[7].Split(':');//z[0]->tcp;z[1]->//localhost;z[2]->XXXX/broker string[] y = z[2].Split('/'); int port = Int32.Parse(y[0]); pname_port[words[1]] = port; } } }
//actualiza node_broker + site_name public List<MyProcess> fillProcessList(string v, TreeNode root) { PuppetInterface myremote; string[] lines = System.IO.File.ReadAllLines(v); List<MyProcess> res = new List<MyProcess>(); foreach (string line in lines) { if (line.Contains("Is broker")) { string[] words = line.Split(' '); //words[1]-name, words[5]-site, words[7]-url TreeNode t = site_treeNode[words[5]]; string urlService = words[7].Substring(0, words[7].Length - 6); myremote = (PuppetInterface)Activator.GetObject(typeof(PuppetInterface),urlService+"PuppetMasterURL"); myremote.createProcess(t, "broker", words[1], words[5], words[7]); //actualizar estruturas Broker aux = new Broker(words[1], words[5], words[7]); t.setBroker(aux); pname_site.Add(words[1], words[5]); node_broker.Add(t, aux); res.Add(aux); } if (line.Contains("Is publisher")) { string[] words = line.Split(' '); //words[1]-name, words[5]-site, words[7]-url TreeNode t = site_treeNode[words[5]]; string urlService = words[7].Substring(0, words[7].Length - 9); myremote = (PuppetInterface)Activator.GetObject(typeof(PuppetInterface), urlService + "PuppetMasterURL"); myremote.createProcess(t,"publisher", words[1], words[5], words[7]); //actualizar //Broker b = findBroker(words[5]); Publisher aux = new Publisher(words[1], words[5], words[7]/*, b*/); //t.addPublisher(aux); pname_site.Add(words[1], words[5]); res.Add(aux); } if (line.Contains("Is subscriber")) { string[] words = line.Split(' '); //words[1]-name, words[5]-site, words[7]-url TreeNode t = site_treeNode[words[5]]; string urlService = words[7].Substring(0, words[7].Length - 10); myremote = (PuppetInterface)Activator.GetObject(typeof(PuppetInterface), urlService + "PuppetMasterURL"); myremote.createProcess(t,"subscriber", words[1], words[5], words[7]); //actualizar Subscriber aux = new Subscriber(words[1], words[5], words[7]); //t.addSubscriber(aux); pname_site.Add(words[1], words[5]); res.Add(aux); } } return res; }