public ConfigureEvent(MachineId env, MachineId manager, int id) : base() { this.Environment = env; this.NodeManager = manager; this.Id = id; }
void Configure() { this.NodeId = (this.ReceivedEvent as Config).Id; this.Keys = (this.ReceivedEvent as Config).Keys; this.Manager = (this.ReceivedEvent as Config).Manager; var nodes = (this.ReceivedEvent as Config).Nodes; var nodeIds = (this.ReceivedEvent as Config).NodeIds; this.NumOfIds = (int)Math.Pow(2, nodes.Count); for (var idx = 1; idx <= nodes.Count; idx++) { var start = (this.NodeId + (int)Math.Pow(2, (idx - 1))) % this.NumOfIds; var end = (this.NodeId + (int)Math.Pow(2, idx)) % this.NumOfIds; var nodeId = this.GetSuccessorNodeId(start, nodeIds); this.FingerTable.Add(start, new Finger(start, end, nodes[nodeId])); } for (var idx = 0; idx < nodeIds.Count; idx++) { if (nodeIds[idx] == this.NodeId) { this.Predecessor = nodes[this.WrapSubtract(idx, 1, nodeIds.Count)]; break; } } this.Raise(new Local()); }
public ConfigureEvent(int id, MachineId[] servers, MachineId manager) : base() { this.Id = id; this.Servers = servers; this.ClusterManager = manager; }
public SentLog(int nextSeqId, MachineId client, int key, int val) { this.NextSeqId = nextSeqId; this.Client = client; this.Key = key; this.Value = val; }
public Config(List<MachineId> servers, MachineId parentServer, int myRank) : base(-1, -1) { this.Servers = servers; this.ParentServer = parentServer; this.MyRank = myRank; }
void InitOnEntry() { this.Bank = this.CreateMachine(typeof(Bank), new Bank.Config(this.Id)); this.ATM = this.CreateMachine(typeof(ATM), new ATM.Config(this.Bank)); this.Goto(typeof(Test1)); }
void DoHook() { var creature = (this.ReceivedEvent as Hook).Creature; var colour = (this.ReceivedEvent as Hook).Colour; if (this.TotalRendezvous == 0) { this.TotalStoppedCreatures++; this.DoPostRoundProcessing(); return; } if (this.FirstHooker == null) { this.FirstHooker = creature; this.FirstColour = colour; } else { this.Send(this.FirstHooker, new Hook(creature, colour)); this.Send(creature, new Hook(this.FirstHooker, this.FirstColour)); this.FirstHooker = null; this.TotalRendezvous = this.TotalRendezvous - 1; } }
/// <summary> /// Constructor. /// </summary> /// <param name="senderMachineId">Sender machine id</param> /// <param name="senderMachineName">Sender machine name</param> /// <param name="senderStateName">Sender state name</param> internal EventOriginInfo(MachineId senderMachineId, string senderMachineName, string senderStateName) { this.SenderMachineId = senderMachineId; this.SenderMachineName = senderMachineName; this.SenderStateName = senderStateName; }
public monitor_valueChosen(MachineId id, int nextSlot, Tuple<int, int> nextProposal, int proposeVal) : base(-1, -1) { this.Node = id; this.NextSlotForProposer = nextSlot; this.NextProposal = nextProposal; this.ProposeVal = proposeVal; }
public Prepare(MachineId id, int nextSlot, Tuple<int, int> nextProposal, int myRank) : base(-1, -1) { this.Node = id; this.NextSlotForProposer = nextSlot; this.NextProposal = nextProposal; this.MyRank = myRank; }
void ProcessBecomeHead() { this.IsHead = true; this.Predecessor = this.Id; var target = (this.ReceivedEvent as ChainReplicationMaster.BecomeHead).Target; this.Send(target, new ChainReplicationMaster.HeadChanged()); }
public int LastLogTerm; // term of candidate’s last log entry public VoteRequest(int term, MachineId candidateId, int lastLogIndex, int lastLogTerm) : base() { this.Term = term; this.CandidateId = candidateId; this.LastLogIndex = lastLogIndex; this.LastLogTerm = lastLogTerm; }
void InitOnEntry() { this.ClusterManager = (this.ReceivedEvent as Config).ClusterManager; this.Keys = (this.ReceivedEvent as Config).Keys; // this.Keys.Add(17); this.QueryCounter = 0; this.Raise(new Local()); }
void Configure() { this.ProcessId = (this.ReceivedEvent as Config).Id; this.RightProcess = (this.ReceivedEvent as Config).RightProcess; this.MaxProcessId = this.ProcessId; this.IsActive = true; this.Goto(typeof(Active)); }
void Configure() { this.NodeManagerMachine = (this.ReceivedEvent as Events.DataNodeConfigEvent).id; this.Idx = (this.ReceivedEvent as Events.DataNodeConfigEvent).idx; this.DataNode = new DataNodeWrapper(this.Idx); this.Monitor<M>(new Events.NodeCreatedEvent()); this.Raise(new Events.UnitEvent()); }
void InitOnEntry() { this.Master = (this.ReceivedEvent as Config).Master; this.Servers = (this.ReceivedEvent as Config).Servers; this.CheckNodeIdx = 0; this.Failures = 100; this.Raise(new Local()); }
void Configure() { this.Environment = (this.ReceivedEvent as ConfigureEvent).Environment; this.NumberOfReplicas = (this.ReceivedEvent as ConfigureEvent).NumberOfReplicas; for (int idx = 0; idx < this.NumberOfReplicas; idx++) { this.CreateNewNode(); } this.Raise(new LocalEvent()); }
public MachineId ReceiverEndpoint; // client public AppendEntriesRequest(int term, MachineId leaderId, int prevLogIndex, int prevLogTerm, List<Log> entries, int leaderCommit, MachineId client) : base() { this.Term = term; this.LeaderId = leaderId; this.PrevLogIndex = prevLogIndex; this.PrevLogTerm = prevLogTerm; this.Entries = entries; this.LeaderCommit = leaderCommit; this.ReceiverEndpoint = client; }
void CorrectHeadFailureOnEntry() { this.Servers.RemoveAt(0); this.Monitor<InvariantMonitor>( new InvariantMonitor.UpdateServers(this.Servers)); this.Monitor<ServerResponseSeqMonitor>( new ServerResponseSeqMonitor.UpdateServers(this.Servers)); this.Head = this.Servers[0]; this.Send(this.Head, new BecomeHead(this.Id)); }
void InitOnEntry() { this.Servers = (this.Payload as object[])[0] as List<MachineId>; this.ParentServer = (this.Payload as object[])[1] as MachineId; this.MyRank = (int)(this.Payload as object[])[2]; this.CurrentLeader = Tuple.Create(this.MyRank, this.Id); this.CommunicateLeaderTimeout = this.CreateMachine(typeof(Timer), this.Id, 100); this.BroadCastTimeout = this.CreateMachine(typeof(Timer), this.Id, 10); this.Raise(new local()); }
void InitOnEntry() { this.NodeSeq = new List<MachineId>(); this.NodeMap = new Dictionary<MachineId, bool>(); this.Initialize(); this.FailureDetector = this.CreateMachine(typeof(FailureDetector)); this.Send(this.FailureDetector, new FailureDetector.Config(this.NodeSeq)); this.Send(this.FailureDetector, new RegisterClient(this.Id)); this.Fail(); }
void Configure() { this.Environment = (this.ReceivedEvent as Events.NodeManagerConfigEvent).env_id; this.DataNodeMachines = new List<MachineId>(); for (int idx = 0; idx < 3; idx++) { this.DataNodeMachines.Add(this.CreateMachine(typeof(DataNodeMachine))); } this.NodeManager = new NodeManagerWrapper(this.DataNodeMachines); this.Send(this.Environment, new Events.ConfigAckEvent(this.DataNodeMachines)); this.Raise(new Events.UnitEvent()); }
void InitOnEntry() { this.PaxosNodes = new List<MachineId>(); this.PaxosNodes.Insert(0, this.CreateMachine(typeof(PaxosNode), 3)); this.PaxosNodes.Insert(0, this.CreateMachine(typeof(PaxosNode), 2)); this.PaxosNodes.Insert(0, this.CreateMachine(typeof(PaxosNode), 1)); foreach (var node in this.PaxosNodes) { this.Send(node, new allNodes(), this.PaxosNodes); } this.Client = this.CreateMachine(typeof(Client), this.PaxosNodes); }
void Configure() { this.Servers = (this.ReceivedEvent as LeaderElection.Config).Servers; this.ParentServer = (this.ReceivedEvent as LeaderElection.Config).ParentServer; this.MyRank = (this.ReceivedEvent as LeaderElection.Config).MyRank; this.CurrentLeader = Tuple.Create(this.MyRank, this.Id); this.CommunicateLeaderTimeout = this.CreateMachine(typeof(Timer)); this.Send(this.CommunicateLeaderTimeout, new Timer.Config(this.Id, 100)); this.BroadCastTimeout = this.CreateMachine(typeof(Timer)); this.Send(this.BroadCastTimeout, new Timer.Config(this.Id, 10)); this.Raise(new local()); }
void EntryOnInit() { this.NumberOfServers = 5; this.LeaderTerm = 0; this.Servers = new MachineId[this.NumberOfServers]; for (int idx = 0; idx < this.NumberOfServers; idx++) { this.Servers[idx] = this.CreateMachine(typeof(Server)); } this.Client = this.CreateMachine(typeof(Client)); this.Raise(new LocalEvent()); }
void EntryOnInit() { this.NumberOfReplicas = 3; this.NumberOfFaults = 1; this.AliveNodes = new List<MachineId>(); this.Monitor<LivenessMonitor>(new LivenessMonitor.ConfigureEvent(this.NumberOfReplicas)); this.NodeManager = this.CreateMachine(typeof(NodeManager)); this.Client = this.CreateMachine(typeof(Client)); this.FailureTimer = this.CreateMachine(typeof(FailureTimer)); this.Send(this.FailureTimer, new FailureTimer.ConfigureEvent(this.Id)); this.Raise(new LocalEvent()); }
void ProcessBecomeTail() { this.IsTail = true; this.Successor = this.Id; for (int i = 0; i < this.SentHistory.Count; i++) { this.Monitor<ServerResponseSeqMonitor>(new ServerResponseSeqMonitor.ResponseToUpdate( this.Id, this.SentHistory[i].Key, this.SentHistory[i].Value)); this.Send(this.SentHistory[i].Client, new ResponseToUpdate()); this.Send(this.Predecessor, new BackwardAck(this.SentHistory[i].NextSeqId)); } var target = (this.ReceivedEvent as ChainReplicationMaster.BecomeTail).Target; this.Send(target, new ChainReplicationMaster.TailChanged()); }
void InitOnEntry() { var numOfWorkers = (this.ReceivedEvent as Config).Input; this.Workers = new List<MachineId>(); for (int idx = 0; idx < numOfWorkers; idx++) { this.Workers.Add(this.CreateMachine(typeof(Worker), new Worker.Config(idx, numOfWorkers))); } this.Master = this.CreateMachine(typeof(Master), new Master.Config(this.Workers)); this.Send(this.Master, new Master.Boot()); this.Raise(new Halt()); }
void Configure() { this.Nodes = new List<MachineId>(); this.Clients = new Dictionary<MachineId, bool>(); this.Alive = new Dictionary<MachineId, bool>(); this.Responses = new Dictionary<MachineId, bool>(); this.Nodes = (this.ReceivedEvent as Config).Nodes; foreach (var node in this.Nodes) { this.Alive.Add(node, true); } this.Timer = this.CreateMachine(typeof(Timer)); this.Send(this.Timer, new Timer.Config(this.Id)); this.Raise(new Unit()); }
void InitOnEntry() { this.ClientId = (this.ReceivedEvent as Config).Id; this.HeadNode = (this.ReceivedEvent as Config).HeadNode; this.TailNode = (this.ReceivedEvent as Config).TailNode; this.StartIn = (this.ReceivedEvent as Config).Value; this.Next = 1; this.KeyValueStore = new Dictionary<int, int>(); this.KeyValueStore.Add(1 * this.StartIn, 100); this.KeyValueStore.Add(2 * this.StartIn, 200); this.KeyValueStore.Add(3 * this.StartIn, 300); this.KeyValueStore.Add(4 * this.StartIn, 400); this.Raise(new Local()); }
/// <summary> /// Sends an asynchronous <see cref="Event"/> to a remote machine. /// </summary> /// <param name="mid">MachineId</param> /// <param name="e">Event</param> /// <param name="sender">Sender machine</param> /// <param name="options">Optional parameters of a send operation.</param> internal override void SendEventRemotely(MachineId mid, Event e, AbstractMachine sender, SendOptions options) { base.NetworkProvider.RemoteSend(mid, e); }
/// <summary> /// Creates a new <see cref="Machine"/> of the specified <see cref="Type"/>. The /// method returns only when the machine is initialized and the <see cref="Event"/> /// (if any) is handled. /// </summary> /// <param name="mid">Unbound machine id</param> /// <param name="type">Type of the machine</param> /// <param name="friendlyName">Friendly machine name used for logging</param> /// <param name="e">Event passed during machine construction</param> /// <param name="operationGroupId">Operation group id</param> /// <param name="creator">Creator machine</param> /// <returns>MachineId</returns> internal abstract Task <MachineId> CreateMachineAndExecute(MachineId mid, Type type, string friendlyName, Event e, Machine creator, Guid?operationGroupId);
/// <summary> /// Creates a new machine of the specified <see cref="Type"/>, using the specified /// unbound machine id, and passes the specified optional <see cref="Event"/>. This /// event can only be used to access its payload, and cannot be handled. /// </summary> /// <param name="mid">Unbound machine id</param> /// <param name="type">Type of the machine</param> /// <param name="e">Event</param> /// <param name="operationGroupId">Optional operation group id</param> public override void CreateMachine(MachineId mid, Type type, Event e = null, Guid?operationGroupId = null) { this.CreateMachine(mid, type, null, e, null, operationGroupId); }
/// <summary> /// Sends an asynchronous <see cref="Event"/> to a machine and /// executes the event handler if the machine is available. /// </summary> /// <param name="mid">MachineId</param> /// <param name="e">Event</param> /// <param name="sender">Sender machine</param> /// <param name="options">Optional parameters of a send operation.</param> internal abstract Task SendEventAndExecute(MachineId mid, Event e, AbstractMachine sender, SendOptions options);
/// <summary> /// Sends an asynchronous event to a machine. /// </summary> /// <param name="mid">Machine id</param> /// <param name="e">Event</param> internal static void Send(MachineId mid, Event e) { if (mid == null) { ErrorReporter.ReportAndExit("Cannot send to a null machine."); } else if (e == null) { ErrorReporter.ReportAndExit("Cannot send a null event."); } if (PSharpRuntime.TaskMap.ContainsKey((int)Task.CurrentId)) { Machine sender = PSharpRuntime.TaskMap[(int)Task.CurrentId]; Output.Log("<SendLog> Machine '{0}({1})' sent event '{2}' to '{3}({4})'.", sender, sender.Id.MVal, e.GetType(), mid.Type, mid.MVal); } else { Output.Log("<SendLog> Event '{0}' was sent to '{1}({2})'.", e.GetType(), mid.Type, mid.MVal); } Machine machine = PSharpRuntime.MachineMap[mid.Value]; bool runHandler = false; machine.Enqueue(e, ref runHandler); if (!runHandler) { PSharpRuntime.BugFinder.Schedule(); return; } Task task = new Task(() => { PSharpRuntime.BugFinder.NotifyTaskStarted(); machine.RunEventHandler(); PSharpRuntime.BugFinder.NotifyTaskCompleted(); }); lock (PSharpRuntime.Lock) { PSharpRuntime.MachineTasks.Add(task); PSharpRuntime.TaskMap.Add(task.Id, machine as Machine); } PSharpRuntime.BugFinder.NotifyNewTaskCreated(task.Id, machine); if (PSharpRuntime.Configuration.ScheduleIntraMachineConcurrency) { task.Start(PSharpRuntime.TaskScheduler); } else { task.Start(); } PSharpRuntime.BugFinder.WaitForTaskToStart(task.Id); PSharpRuntime.BugFinder.Schedule(); }
/// <summary> /// Initializes a new instance of the <see cref="QuiescentEvent"/> class. /// </summary> /// <param name="mid">The id of the machine that has reached quiescence.</param> public QuiescentEvent(MachineId mid) { this.MachineId = mid; }
/// <summary> /// Creates a new machine of the specified <see cref="Type"/>, using the specified /// unbound machine id, and passes the specified optional <see cref="Event"/>. This /// event can only be used to access its payload, and cannot be handled. The method /// returns only when the machine is initialized and the <see cref="Event"/> (if any) /// is handled. /// </summary> /// <param name="mid">Unbound machine id</param> /// <param name="type">Type of the machine</param> /// <param name="e">Event</param> /// <param name="operationGroupId">Optional operation group id</param> public abstract Task CreateMachineAndExecute(MachineId mid, Type type, Event e = null, Guid?operationGroupId = null);
/// <summary> /// Notifies that a machine received an event that it was waiting for. /// </summary> /// <param name="mid">Machine id</param> internal static void NotifyReceivedEvent(MachineId mid) { Machine machine = PSharpRuntime.MachineMap[mid.Value]; PSharpRuntime.BugFinder.NotifyTaskReceivedEvent(machine); }
/// <summary> /// Creates a new instance of the <see cref="QuiescentEvent"/> class. /// </summary> /// <param name="mid">The id of the machine that has reached quiescence.</param> public QuiescentEvent(MachineId mid) : base() { this.mid = mid; }
/// <summary> /// Creates a new machine of the specified <see cref="Type"/>, using the specified /// unbound machine id, and passes the specified optional <see cref="Event"/>. This /// event can only be used to access its payload, and cannot be handled. The method /// returns only when the machine is initialized and the <see cref="Event"/> (if any) /// is handled. /// </summary> /// <param name="mid">Unbound machine id</param> /// <param name="type">Type of the machine</param> /// <param name="e">Event</param> /// <param name="operationGroupId">Optional operation group id</param> /// <returns>MachineId</returns> public override async Task CreateMachineAndExecute(MachineId mid, Type type, Event e = null, Guid?operationGroupId = null) { await this.CreateMachineAndExecute(mid, type, null, e, null, operationGroupId); }
/// <summary> /// Returns the operation group id of the specified machine. During testing, /// the runtime asserts that the specified machine is currently executing. /// </summary> /// <param name="currentMachine">MachineId of the currently executing machine.</param> /// <returns>Guid</returns> public abstract Guid GetCurrentOperationGroupId(MachineId currentMachine);
/// <summary> /// Creates a new machine of the specified <see cref="Type"/>, using the specified /// machine id, and passes the specified optional <see cref="Event"/>. This /// event can only be used to access its payload, and cannot be handled. /// </summary> /// <param name="mid">Unbound machine id</param> /// <param name="type">Type of the machine</param> /// <param name="e">Event</param> /// <param name="operationGroupId">Optional operation group id</param> public abstract void CreateMachine(MachineId mid, Type type, Event e = null, Guid?operationGroupId = null);
/// <summary> /// Creates a new <see cref="Machine"/> of the specified <see cref="Type"/>. /// </summary> /// <param name="mid">Unbound machine id</param> /// <param name="type">Type of the machine</param> /// <param name="friendlyName">Friendly machine name used for logging</param> /// <param name="operationGroupId">Operation group id</param> /// <param name="e">Event passed during machine construction</param> /// <param name="creator">Creator machine</param> /// <returns>MachineId</returns> internal abstract MachineId CreateMachine(MachineId mid, Type type, string friendlyName, Event e, Machine creator, Guid?operationGroupId);
/// <summary> /// Sends an asynchronous <see cref="Event"/> to a remote machine. /// </summary> /// <param name="mid">MachineId</param> /// <param name="e">Event</param> /// <param name="sender">Sender machine</param> /// <param name="options">Optional parameters of a send operation.</param> internal abstract void SendEventRemotely(MachineId mid, Event e, AbstractMachine sender, SendOptions options);
/// <summary> /// Sends an asynchronous <see cref="Event"/> to a remote machine. /// </summary> /// <param name="target">Target machine id</param> /// <param name="e">Event</param> /// <param name="options">Optional parameters of a send operation.</param> public abstract void RemoteSendEvent(MachineId target, Event e, SendOptions options = null);
/// <summary> /// Synchronously delivers an <see cref="Event"/> to a machine and /// executes the event handler if the machine is available. /// </summary> /// <param name="target">Target machine id</param> /// <param name="e">Event</param> /// <param name="options">Optional parameters of a send operation.</param> public abstract Task SendEventAndExecute(MachineId target, Event e, SendOptions options = null);