view src/main/java/christie/test/topology/paxos/Proposal.java @ 198:dd3c0ba6a0a6

fix topology manager
author akahori
date Sat, 09 Mar 2019 21:53:37 +0900
parents 9b0a7f8dde81
children
line wrap: on
line source

package christie.test.topology.paxos;

import org.msgpack.annotation.Message;

@Message
public class Proposal {
    private String proposerName = "";
    private String acceptorName = "";
    private int acceptorNum = 0;
    private int nodeNum = 0;
    private int number = 0;
    private int value = -1; // not selected value
    private int id = 0;
    private int round = 0;
    private boolean accepted = false;

    public Proposal(){

    }

    public Proposal(String proposerName, int nodeNum, int value, int id, int acceptorNum){
        this.proposerName = proposerName;
        this.nodeNum = nodeNum;
        this.value = value;
        this.id = id;
        this.acceptorNum = acceptorNum;
    }

    public void setValue(int value){
        this.value = value;
    }

    public int getValue(){ return this.value; }

    public int getNumber(){
        return this.number;
    }

    public int incrementRound(){
        this.round += 1;
        return this.round;
    }

    public int incrementNumber() {
        this.number = incrementRound() * nodeNum + id;
        return this.number;
    }

    public int getAcceptorNum(){
        return this.acceptorNum;
    }

    public String getProposerName() {
        return proposerName;
    }

    public boolean isAccepted() {
        return accepted;
    }

    public void setAccepted(boolean accepted) {
        this.accepted = accepted;
    }

    public String getAcceptorName() {
        return acceptorName;
    }

    public void setAcceptorName(String acceptorName) {
        this.acceptorName = acceptorName;
    }

    public String toString() {
        return "Proposal : number = " + number + ",  " +
                           "value = " + value;
    }

    public boolean equalNumberAndValue(Proposal proposal){
        if(proposal.getNumber() == this.number &&
           proposal.getValue()  == this.value)
            return true;

        return false;
    }



}