static void Main(string[] args) { var proxy = XmlRpcProxyGen.Create<IConnectionProxy>(); var port = NetworkHelper.FindFreePort(); var ipAddress = NetworkHelper.FindIp().ToString(); var nodeInfo = new NodeInfo(ipAddress, port); var electAlg = new Bully(nodeInfo, proxy); var ricartSyncAlgorithm = new RicartSyncAlgorithm(nodeInfo, proxy); var centralizedSyncAlgorithm = new CentralizedSyncAlgorithm(nodeInfo, proxy); var client = new Node(nodeInfo, proxy, electAlg, ricartSyncAlgorithm.Client, centralizedSyncAlgorithm.Client); var server = new Server(port, client, ricartSyncAlgorithm.Server, centralizedSyncAlgorithm.Server); var host = new Host(client, server); Console.WriteLine("Client IP: " + client.NodeInfo.GetIpAndPort()); Console.WriteLine("Client ID: " + client.NodeInfo.Id); while (true) { Console.Write("["+client.NodeInfo.GetIpAndPort()+"] "); Console.WriteLine("The service is ready, please write commands: "); var command = Console.ReadLine(); try { client.ProcessCommand(command); } catch (Exception exception) { Console.WriteLine(exception.Message); } } }
public virtual void Init() { //if (initialized) Assert.Fail("fixture setup called multiple times"); if (initialized) return; initialized = true; var hostLookup = new Dictionary<String, Host>(); var mockProxy = new ConnectionProxyMock(hostLookup); for (var i = 0; i < HostNumber; i++) { //var proxy = XmlRpcProxyGen.Create<IConnectionProxy>(); var port = NetworkHelper.FindFreePort(); var ipAddress = NetworkHelper.FindIp().ToString(); var nodeInfo = new NodeInfo(ipAddress, port); var electAlg = new Bully(nodeInfo, mockProxy); var ricartSyncAlgorithm = new RicartSyncAlgorithm(nodeInfo, mockProxy); var centralizedSyncAlgorithm = new CentralizedSyncAlgorithm(nodeInfo, mockProxy); var client = new Node(nodeInfo, mockProxy, electAlg, ricartSyncAlgorithm.Client, centralizedSyncAlgorithm.Client); var server = new Server(port, client, ricartSyncAlgorithm.Server, centralizedSyncAlgorithm.Server); var host = new Host(client, server); hostLookup.Add(nodeInfo.GetFullUrl(), host); Hosts.Add(host); } //var proxy2 = XmlRpcProxyGen.Create<IConnectionProxy>(); var port2 = NetworkHelper.FindFreePort(); var ipAddress2 = "255.255.255.255"; var nodeInfo2 = new NodeInfo(ipAddress2, port2); var electAlg2 = new Bully(nodeInfo2, mockProxy); var ricartSyncAlgorithm2 = new RicartSyncAlgorithm(nodeInfo2, mockProxy); var centralizedSyncAlgorithm2 = new CentralizedSyncAlgorithm(nodeInfo2, mockProxy); var masterclient = new Node(nodeInfo2, mockProxy, electAlg2, ricartSyncAlgorithm2.Client, centralizedSyncAlgorithm2.Client); MasterHost = new Host(masterclient, new Server(port2, masterclient, ricartSyncAlgorithm2.Server, centralizedSyncAlgorithm2.Server)); hostLookup.Add(nodeInfo2.GetFullUrl(), MasterHost); }