/// <summary> /// Initializes a new instance of the <see cref="MachineId"/> class. /// </summary> internal MachineId(Type type, string machineName, MachineRuntime runtime, bool useNameForHashing = false) { this.Runtime = runtime; this.Endpoint = string.Empty; if (useNameForHashing) { this.Value = 0; this.NameValue = machineName; this.Runtime.Assert(!string.IsNullOrEmpty(this.NameValue), "Input machine name cannot be null when used as id."); } else { // Atomically increments and safely wraps into an unsigned long. this.Value = (ulong)Interlocked.Increment(ref runtime.MachineIdCounter) - 1; this.NameValue = string.Empty; // Checks for overflow. this.Runtime.Assert(this.Value != ulong.MaxValue, "Detected machine id overflow."); } this.Generation = runtime.Configuration.RuntimeGeneration; this.Type = type.FullName; if (this.IsNameUsedForHashing) { this.Name = this.NameValue; } else { this.Name = string.Format(CultureInfo.InvariantCulture, "{0}({1})", string.IsNullOrEmpty(machineName) ? this.Type : machineName, this.Value.ToString()); } }
public static void Execute(IMachineRuntime runtime) { // Monitors must be registered before the first P# machine // gets created (which will kickstart the runtime). runtime.RegisterMonitor(typeof(Safety)); runtime.RegisterMonitor(typeof(Liveness)); runtime.CreateMachine(typeof(Driver), new Driver.Config(2)); }
/// <summary> /// Static method for safely getting a response from a machine. /// </summary> /// <param name="runtime">The runtime.</param> /// <param name="mid">Target machine id.</param> /// <param name="ev">Event to send whose respose we're interested in getting.</param> public static async Task <T> GetResponse(IMachineRuntime runtime, MachineId mid, Func <MachineId, Event> ev) { var conf = new Config(mid, ev); // This method awaits until the GetResponseMachine finishes its Execute method await runtime.CreateMachineAndExecuteAsync(typeof(GetReponseMachine <T>), conf); // Safely return the result back (no race condition here) return(conf.ReceivedEvent); }
public static void Execute(IMachineRuntime runtime) { runtime.SetLogWriter(new PLogger()); PModule.runtime = runtime; PHelper.InitializeInterfaces(); PHelper.InitializeEnums(); InitializeLinkMap(); InitializeInterfaceDefMap(); InitializeMonitorMap(runtime); InitializeMonitorObserves(); runtime.CreateMachine(typeof(_GodMachine), new _GodMachine.Config(typeof(Main))); }
/// <summary> /// Creates a new shared counter. /// </summary> /// <param name="runtime">The machine runtime.</param> /// <param name="value">The initial value.</param> public static ISharedCounter Create(IMachineRuntime runtime, int value = 0) { if (runtime is ProductionRuntime) { return(new ProductionSharedCounter(value)); } else if (runtime is SystematicTestingRuntime testingRuntime) { return(new MockSharedCounter(value, testingRuntime)); } else { throw new RuntimeException("Unknown runtime object of type: " + runtime.GetType().Name + "."); } }
/// <summary> /// Creates a new shared dictionary. /// </summary> /// <param name="runtime">The machine runtime.</param> public static ISharedDictionary <TKey, TValue> Create <TKey, TValue>(IMachineRuntime runtime) { if (runtime is ProductionRuntime) { return(new ProductionSharedDictionary <TKey, TValue>()); } else if (runtime is SystematicTestingRuntime testingRuntime) { return(new MockSharedDictionary <TKey, TValue>(null, testingRuntime)); } else { throw new RuntimeException("Unknown runtime object of type: " + runtime.GetType().Name + "."); } }
/// <summary> /// Creates a new shared register. /// </summary> /// <param name="runtime">The machine runtime.</param> /// <param name="value">The initial value.</param> public static ISharedRegister <T> Create <T>(IMachineRuntime runtime, T value = default) where T : struct { if (runtime is ProductionRuntime) { return(new ProductionSharedRegister <T>(value)); } else if (runtime is SystematicTestingRuntime testingRuntime) { return(new MockSharedRegister <T>(value, testingRuntime)); } else { throw new RuntimeException("Unknown runtime object of type: " + runtime.GetType().Name + "."); } }
public static void Execute(IMachineRuntime runtime) { // This is the root machine to the P# PingPong program. CreateMachine // executes asynchronously (i.e. non-blocking). runtime.CreateMachine(typeof(NetworkEnvironment)); }
public static void Execute(IMachineRuntime runtime) { runtime.CreateMachine(typeof(Scheduler), new Scheduler.Config(3)); }
public static void Execute(IMachineRuntime runtime) { runtime.CreateMachine(typeof(Host)); }
/// <summary> /// Gets result from the given machine. /// </summary> /// <param name="runtime">The P# runtime.</param> /// <param name="mid">Machine to get response from.</param> static async Task GetDataAndPrint(IMachineRuntime runtime, MachineId mid) { var resp = await GetReponseMachine <M1.Response> .GetResponse(runtime, mid, m => new M1.Get(m)); Console.WriteLine("Got response: {0}", resp.v); }
public static void Execute(IMachineRuntime r) { }
/// <summary> /// Initializes a new instance of the <see cref="LocalNetworkProvider"/> class. /// </summary> public LocalNetworkProvider(IMachineRuntime runtime) { this.Runtime = runtime; this.LocalEndpoint = string.Empty; }
/// <summary> /// Bind the machine id. /// </summary> internal void Bind(MachineRuntime runtime) { this.Runtime = runtime; }
public static bool FairRandom(IMachineRuntime runtime) { return(runtime.FairRandom()); }
public static void InitializeMonitorMap(IMachineRuntime runtime) { PModule.monitorMap.Clear(); }
public static void Execute(IMachineRuntime runtime) { runtime.RegisterMonitor(typeof(InvariantMonitor)); runtime.RegisterMonitor(typeof(ServerResponseSeqMonitor)); runtime.CreateMachine(typeof(Environment)); }
public static void Send(IMachineRuntime runtime, MachineId target) { runtime.SendEvent(target, new E(2)); }
public static void Execute(IMachineRuntime runtime) { runtime.RegisterMonitor(typeof(LivenessMonitor)); runtime.CreateMachine(typeof(Environment)); }
public static void Execute(IMachineRuntime runtime) { runtime.RegisterMonitor(typeof(ValidityCheck)); runtime.CreateMachine(typeof(GodMachine)); }
public static void Execute(IMachineRuntime runtime) { runtime.CreateMachine(typeof(TwoPhaseCommit)); }
/// <summary> /// Registers the testing runtime. /// </summary> public void RegisterRuntime(IMachineRuntime runtime) { runtime.Assert((runtime as SystematicTestingRuntime) != null, "Requires passed runtime to support method GetCurrentMachineId"); this.Runtime = runtime as SystematicTestingRuntime; }
public static void Execute(IMachineRuntime runtime) { runtime.RegisterMonitor(typeof(LivenessMonitor)); runtime.CreateMachine(typeof(ClusterManager)); }
public static void Execute(IMachineRuntime runtime) { // Assigns a user-defined name to this network environment machine. runtime.CreateMachine(typeof(NetworkEnvironment), "TheUltimateNetworkEnvironmentMachine"); }