Exemplo n.º 1
0
        private string graphString(ReadOnlyDictionary <IActorRef, ReadOnlyCollection <IActorRef> > graph)
        {
            StringBuilder output = new StringBuilder();

            foreach (var pair in graph)
            {
                IActorRef a = pair.Key;
                output.Append($"{a.ToShortString()} => ");
                output.Append("[ ");
                foreach (var v in pair.Value)
                {
                    output.Append(v.ToShortString() + " ");
                }
                output.Append("]\n");
            }

            return(output.ToString());
        }
Exemplo n.º 2
0
        public void ProcessCrash(VertexPair crashedLink, HashSet <VertexPair> F, bool outFlag)
        {
            IActorRef p  = crashedLink.V1;
            IActorRef pk = crashedLink.V2;

            if (!graph.ContainsKey(p))
            {
                return;
            }

            if (!hasSuccessors(p))
            {
                Queue <VertexPair> possibleRecipients = new Queue <VertexPair>();

                foreach (var n in allSuccessors[p])
                {
                    if (!n.Equals(pk) && !n.Equals(trackedServer))
                    {
                        possibleRecipients.Enqueue(new VertexPair(p, n));
                    }
                }

                while (possibleRecipients.Count != 0)
                {
                    VertexPair link = possibleRecipients.Dequeue();
                    graph[link.V1].AddLast(link.V2);
                    if (!graph.ContainsKey(link.V2))
                    {
                        graph[link.V2] = new LinkedList <IActorRef>();

                        foreach (var err in F)
                        {
                            if (err.V1.Path.Equals(link.V2.Path))
                            {
                                foreach (var n in allSuccessors[link.V2])
                                {
                                    if (n.Path.Equals(trackedServer.Path))
                                    {
                                        continue;
                                    }
                                    VertexPair additional = new VertexPair(link.V2, n);

                                    if (outFlag == true)
                                    {
                                        Console.WriteLine($"====================> Try to add {additional.V1.ToShortString()} {additional.V2.ToShortString()}");
                                    }

                                    if (!F.Contains(additional))
                                    {
                                        if (outFlag == true)
                                        {
                                            Console.WriteLine($"====================> added {additional.V1.ToShortString()} {additional.V2.ToShortString()}");
                                        }

                                        possibleRecipients.Enqueue(additional);
                                    }
                                }
                                break;
                            }
                        }
                    }
                }
            }
            else
            {
                graph[p].Remove(pk);

                if (graph[p].Count == 0) // Not checked
                {
                    Queue <IActorRef> pToDel = new Queue <IActorRef>();
                    pToDel.Enqueue(p);

                    while (pToDel.Count != 0)
                    {
                        IActorRef currentP = pToDel.Dequeue();
                        graph.Remove(currentP);

                        foreach (var key in graph.Keys)
                        {
                            graph[key].Remove(currentP);
                            if (graph[key].Count == 0)
                            {
                                pToDel.Enqueue(key);
                            }
                        }
                    }
                }

                List <IActorRef> keysToDelete = new List <IActorRef>();
                foreach (var pair in graph)
                {
                    if (!pathExists(pair.Key))
                    {
                        keysToDelete.Add(pair.Key);
                    }
                }
                foreach (var k in keysToDelete)
                {
                    graph.Remove(k);
                }
            }

            bool failure = false;

            foreach (var pair in graph)
            {
                IActorRef link = pair.Key;
                foreach (var err in F)
                {
                    if (err.V1.Path.Equals(link.Path))
                    {
                        failure = true;
                        break;
                    }
                }

                if (!failure)
                {
                    return;
                }
                failure = false;
            }
            if (outFlag)
            {
                Console.WriteLine($"XXXXX {trackedServer.ToShortString()} cleared");
            }
            Clear();
        }
Exemplo n.º 3
0
        public LogActor()
        {
            sw = new Stopwatch();
            sw.Start();

            Receive <Messages.LogABcastVerbose>((m) => {
                long time = m.RoundTime;
                long mcs  = time / 1000;
                long ns   = time % 1000;
                long ms   = mcs / 1000;
                mcs      %= 1000;

                StringBuilder output = new StringBuilder();
                output.AppendLine(new string('-', 80));
                var msgs = m.ADeliveredMsgs;
                output.AppendLine($"Round {m.Stage}, Actor '{Sender.Path}' " +
                                  $"A-Delivered {msgs.Count} msgs in [{ms}ms{mcs}mcs{ns}ns] : ");

                for (int i = 0; i < msgs.Count; i++)
                {
                    var inner_msgs = msgs[i].Message.Value as ReadOnlyCollection <Messages.Abroadcast>;
                    if (inner_msgs == null)
                    {
                        output.Append(msgs[i].Message);
                    }
                    else
                    {
                        for (int j = 0; j < inner_msgs.Count; j++)
                        {
                            output.Append(inner_msgs[j]);
                            output.Append((j != inner_msgs.Count - 1) ? "," : "");
                        }
                    }

                    output.Append((i != msgs.Count - 1) ? " -> " : "#");
                }
                Console.WriteLine(output);
            });
            Receive <Messages.LogAbcast>((m) => {
                Console.WriteLine($"{m.Stage} {m.RoundTime} {m.ActorsNumber} {m.Throughput} {sw.ElapsedMilliseconds}ms");
            });

            Receive <Messages.LogGraph>((m) => {
                Console.WriteLine(graphString(m.Graph));
            });
            Receive <Messages.LogTrackGraph>((m) => {
                StringBuilder output = new StringBuilder();
                output.AppendLine(new string('+', 80));
                output.AppendLine($"Tracking graphs of the actor '{Sender.Path}' : ");
                foreach (var g in m.Graphs)
                {
                    IActorRef a = g.Key;
                    output.Append($"Message from {a.ToShortString()} graph: \n");
                    output.Append(graphString(g.Value));
                }
                output.Append("\n");
                Console.WriteLine(output);
            });
            Receive <Messages.LogFailureVerbose>((m) => {
                StringBuilder output = new StringBuilder();
                output.AppendLine(failureString(m.Notification) + $"::{Sender}");
                foreach (var pair in m.FailureNotifications)
                {
                    output.Append($"|'{pair.V1.ToShortString()} crashed' - {pair.V2.ToShortString()} said.|\n");
                }
                Console.WriteLine(output);
            });
            Receive <Messages.LogFailure>((m) => {
                Console.WriteLine(failureString(m.Notification) + $"::{Sender}");
            });
            Receive <Messages.LogMessage>((m) => {
                Console.WriteLine(m.Message);
            });
        }