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

org.jgroups.util.MergeId Maven / Gradle / Ivy

Go to download

This artifact provides a single jar that contains all classes required to use remote EJB and JMS, including all dependencies. It is intended for use by those not using maven, maven users should just import the EJB and JMS BOM's instead (shaded JAR's cause lots of problems with maven, as it is very easy to inadvertently end up with different versions on classes on the class path).

There is a newer version: 33.0.2.Final
Show newest version
package org.jgroups.util;

import org.jgroups.Address;
import org.jgroups.Global;

import java.io.DataInput;
import java.io.DataOutput;

/** ID to uniquely identify a merge
 * @author Bela Ban
 */
public class MergeId implements Streamable {
    private Address initiator; // must be non-null
    private int id;
    private static int LAST_ID=1;

    public MergeId() {}

    private MergeId(Address initiator, int id) {
        this.initiator=initiator;
        this.id=id;
    }

    public synchronized static MergeId create(Address addr) {
        if(addr == null)
            throw new IllegalArgumentException("initiator has to be non null");

        int id=LAST_ID++;
        return new MergeId(addr, id);
    }

    public boolean equals(Object obj) {
        return obj instanceof MergeId && initiator.equals(((MergeId)obj).initiator) && id == ((MergeId)obj).id;
    }

    public int hashCode() {
        return initiator.hashCode() + id;
    }

    public int size() {
        return Util.size(initiator) + Global.INT_SIZE;
    }

    public void writeTo(DataOutput out) throws Exception {
        Util.writeAddress(initiator, out);
        out.writeInt(id);
    }

    public void readFrom(DataInput in) throws Exception {
        initiator=Util.readAddress(in);
        id=in.readInt();
    }

    public String toString() {
        return initiator + "::" + id;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy