All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jgroups.protocols.raft.VoteResponse Maven / Gradle / Ivy

There is a newer version: 1.0.14.Final
Show newest version
package org.jgroups.protocols.raft;

import org.jgroups.Header;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.function.Supplier;

/**
 * @author Bela Ban
 * @since  0.1
 */
public class VoteResponse extends RaftHeader {
    protected boolean result;

    public VoteResponse() {}
    public VoteResponse(int term, boolean result) {super(term); this.result=result;}

    public short getMagicId() {
        return ELECTION.VOTE_RSP;
    }

    public Supplier create() {
        return VoteResponse::new;
    }

    public boolean result() {return result;}

    public int serializedSize() {
        return super.serializedSize() + 1;
    }

    public void readFrom(DataInput in) throws IOException, ClassNotFoundException {
        super.readFrom(in);
    	result=in.readByte() == 1;
    }

    public void writeTo(DataOutput out) throws IOException {
        super.writeTo(out);
        out.writeByte(result ? 1 : 0);
    }

    public String toString() {
        return super.toString() + ", result=" + result;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy