Esempio n. 1
0
        protected override bool Receive(object message) => message.Match()
        .With <ReadResult>(x =>
        {
            if (x.Envelope != null)
            {
                _result = _result?.Merge(x.Envelope) ?? x.Envelope;
            }

            Remaining = Remaining.Remove(Sender.Path.Address);
            var done  = DoneWhenRemainingSize;
            Log.Debug("read acks remaining: {0}, done when: {1}, current state: {2}", Remaining.Count, done, _result);
            if (Remaining.Count == done)
            {
                Reply(true);
            }
        })
        .With <SendToSecondary>(x =>
        {
            foreach (var n in SecondaryNodes)
            {
                Replica(n).Tell(_read);
            }
        })
        .With <ReceiveTimeout>(_ => Reply(false))
        .WasHandled;
Esempio n. 2
0
        void OnPlayerDied(Player p)
        {
            if (!Remaining.Remove(p) || !RoundInProgress)
            {
                return;
            }
            Player[] players = Remaining.Items;

            switch (players.Length)
            {
            case 1:
                Map.Message(players[0].ColoredName + " %Sis the winner!");
                EndRound(players[0]);
                break;

            case 2:
                Map.Message("Only 2 Players left:");
                Map.Message(players[0].ColoredName + " %Sand " + players[1].ColoredName);
                break;

            default:
                Map.Message(players.Length + " players left!");
                break;
            }
            UpdateAllStatus2();
        }
Esempio n. 3
0
        protected override bool Receive(object message) => message.Match()
        .With <ReadResult>(x =>
        {
            if (_result != null && x.Envelope != null)
            {
                _result = _result.Merge(x.Envelope.Data);
            }
            else if (_result == null && x.Envelope != null)
            {
                _result = x.Envelope;
            }
            else if (_result != null && x.Envelope == null)
            {
                _result = _result;
            }
            else
            {
                _result = null;
            }

            Remaining = Remaining.Remove(Sender.Path.Address);
            if (Remaining.Count == DoneWhenRemainingSize)
            {
                Reply(true);
            }
        })
        .With <SendToSecondary>(x =>
        {
            foreach (var n in PrimaryAndSecondaryNodes.Value.Item2)
            {
                Replica(n).Tell(_read);
            }
        })
        .With <ReceiveTimeout>(_ => Reply(false))
        .WasHandled;
Esempio n. 4
0
        protected override bool Receive(object message) => message.Match()
        .With <WriteAck>(x =>
        {
            Remaining = Remaining.Remove(SenderAddress);
            if (IsDone)
            {
                Reply(isTimeout: false);
            }
        })
        .With <WriteNack>(x =>
        {
            _gotNackFrom = _gotNackFrom.Add(SenderAddress);
            if (IsDone)
            {
                Reply(isTimeout: false);
            }
        })
        .With <DeltaNack>(_ =>
        {
            // ok, will be retried with full state
        })
        .With <UpdateSuccess>(x =>
        {
            _gotLocalStoreReply = true;
            if (IsDone)
            {
                Reply(isTimeout: false);
            }
        })
        .With <StoreFailure>(x =>
        {
            _gotLocalStoreReply = true;
            _gotNackFrom        = _gotNackFrom.Remove(_selfUniqueAddress.Address);
            if (IsDone)
            {
                Reply(isTimeout: false);
            }
        })
        .With <SendToSecondary>(x =>
        {
            // Deltas must be applied in order and we can't keep track of ordering of
            // simultaneous updates so there is a chance that the delta could not be applied.
            // Try again with the full state to the primary nodes that have not acked.
            if (_delta != null)
            {
                foreach (var address in PrimaryNodes.Intersect(Remaining))
                {
                    Replica(address).Tell(_write);
                }
            }

            foreach (var n in SecondaryNodes)
            {
                Replica(n).Tell(_write);
            }
        })
        .With <ReceiveTimeout>(x => Reply(isTimeout: true))
        .WasHandled;
