public void sendRemoveSubscription() { lock (this) { subscribeParameters removeSubscription = new subscribeParameters(); int positionToRemove = 0; if (removeCommandList.Count >= (removeListOrder + 1)) { removeSubscription = removeCommandList[removeListOrder]; removeListOrder++; if (removeSubscription.topicName.Contains("*")) { string[] result = removeSubscription.topicName.Split(new Char[] { '*' }); removeSubscription.topicName = result[0]; } for (int i = topics.Count - 1; i >= 0; i--) { if (topics[i].Equals(removeSubscription.topicName)) { positionToRemove = i; removeSubscription.urlSubCreator = subscriberData.url; removeSubscription.urlBroker = broker.getData().url; Console.WriteLine("Remove Subscription on: " + removeSubscription.topicName); broker.RemoveSubscriptionList(removeSubscription); foreach (BrokerInterface brokerReplica in brokerReplicas) { brokerReplica.RemoveSubscriptionList(removeSubscription); } broker.logMsgFromBrokerToMaster(removeSubscription.type + " from " + removeSubscription.processName + " on " + removeSubscription.topicName); } } topics.RemoveAt(positionToRemove); } } }
public void RemoveSubscription(subscribeParameters parameters) { lock (this) { int position = 0; if (!SingleMachine) { remoteSlave.msgToSlave("Unsubscribe from: " + parameters.processName + " on topic: " + parameters.topicName); } Console.WriteLine("Removed Subscription from: " + parameters.processName + " on: " + parameters.topicName); for (int i = 0; i < topicsSubscriptons[parameters.topicName].Count; i++) { if (topicsSubscriptons[parameters.topicName][i].Equals(parameters.urlSubCreator)) { position = i; } } topicsSubscriptons[parameters.topicName].RemoveAt(position); if (topicsSubscriptons[parameters.topicName].Count == 0) { topicsSubscriptons.Remove(parameters.topicName); } if (routingPolicy.Equals("filter")) { removeSubFilter(parameters); } } }
public void UpdateSubscriptionList(subscribeParameters parameters) { lock (this) { List <string> list; if (!topicsSubscriptons.TryGetValue(parameters.topicName, out list)) { list = new List <string>(); topicsSubscriptons.Add(parameters.topicName, list); list.Add(parameters.urlSubCreator); } else { topicsSubscriptons[parameters.topicName].Add(parameters.urlSubCreator); } Console.WriteLine("New Subscription arrived from: " + parameters.processName + " on: " + parameters.topicName); if (!SingleMachine) { remoteSlave.msgToSlave("New Subscription arrived from: " + parameters.processName + " on: " + parameters.topicName); } if (routingPolicy.Equals("filter")) { subFilter(parameters); } } }
public void AddSubscription(subscribeParameters parameters) { commandsList.Add(parameters); ThreadStart tx = new ThreadStart(this.sendSubscription); Thread t_x = new Thread(tx); t_x.Start(); }
public void RemoveSubscription(subscribeParameters parameters) { removeCommandList.Add(parameters); ThreadStart tz = new ThreadStart(this.sendRemoveSubscription); Thread t_z = new Thread(tz); t_z.Start(); }
public void removeEntryRoutingTable(subscribeParameters parameters) { routingEvents eventToRemove = new routingEvents(); bool canRemoveEvent = false; foreach (routingEvents RoutingEventToRemove in routingTable) { if (RoutingEventToRemove.Topic.Equals(parameters.topicName) && RoutingEventToRemove.UrlSubscriberOnTopic.Equals(parameters.urlSubCreator)) { canRemoveEvent = true; eventToRemove.Topic = RoutingEventToRemove.Topic; eventToRemove.UrlBrokerSender = RoutingEventToRemove.UrlBrokerSender; eventToRemove.UrlSubscriberOnTopic = RoutingEventToRemove.UrlSubscriberOnTopic; } } if (canRemoveEvent) { routingTable.Remove(eventToRemove); } }
public void removeSubFilter(subscribeParameters parameters) { if (!brokerData.url.Equals(parameters.urlBroker)) { removeEntryRoutingTable(parameters); } if (isLeader) { if (!subscribersRegistry.ContainsKey(parameters.processName)) { foreach (BrokerInterface replica in replicas) { replica.RemoveSubscriptionList(parameters); } } subFloodRemove.Add(parameters); ThreadStart td = new ThreadStart(this.subscriptionFloodRemove); Thread t_d = new Thread(td); t_d.Start(); } }
public void UpdateRoutingTable(subscribeParameters parameters) { bool cantCreateNewEvent = false; foreach (routingEvents Event in routingTable) { if (Event.Topic.Equals(parameters.topicName) && Event.UrlSubscriberOnTopic.Equals(parameters.urlSubCreator)) { cantCreateNewEvent = true; } } if (!cantCreateNewEvent) { routingEvents newEventArrived = new routingEvents(); newEventArrived.Topic = parameters.topicName; newEventArrived.UrlBrokerSender = parameters.urlBrokerSender; newEventArrived.UrlSubscriberOnTopic = parameters.urlSubCreator; routingTable.Add(newEventArrived); Console.WriteLine("RoutingTable Updated on: " + brokerData.name + " for topic: " + parameters.topicName + " sender: " + parameters.urlBrokerSender + " creator: " + parameters.urlSubCreator); } }
public void removeSubFilter(subscribeParameters parameters) { subFloodRemove(parameters); }
public void subFilter(subscribeParameters parameters) { subFlood(parameters); }
public void RemoveSubscriptionList(subscribeParameters parameters) { removeSubscription(parameters); }
public void UpdateSubscriptionList(subscribeParameters parameters) { addSubscription(parameters); }
public void sendSubscription() { lock (this) { subscribeParameters subscriber = new subscribeParameters(); if (commandsList.Count >= (commandListOrder + 1)) { subscriber = commandsList[commandListOrder]; commandListOrder++; Console.WriteLine("New Subscription on: " + subscriber.topicName); if (subscriber.topicName.Contains("*")) { string[] result = subscriber.topicName.Split(new Char[] { '*' }); topics.Add(result[0]); subscriber.topicName = result[0]; subscriber.urlSubCreator = subscriberData.url; try { subscriber.urlBroker = broker.getData().url; broker.UpdateSubscriptionList(subscriber); broker.logMsgFromBrokerToMaster("New " + subscriber.type + " from " + subscriber.processName + " on " + subscriber.topicName); } catch (SocketException e) { Console.WriteLine("O Leader esta Morto"); broker = brokerReplicas[0]; brokerReplicas.RemoveAt(0); broker.setBrokerLeader(); broker.setReplicas(brokerReplicas[1].getData().url); Console.WriteLine("New Leader " + broker.getData().name); } foreach (BrokerInterface brokerReplica in brokerReplicas) { brokerReplica.UpdateSubscriptionList(subscriber); } } else { topics.Add(subscriber.topicName); subscriber.urlSubCreator = subscriberData.url; try { subscriber.urlBroker = broker.getData().url; broker.UpdateSubscriptionList(subscriber); broker.logMsgFromBrokerToMaster("New " + subscriber.type + " from " + subscriber.processName + " on " + subscriber.topicName); } catch (SocketException e) { Console.WriteLine("O Leader esta Morto"); broker = brokerReplicas[0]; brokerReplicas.Remove(broker); broker.setBrokerLeader(); broker.setReplicas(brokerReplicas[1].getData().url); Console.WriteLine("New Leader " + broker.getData().name); } foreach (BrokerInterface brokerReplica in brokerReplicas) { brokerReplica.UpdateSubscriptionList(subscriber); } } } } }
public void RemoveSubscription(subscribeParameters parameters) { unsubscription(parameters); }
public void AddSubscription(subscribeParameters topicname) { subscription(topicname); }