public ServerActor(bool logging = false)
        {
            allActors          = new List <IActorRef>();
            olds               = new HashSet <IActorRef>();
            reliableSuccessors = new List <IActorRef>();
            predecessors       = new List <IActorRef>();

            faultyServers        = new HashSet <IActorRef>();
            failureNotifications = new HashSet <VertexPair>();
            trackingGraphs       = new Dictionary <IActorRef, TrackingGraph>();

            pendingMessages = new Queue <Messages.Abroadcast>();

            stageDeliveredMsgs = new HashSet <Messages.Rbroadcast>();
            stageReceivedFrom  = new HashSet <IActorRef>();
            stageMsg           = null;
            currentRound       = 0;

            stageNewMemberFlag = false;

            logger = null;
            if (logging)
            {
                logger = Context.ActorOf <LogActor>();
            }

            Receive <Messages.InitServer>(Initialize);
            ReceiveAny(_ => Stash.Stash());
        }
        public void NewMessageToBroadcast(Messages.Abroadcast m)
        {
            pendingMessages.Enqueue(m);

            if (stageMsg == null && pendingMessages.Count >= ACTOR_CAP)
            {
                SendMyMessage();
            }
        }
        public void NextStagePreparing()
        {
            // If Server does not deliver a message it will be regarded as failed.
            List <IActorRef> keysToDelete = new List <IActorRef>();

            foreach (var key in trackingGraphs.Keys)
            {
                if (!stageReceivedFrom.Contains(key))
                {
                    keysToDelete.Add(key);
                }
            }
            foreach (var key in keysToDelete)
            {
                trackingGraphs.Remove(key);
                reliableSuccessors.Remove(key);
                Context.Unwatch(key);
            }

            foreach (var err in failureNotifications)
            {
                if (trackingGraphs.ContainsKey(err.V1))
                {
                    foreach (var actor in reliableSuccessors)
                    {
                        actor.Tell(new Messages.IndirectFailureNotification(err.V1), err.V2);
                    }
                }
            }

            stageDeliveredMsgs.Clear();
            stageReceivedFrom.Clear();
            foreach (var pair in trackingGraphs)
            {
                if (pair.Key != Self)
                {
                    pair.Value.Reset();
                }
            }

            currentRound++;
            stageMsg = null;

            if (stageNewMemberFlag)
            {
                olds = new HashSet <IActorRef>(allActors);
                NewMemberReconfigure(newMember);
                SendLogMsg("New membership request.");
            }

            Stash.UnstashAll();
            if (pendingMessages.Count != 0 && pendingMessages.Count >= ACTOR_CAP)
            {
                SendMyMessage();
            }
        }
        public void SendMyMessage()
        {
            timer.Restart();

            Messages.Rbroadcast rbm;

            if (pendingMessages.Count == 0)
            {
                stageMsg = EMPTY_MSG;
                rbm      = new Messages.Rbroadcast(stageMsg, currentRound);
            }
            else
            {
                var list = new List <Messages.Abroadcast>();

                int c = ACTOR_CAP;
                if (pendingMessages.Count > ACTOR_CAP)
                {
                    c *= 3;
                }

                for (int i = 0; i < c && i < pendingMessages.Count; i++)
                {
                    list.Add(pendingMessages.Dequeue());
                }

                stageMsg = new Messages.Abroadcast(list.AsReadOnly());

                rbm = new Messages.Rbroadcast(stageMsg, currentRound);
            }

            foreach (var s in reliableSuccessors)
            {
                s.Tell(rbm);
            }
            stageDeliveredMsgs.Add(rbm);
            stageReceivedFrom.Add(Self);
            CheckTermination();
        }
Beispiel #5
0
 public Rbroadcast(Abroadcast m, int s)
 {
     Message = m;
     Round   = s;
     Id      = Guid.NewGuid();
 }