Esempio n. 5
0
 private Receive WaitRepairAck(DataEnvelope envelope) => msg => msg.Match()
 .With <ReadRepairAck>(x =>
 {
     var reply = envelope.Data is DeletedData
             ? (object)new DataDeleted(_key, null)
             : new GetSuccess(_key, _req, envelope.Data);
     _replyTo.Tell(reply, Context.Parent);
     Context.Stop(Self);
 })
 .With <ReadResult>(x => Remaining = Remaining.Remove(Sender.Path.Address))
 .With <SendToSecondary>(_ => { })
 .With <ReceiveTimeout>(_ => { })
 .WasHandled;
Esempio n. 6
0
 protected override bool Receive(object message) => message.Match()
 .With <WriteAck>(x =>
 {
     Remaining = Remaining.Remove(SenderAddress);
     if (Remaining.Count == DoneWhenRemainingSize)
     {
         Reply(true);
     }
 })
 .With <SendToSecondary>(x =>
 {
     foreach (var n in PrimaryAndSecondaryNodes.Value.Item2)
     {
         Replica(n).Tell(_write);
     }
 })
 .With <ReceiveTimeout>(x => Reply(false))
 .WasHandled;
Esempio n. 7
0
 protected override bool Receive(object message) => message.Match()
 .With <WriteAck>(x =>
 {
     Remaining = Remaining.Remove(SenderAddress);
     if (IsDone)
     {
         Reply(isTimeout: false);
     }
 })
 .With <WriteNack>(x =>
 {
     _gotNackFrom = _gotNackFrom.Remove(SenderAddress);
     if (IsDone)
     {
         Reply(isTimeout: false);
     }
 })
 .With <UpdateSuccess>(x =>
 {
     _gotLocalStoreReply = true;
     if (IsDone)
     {
         Reply(isTimeout: false);
     }
 })
 .With <StoreFailure>(x =>
 {
     _gotLocalStoreReply = true;
     _gotNackFrom        = _gotNackFrom.Remove(Cluster.Cluster.Get(Context.System).SelfAddress);
     if (IsDone)
     {
         Reply(isTimeout: false);
     }
 })
 .With <SendToSecondary>(x =>
 {
     foreach (var n in SecondaryNodes)
     {
         Replica(n).Tell(_write);
     }
 })
 .With <ReceiveTimeout>(x => Reply(isTimeout: true))
 .WasHandled;
Esempio n. 8
0
        protected override bool Receive(object message)
        {
            switch (message)
            {
            case WriteAck _:
                Remaining = Remaining.Remove(SenderAddress);
                if (IsDone)
                {
                    Reply(isTimeout: false);
                }
                return(true);

            case WriteNack _:
                _gotNackFrom = _gotNackFrom.Add(SenderAddress);
                if (IsDone)
                {
                    Reply(isTimeout: false);
                }
                return(true);

            case DeltaNack _:
                Sender.Tell(_write);
                return(true);

            case UpdateSuccess _:
                _gotLocalStoreReply = true;
                if (IsDone)
                {
                    Reply(isTimeout: false);
                }
                return(true);

            case StoreFailure _:
                _gotLocalStoreReply = true;
                _gotNackFrom        = _gotNackFrom.Add(_selfUniqueAddress.Address);
                if (IsDone)
                {
                    Reply(isTimeout: false);
                }
                return(true);

            case SendToSecondary _:
                if (_delta != null)
                {
                    // Deltas must be applied in order and we can't keep track of ordering of
                    // simultaneous updates so there is a chance that the delta could not be applied.
                    // Try again with the full state to the primary nodes that have not acked.
                    foreach (var address in PrimaryNodes)
                    {
                        if (Remaining.Contains(address))
                        {
                            Replica(address).Tell(_write);
                        }
                    }
                }

                foreach (var n in SecondaryNodes)
                {
                    Replica(n).Tell(_write);
                }
                return(true);

            case ReceiveTimeout _:
                Reply(isTimeout: true);
                return(true);
            }

            return(false);
        }