public void addNeighbour(ServiceNode neighbourNode) { if (!hasNeighbour(neighbourNode)) { neighbours.Add(neighbourNode); neighbourNode.addNeighbour(this); } }
public void removeNeighbour(ServiceNode neighbour) { neighbours.Remove(neighbour); }
public bool hasNeighbour(ServiceNode node) { return neighbours.Contains(node); }
public bool hasNeighbour(ServiceNode node) { return(neighbours.Contains(node)); }
/// <summary> /// Create a ServiceNodeCore and initialize its fields. /// </summary> /// <param name="serviceNode">represents the ServiceNode and its settings.</param> public ServiceNodeCore(ServiceNode serviceNode) { this.serviceNode = serviceNode; // Create a new instance of the service implementor. serviceImpl = new DarPoolingService(this); mobileServiceImpl = new DarPoolingServiceMobile(serviceImpl); //serviceImpl.SetMobileHandler = mobileServiceImpl; // Set the delegates removeJoinedUser = new RemoveJoinedUser(serviceImpl.RemoveJoinedUser); string serviceIP = "localhost"; baseHTTPAddress = "http://" + serviceIP + ":1111/"; baseMobileAddress = "http://" + serviceIP + ":1155/"; baseForwardAddress = "http://" + serviceIP + ":1177/"; //Console.WriteLine("Final addresses are:\n {0}\n{1}\n{2}",baseHTTPAddress, baseMobileAddress, baseForwardAddress); InitializeXmlDatabases(); }
/// <summary> /// Retrieve the coordinates from location names, build the ServiceNode /// and ServiceNodeCore objects, set the topology of the net of service nodes. /// </summary> public static void InitializeNodes(bool fullTopology) { Console.WriteLine("**** DarPooling Service Nodes ****\n"); string[] locNames = new string[] { "Venezia", "Milano", "Torino", "Genova", "Pisa", "Roma", "Napoli", "Bari", "CT Aci Trezza", "CT Nicolosi", "Bologna" }; // Obtain the Location coordinates from the location name Console.Write("Retrieving Coordinates from GMap Server.... "); foreach (string locName in locNames) { Location location = GMapsAPI.addressToLocation(locName); nameLoc.Add(locName, location); } foreach (string locName in locNames) { //Console.WriteLine("Dtance between {0} and {1} is {2} km", locNames[4], locName, nameLoc[locNames[4]].distance(nameLoc[locName])); } Console.WriteLine("Done!"); // ServiceNode ServiceNode veneziaSN = new ServiceNode("Venezia", locNames[0], nameLoc[locNames[0]]); ServiceNode milanoSN = new ServiceNode("Milano", locNames[1], nameLoc[locNames[1]]); ServiceNode torinoSN = new ServiceNode("Torino", locNames[2], nameLoc[locNames[2]]); ServiceNode genovaSN = new ServiceNode("Genova", locNames[3], nameLoc[locNames[3]]); ServiceNode pisaSN = new ServiceNode("Pisa", locNames[4], nameLoc[locNames[4]]); ServiceNode romaSN = new ServiceNode("Roma", locNames[5], nameLoc[locNames[5]]); ServiceNode napoliSN = new ServiceNode("Napoli", locNames[6], nameLoc[locNames[6]]); ServiceNode bariSN = new ServiceNode("Bari", locNames[7], nameLoc[locNames[7]]); ServiceNode cataniaSN = new ServiceNode("Catania", locNames[8], nameLoc[locNames[8]]); ServiceNode catania2SN = new ServiceNode("Catania2", locNames[9], nameLoc[locNames[9]]); ServiceNode bolognaSN = new ServiceNode("Bologna", locNames[10], nameLoc[locNames[10]]); // ServiceNodeCore ServiceNodeCore venezia = new ServiceNodeCore(veneziaSN); ServiceNodeCore milano = new ServiceNodeCore(milanoSN); ServiceNodeCore torino = new ServiceNodeCore(torinoSN); ServiceNodeCore genova = new ServiceNodeCore(genovaSN); ServiceNodeCore pisa = new ServiceNodeCore(pisaSN); ServiceNodeCore roma = new ServiceNodeCore(romaSN); ServiceNodeCore napoli = new ServiceNodeCore(napoliSN); ServiceNodeCore bari = new ServiceNodeCore(bariSN); ServiceNodeCore catania = new ServiceNodeCore(cataniaSN); ServiceNodeCore catania2 = new ServiceNodeCore(catania2SN); ServiceNodeCore bologna = new ServiceNodeCore(bolognaSN); // Set Topology if (fullTopology) { venezia.addNeighbour(milano); venezia.addNeighbour(bologna); milano.addNeighbour(torino); milano.addNeighbour(genova); torino.addNeighbour(genova); genova.addNeighbour(pisa); bologna.addNeighbour(pisa); pisa.addNeighbour(roma); roma.addNeighbour(napoli); napoli.addNeighbour(bari); napoli.addNeighbour(catania); napoli.addNeighbour(catania2); catania.addNeighbour(catania2); } else { milano.addNeighbour(roma); roma.addNeighbour(catania); } ServiceNodeCore[] nodes; if (fullTopology) { nodes = new ServiceNodeCore[] { venezia, milano, torino, genova, bologna, pisa, roma, napoli, bari, catania, catania2 }; } else { nodes = new ServiceNodeCore[] { milano, roma, catania //,venezia, torino, genova, pisa, roma, napoli, bari, catania2, bologna }; } sncList.AddRange(nodes); }