public void unsubscribe(string topic) { string urlRemote = url.Substring(0, url.Length - 8);//retirar XXXX/subscriber string myURL = urlRemote + myPort; subscriptions.Remove(topic); Console.WriteLine("unsubscribing on topic {0} o meu url e {1}", topic, myURL); foreach (var broker in urlMyBroker) { BrokerReceiveBroker subunsub = (BrokerReceiveBroker)Activator.GetObject(typeof(BrokerReceiveBroker), broker + "BrokerCommunication"); try { SubUnsubRemoteAsyncDelegate remoteDel = new SubUnsubRemoteAsyncDelegate(subunsub.receiveUnsub); AsyncCallback RemoteCallBack = new AsyncCallback(SubUnsubRemoteAsyncCallBack); IAsyncResult remAr = remoteDel.BeginInvoke(topic, myURL, RemoteCallBack, null); } catch(SocketException) { Console.WriteLine("Could not locate server"); } //subunsub.receiveUnsub(topic, myURL); } }
public void forwardUnsub(string topic, string brokerName) { //Console.WriteLine("unsub on topic {0} received from {1}", topic, brokerName); //buscar broker com nome brokerName foreach (var v in lstVizinhos) { if (v.Name.Equals(brokerName)) { Broker aux = v; if (routingTable.ContainsKey(aux))//ja tenho uma entrada para este broker { routingTable[aux].Remove(topic); } } } 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 { SubUnsubRemoteAsyncDelegate RemoteDel = new SubUnsubRemoteAsyncDelegate(bro.forwardUnsub); AsyncCallback RemoteCallBack = new AsyncCallback(SubUnsubRemoteAsyncCallBack); IAsyncResult RemAr = RemoteDel.BeginInvoke(topic, name, RemoteCallBack, null); } catch (SocketException) { Console.WriteLine("Could not locate server"); } } }
public void subscribe(string topic) { string urlRemote = this.url.Substring(0, this.url.Length - 8);//retira XXXX/subscriber string myURL = urlRemote + myPort; Console.WriteLine("subscribing on topic {0} o meu url e {1}", topic, myURL); subscriptions.Add(topic); foreach (var broker in urlMyBroker) { BrokerReceiveBroker subunsub = (BrokerReceiveBroker)Activator.GetObject(typeof(BrokerReceiveBroker), broker + "BrokerCommunication"); try { SubUnsubRemoteAsyncDelegate remoteDel = new SubUnsubRemoteAsyncDelegate(subunsub.receiveSub); AsyncCallback RemoteCallBAck = new AsyncCallback(SubUnsubRemoteAsyncCallBack); IAsyncResult remAr = remoteDel.BeginInvoke( topic, myURL, RemoteCallBAck, null ); } catch(SocketException) { Console.WriteLine("Could not locate server"); } //subunsub.receiveSub(topic, myURL); } Stopwatch sw = new Stopwatch(); sw.Start(); // enquanto não recebi todas as respostas while (okBrokers != liveBrokers) { //enquanto não for timeout if (sw.ElapsedMilliseconds > 1000) { //TODO - enviar mensagem ao broker return; } } okBrokers = 0; //BrokerReceiveBroker subunsub = (BrokerReceiveBroker)Activator.GetObject(typeof(BrokerReceiveBroker), urlMyBroker+"BrokerCommunication"); //subunsub.receiveSub(topic, myURL); }
public void forwardSub(string topic, string brokerName) { //buscar broker com nome brokerName foreach (var v in lstVizinhos) { if (v.Name.Equals(brokerName)) { Broker aux = v; if (routingTable.ContainsKey(aux))//ja tenho uma entrada para este broker { if (!routingTable[aux].Contains(topic))//adicionar apenas se for outro topico { routingTable[aux].Add(topic); } } else { routingTable[aux] = new List<string> { topic }; } } } 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 if (!isLeader)//se não és lider não propagas { return; } foreach (var viz in lst) { string urlRemote = viz.URL.Substring(0, viz.URL.Length - 6);//retirar XXXX/broker Console.WriteLine("Flooding vizinho em {0}", urlRemote); BrokerReceiveBroker bro = (BrokerReceiveBroker)Activator.GetObject(typeof(BrokerReceiveBroker), urlRemote + "BrokerCommunication"); try { SubUnsubRemoteAsyncDelegate RemoteDel = new SubUnsubRemoteAsyncDelegate(bro.forwardSub); AsyncCallback RemoteCallBack = new AsyncCallback(SubUnsubRemoteAsyncCallBack); IAsyncResult RemAr = RemoteDel.BeginInvoke(topic, name, RemoteCallBack, null); } catch (SocketException) { Console.WriteLine("Could not locate server"); } } }