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

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

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

import org.jgroups.Address;
import org.jgroups.Header;
import org.jgroups.util.Util;

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

/**
 * Used by {@link org.jgroups.protocols.raft.ELECTION} to send heartbeats. Contrary to the RAFT paper, heartbeats are
 * not emulated with AppendEntriesRequests
 * @author Bela Ban
 * @since  0.1
 */
public class HeartbeatRequest extends RaftHeader {
    protected Address leader;

    public HeartbeatRequest() {}
    public HeartbeatRequest(int term, Address leader) {super(term); this.leader=leader;}

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

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

    public int serializedSize() {
        return super.serializedSize() + Util.size(leader);
    }

    public void writeTo(DataOutput out) throws Exception {
        super.writeTo(out);
        Util.writeAddress(leader, out);
    }

    public void readFrom(DataInput in) throws Exception {
        super.readFrom(in);
        leader=Util.readAddress(in);
    }

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy