public IDIDATuple Add(IDIDATuple didatuple, bool fromXLBroadcast) { bool ackFromServers = false; DIDATuple didaAdd = null; if (!fromXLBroadcast) { //broadCast to all servers ackFromServers = BroadcastAdd((DIDATuple)didatuple); } if (ackFromServers || fromXLBroadcast) { didaAdd = (DIDATuple)didatuple; tupleSpace.Add(didaAdd); size++; Console.Write("Client added new tuple : "); this.PrintTuple(didaAdd); } else { Add(didatuple, false); } return(didaAdd); }
public IDIDATuple Read(IDIDATuple didatuple, string name, int port) { if (MaxDelay == -1) { this.SimulateDelay(didatuple); } return(Read(didatuple, name, port, false)); }
public IDIDATuple Take(IDIDATuple didatuple, string name, int port) { if (MaxDelay == -1) { this.SimulateDelay(didatuple); } if (name == null) { numOps++; } this.RequestMostRecent(); string url = "tcp://localhost:" + port + "/" + name; DIDATuple didaTake; //lock (this) //{ didaTake = (DIDATuple)didatuple; int count = 0; if (pending.Count == 0 && isfrozen == false) { foreach (DIDATuple didaTuple in tupleSpace) { if (didaTuple.CompareParams(didaTake)) { //remove element from tuple space Console.Write("Client removing tuple : "); tupleSpace.RemoveAt(count); this.PrintTuple(didaTake); if (didaTake.getTakeme()) { numOps++; didaTake.setTakeme(false); this.BroadcastTake(didaTake); } return(didatuple); } count++; } } else { Console.Write("Client removing tuple inserted to the queue : "); this.PrintTuple(didaTake); pending.Enqueue(new KeyValuePair <string, DIDATuple>("take", didaTake)); } // } if (name != null) { queuedClients.Add(url, didaTake); } return(null); }
public IDIDATuple Add(IDIDATuple didatuple) { if (MaxDelay == -1) { this.SimulateDelay(didatuple); } return(Add(didatuple, false)); }
public IDIDATuple Take(IDIDATuple didatuple, string name, int port) { if (MaxDelay == -1) { this.SimulateDelay(didatuple); } //broadCast to all servers return(BroadcastTake((DIDATuple)didatuple)); }
public bool XLBroadcastRemove(IDIDATuple didaTuple) { bool result = tupleSpace.Remove((DIDATuple)didaTuple); if (result) { Console.Write("Client removed tuple : "); this.PrintTuple((DIDATuple)didaTuple); } return(result); }
private IDIDATuple Add(IDIDATuple didatuple, bool fromUnfreeze) { DIDATuple didaAdd = (DIDATuple)didatuple; if ((pending.Count == 0 && isfrozen == false) || fromUnfreeze) { tupleSpace.Add(didaAdd); numOps++; size++; Console.Write("Client added new tuple : "); this.PrintTuple(didaAdd); //se tiver algum client a espera deste tuplo foreach (KeyValuePair <string, DIDATuple> elem in queuedClients) { if (elem.Value.CompareParams(didaAdd)) { notifyClient(elem.Key); } } if (didaAdd.getBroadme()) { didaAdd.setBroadme(false); this.BroadcastAdd(didaAdd); } return(didaAdd); } else { Console.Write("Client added new tuple inserted to the queue : "); this.PrintTuple(didaAdd); pending.Enqueue(new KeyValuePair <string, DIDATuple>("add", didaAdd)); return(null); } }
private IDIDATuple Read(IDIDATuple didatuple, string name, int port, bool fromXLBroadcast) { //MULTICAST TO ALL SERVERS - TODO // lock (this) { DIDATuple didaResult = tupleSpace.Read((DIDATuple)didatuple); if (didaResult != null) { return(didaResult); } else { if (!fromXLBroadcast) { //broadCast to all servers return(BroadcastRead((DIDATuple)didatuple)); } } } return(null); }
public IDIDATuple Read(IDIDATuple didatuple, string name, int port) { if (MaxDelay == -1) { this.SimulateDelay(didatuple); } this.RequestMostRecent(); string url = "tcp://localhost:" + port + "/" + name; DIDATuple didaRead; lock (this) { didaRead = (DIDATuple)didatuple; if (pending.Count == 0 && isfrozen == false) { foreach (DIDATuple didaTuple in tupleSpace) { if (didaTuple.CompareParams(didaRead)) { Console.Write("Client reading tuple : "); this.PrintTuple(didaRead); return(didatuple); } } } else { Console.Write("Client reading tuple inserted to the queue : "); this.PrintTuple(didaRead); pending.Enqueue(new KeyValuePair <string, DIDATuple>("read", didaRead)); } } queuedClients.Add(url, didaRead); return(null); }
public void SimulateDelay(IDIDATuple x) { DIDATuple didat = (DIDATuple)x; string name = didat.getName(); string mypath = System.Reflection.Assembly.GetEntryAssembly().Location; string finalpath = mypath.Substring(0, mypath.Length - 10); string newpath = Path.GetFullPath(Path.Combine(finalpath, @"..\..\")); string pathToDelay = newpath + name + "Delay.txt"; string[] lines = System.IO.File.ReadAllLines(pathToDelay); foreach (string line in lines) { //min : max string[] args = line.Split(':'); MinDelay = Int32.Parse(args[0]); MaxDelay = Int32.Parse(args[1]); } Random r = new Random(); int delay = r.Next(MinDelay, MaxDelay); this.Wait(delay); }
private IDIDATuple Add(IDIDATuple didatuple) { return(server.Add(didatuple)); }
public bool XLBroadcastRemove(IDIDATuple didaTuple) { throw new NotImplementedException(); }
public bool XLBroadcastAdd(IDIDATuple didaTuple) { return(Add(didaTuple, true) != null); }
private IDIDATuple Take(IDIDATuple didatuple, string name, int port) { return(server.Take(didatuple, name, port)); }
private IDIDATuple Read(IDIDATuple didatuple, string name, int port) { return(server.Read(didatuple, name, port)); }
public IDIDATuple XLBroadcastRead(IDIDATuple didaTuple) { throw new NotImplementedException(); }
public List <IDIDATuple> XLBroadcastTake(IDIDATuple didaTuple) { throw new NotImplementedException(); }
public IDIDATuple XLBroadcastRead(IDIDATuple didaTuple) { DIDATuple didaRead = (DIDATuple)didaTuple; return(Read(didaTuple, didaRead.getName(), didaRead.getPort(), true)); }
public List <IDIDATuple> XLBroadcastTake(IDIDATuple didaTuple) { return(tupleSpace.Take((DIDATuple)didaTuple)); }
public void Parser(List <string> command, string server_name, string server_port) { Console.WriteLine(); Random r = new Random(); switch (command[0].ToLower()) { case "add": Console.Write("Adding new tuple : "); List <string> fieldsList = command.ToList(); fieldsList.RemoveAt(0); DIDATuple didatuple = new DIDATuple(fieldsList); didatuple.setName(server_name); didatuple.setPort(Int32.Parse(server_port)); Add(didatuple); this.PrintTuple(didatuple); break; case "read": Console.Write("Reading tuple : "); fieldsList = command.ToList(); fieldsList.RemoveAt(0); didatuple = new DIDATuple(fieldsList); didatuple.setName(server_name); didatuple.setPort(Int32.Parse(server_port)); int channel_port = r.Next(7000, 8000); string channel_name = "client" + channel_port; IDIDATuple didatuplefinal = (DIDATuple)Read(didatuple, channel_name, channel_port); this.PrintTuple(didatuple); if (didatuplefinal == null) { Console.WriteLine("-> Unsuccesful search! Waiting.."); TcpServerChannel channel = new TcpServerChannel(channel_name, channel_port); ChannelServices.RegisterChannel(channel, false); RemotingConfiguration.RegisterWellKnownServiceType( typeof(Client), channel_name, WellKnownObjectMode.Singleton); BlockAndWait(); Read(didatuple, channel_name, channel_port); Console.WriteLine("-> Succesful Read!"); ChannelServices.UnregisterChannel(channel); } else { Console.WriteLine("-> Succesful Read!"); } break; case "take": Console.Write("Removing tuple : "); fieldsList = command.ToList(); fieldsList.RemoveAt(0); didatuple = new DIDATuple(fieldsList); didatuple.setName(server_name); didatuple.setPort(Int32.Parse(server_port)); int channel_port2 = r.Next(7000, 8000); string channel_name2 = "client" + channel_port2; IDIDATuple takeFromServer = (DIDATuple)Take(didatuple, channel_name2, channel_port2); this.PrintTuple(didatuple); if (takeFromServer == null) { Console.WriteLine("-> Unsuccesful take! Waiting.."); TcpServerChannel channel2 = new TcpServerChannel(channel_name2, channel_port2); ChannelServices.RegisterChannel(channel2, false); RemotingConfiguration.RegisterWellKnownServiceType( typeof(Client), channel_name2, WellKnownObjectMode.Singleton); BlockAndWait(); Take(didatuple, channel_name2, channel_port2); Console.WriteLine("-> Succesful take!"); ChannelServices.UnregisterChannel(channel2); } else { Console.WriteLine("-> Succesful take!"); } break; case "wait": Console.WriteLine("Waiting"); Wait(Int32.Parse(command[1])); break; case "begin-repeat": Console.WriteLine("Start Repeat"); BeginRepeat(command[1]); break; case "end-repeat": EndRepeat(server_name, server_port); break; } }