Exemplo n.º 1
0
        public void Execute(MessageStrategyExecuteArg <IMessage> obj)
        {
            if (!(obj.Message is ProposalDecision))
            {
                throw new MessageStrategyException("This strategy shouldn't be invoked with this message type");
            }

            ProposalDecision decision = obj.Message as ProposalDecision;
            ReplicaState     state    = obj.RoleState as ReplicaState;

            storeDecision(decision, state);
            if (proposalHasBeenApproved(decision, state))
            {
                ClientRequest clientRequest = cleanProposal(decision, state);
                OnDecisionApproved?.Invoke(this, clientRequest);
            }
            else
            {
                ClientRequest clientRequest = null;
                if (replicaIsProposalEmitter(decision, state))
                {
                    temporaryRemoveClientPendingResponseUntilNextRetry(decision, state);
                    clientRequest = cleanProposal(decision, state);
                }

                OnDecisionRejected?.Invoke(this, clientRequest);
            }
        }
Exemplo n.º 2
0
        public void Execute(MessageStrategyExecuteArg <IMessage> obj)
        {
            checkInvalidParameter(obj);

            SolicitateBallotRequest message = obj.Message as SolicitateBallotRequest;
            AcceptorState           state   = obj.RoleState as AcceptorState;

            updateBallotNumberIfNeeded(message, state);
            sendSolicitateBallotResponse(message.MessageSender, state);
        }
        public void Execute(MessageStrategyExecuteArg <IMessage> obj)
        {
            if (!(obj.Message is SolicitateBallotRequest))
            {
                throw new MessageStrategyException("This strategy shouldn't be invoked with this message type");
            }

            SolicitateBallotRequest request = obj.Message as SolicitateBallotRequest;

            sendRequestToAcceptors(obj.RoleState as LeaderState, request);
        }
Exemplo n.º 4
0
        private void checkInvalidParameter(MessageStrategyExecuteArg <IMessage> obj)
        {
            if (!(obj.Message is VoteRequest))
            {
                throw new MessageStrategyException("This strategy shouldn't be invoked with this message type");
            }

            if (!(obj.RoleState is AcceptorState))
            {
                throw new MessageStrategyException("This strategy should only be executed by an acceptor");
            }
        }
Exemplo n.º 5
0
        public void Execute(MessageStrategyExecuteArg <IMessage> obj)
        {
            if (!(obj.Message is ClientRequest))
            {
                throw new MessageStrategyException("This strategy shouldn't be invoked with this message type");
            }

            ClientRequest request = obj.Message as ClientRequest;
            ReplicaState  state   = obj.RoleState as ReplicaState;

            sendProposalsToLeaders(request, state);
        }
Exemplo n.º 6
0
        public void Execute(MessageStrategyExecuteArg <IMessage> obj)
        {
            if (!(obj.Message is ProposalRequest))
            {
                throw new MessageStrategyException("This strategy shouldn't be invoked with this message type");
            }
            ProposalRequest request = obj.Message as ProposalRequest;
            LeaderState     state   = obj.RoleState as LeaderState;;

            storeProposal(request, state);
            OnProposalReceived?.Invoke(this, EventArgs.Empty);
        }
Exemplo n.º 7
0
        public void Execute(MessageStrategyExecuteArg <IMessage> obj)
        {
            checkInvalidParameter(obj);
            VoteRequest   request = (obj.Message as VoteRequest);
            AcceptorState state   = obj.RoleState as AcceptorState;

            if (ballotIsValid(request.BallotNumber, state.BallotNumber))
            {
                acceptVote(request, state);
            }
            else
            {
                rejectVote(request, state);
            }
        }
Exemplo n.º 8
0
        public void Execute(MessageStrategyExecuteArg <IMessage> obj)
        {
            if (!(obj.Message is SolicitateBallotResponse))
            {
                throw new MessageStrategyException("This strategy shouldn't be invoked with this message type");
            }

            SolicitateBallotResponse response = obj.Message as SolicitateBallotResponse;
            LeaderState state = obj.RoleState as LeaderState;

            if (ballotIsApproved(state.BallotNumber, response.BallotNumber))
            {
                onBallotApproved(state, response);
            }
            else if (higherBallotHasBeenApproved(state.BallotNumber, response.BallotNumber))
            {
                onBallotRejected(state, response);
            }
        }
        public void Execute(MessageStrategyExecuteArg <IMessage> obj)
        {
            if (!(obj.Message is VoteResponse))
            {
                throw new MessageStrategyException("This strategy shouldn't be invoked with this message type");
            }

            VoteResponse response = obj.Message as VoteResponse;
            LeaderState  state    = obj.RoleState as LeaderState;

            state.VoteRequestPendingDecisionPerSlot[response.SlotNumber].Remove(response.MessageSender);

            if (isBallotValid(response.BallotNumber, state.BallotNumber))
            {
                if (isElected(response, state))
                {
                    OnApprovalElected?.Invoke(this, response);
                }
            }
            else
            {
                OnApprovalPreempted?.Invoke(this, EventArgs.Empty);
            }
        }