/// <summary> /// Adds positive infinity, modeled via <see cref="Maybe.Nothing{T}"/> to a total order. /// </summary> /// <typeparam name="T">The type of elements in the relation.</typeparam> /// <param name="order">The total order.</param> public static ITotalOrder <Maybe <T> > LiftTotalOrderWithInfinity <T>(this ITotalOrder <T> order) => new TotalOrder <Maybe <T> >((x, y) => { var comp = x.HasValue.CompareTo(y.HasValue); //Exactly the first one is infinite -> the first one is greater if (comp < 0) { return(false); } //Exactly the second is infinite -> the second one is greater else if (comp > 0) { return(true); } //Neither have a value <-> both are infinite <-> true else if (!x.HasValue) { return(true); } //Both have a value <-> neither are infinite <-> use underlying order else { return(order.Leq(x.Value(), y.Value())); } });
public RequestHandler(IBacklogRepo backlogrepo, ITotalOrder totalOrder, IUserRepo userRepo, ISecurity security, IPermissionRepo permissionsRepo) { _backlogrepo = backlogrepo; _totalorder = totalOrder; _userRepo = userRepo; _security = security; _permissionsRepo = permissionsRepo; }
/// <summary> /// Returns true iff <paramref name="x"/> is strictly greater than <paramref name="y"/> in the total order <paramref name="order"/>. /// </summary> /// <typeparam name="T">The type of the elements in the relation.</typeparam> /// <param name="order">The total order.</param> /// <param name="x">The first element to compare.</param> /// <param name="y">The second element to compare.</param> public static bool Ge <T>(this ITotalOrder <T> order, T x, T y) => order.Compare(x, y) > 0;
/// <summary> /// Returns true iff <paramref name="x"/> is strictly not equal to <paramref name="y"/> in the total order <paramref name="order"/>. /// </summary> /// <typeparam name="T">The type of the elements in the relation.</typeparam> /// <param name="order">The total order.</param> /// <param name="x">The first element to compare.</param> /// <param name="y">The second element to compare.</param> public static bool Neq <T>(this ITotalOrder <T> order, T x, T y) => order.Compare(x, y) != 0;
static void Main(string[] args) { TcpChannel channel; string name; int id; if (args.Count() > 0) { channel = new TcpChannel(Int32.Parse(args[0].Split(':')[2].Split('/')[0])); name = args[0].Split('/')[3]; id = Int32.Parse(args[1]); } else { channel = new TcpChannel(8088); name = "DIDA-TUPLE-SMR"; id = 1; } ChannelServices.RegisterChannel(channel, false); TupleSpaceSMR server = new TupleSpaceSMR(); //Set min delay and max delay if (args.Length == 4) { server.MinDelay = Int32.Parse(args[2]); server.MaxDelay = Int32.Parse(args[3]); } server.MyPath = args[0]; server.ServerId = id; //if requests received, they are delayed until log recover and master finding complete server.SoftFreeze(); RemotingServices.Marshal(server, name, typeof(TupleSpaceSMR)); List <string> servers = new List <string>(); try { string[] file = File.ReadAllLines(Path.Combine(Directory.GetCurrentDirectory(), "../../../config/serverListSMR.txt")); foreach (string i in file) { //Just ignore my path when caching server's URL if (args[0] != i) { servers.Add(i); } } server.SetServers(servers); } catch (FileNotFoundException) { System.Console.WriteLine("Server List not Found"); System.Console.WriteLine("Aborting..."); System.Environment.Exit(1); } string pathMaster = ""; bool logUpdated = false; Console.WriteLine(server.Log); bool alreadyDiscoverMaster = false; for (int i = 0; i < server.ServerId; i++) { foreach (string serverPath in servers) { try { ITotalOrder remoteServer = (ITotalOrder)Activator.GetObject(typeof(ITotalOrder), serverPath); if (logUpdated == false) { //when the server start running fetch from one server the log //so i can sync my tuple space server.Log = remoteServer.fetchLog(); Console.WriteLine(server.Log); //execute by order operation in that log server.executeLog(); logUpdated = true; } //ask if this replic is the master and give them my path if (remoteServer.areYouTheMaster(args[0])) { pathMaster = serverPath; server.MasterPath = pathMaster; //All replicas ping the master server.setBackup(pathMaster); alreadyDiscoverMaster = true; break; } } catch (Exception) { Console.WriteLine((i + 1) + " attempt -> Failed reaching " + serverPath); } } if (alreadyDiscoverMaster) { break; } } //no master exists! so i am the master now! if (pathMaster == "") { server.setIAmTheMaster(); server.MasterPath = server.MyPath; Console.WriteLine("** STATUS: I'm the master now!"); } else { Console.WriteLine("** STATUS: The master is at " + pathMaster); } //log was updated and master search is over, so i can receive client requests server.SoftUnFreeze(); System.Console.WriteLine("DIDA-TUPLE-SMR Server Started!"); System.Console.WriteLine("---------------"); System.Console.WriteLine("<Enter> to exit..."); System.Console.ReadLine(); }
/// <summary> /// Returns the sign (-1 for negative values, 0 for 0, 1 for positive values) of an element <paramref name="x"/>. /// </summary> /// <typeparam name="TStructure">The type of the algebraic structure to use.</typeparam> /// <typeparam name="T">The type of the elements.</typeparam> /// <param name="st">The algebraic structure to use</param> /// <param name="order">The total order.</param> /// <param name="x">The element whose sign to get.</param> public static int Signum <TStructure, T>(this TStructure st, ITotalOrder <T> order, T x) where TStructure : INeutralElement <T> => order.Compare(x, st.Neutral);
/// <summary> /// Returns the absolute value of an element <paramref name="x"/>, as defined via the piecewise function: /// <code> /// abs(x) = if x < 0 then negate(x) else x /// </code> /// Where <c><</c> is defined by the total order, <c>0</c> is the neutral element of the first grouplike structure, and <c>negate</c> is the inverse-function of the first grouplike structure. /// </summary> /// <typeparam name="TStructure">The ringlike structure.</typeparam> /// <typeparam name="TFirst">The first grouplike structure.</typeparam> /// <typeparam name="T">The type of the elements.</typeparam> /// <param name="st">The structure to use.</param> /// <param name="order">The total order.</param> /// <param name="x">The element whose absolute value to get.</param> public static T Abs <T, TStructure, TFirst>(this TStructure st, ITotalOrder <T> order, T x) where TStructure : IContainsFirst <TFirst> where TFirst : IInverse <T>, INeutralElement <T> => order.Le(x, st.Zero <T, TFirst>()) ? st.Negate(x) : x;