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

com.sproutsocial.nsq.SubscriptionId Maven / Gradle / Ivy

There is a newer version: 1.4.8
Show newest version
package com.sproutsocial.nsq;

import java.util.Objects;
import java.util.concurrent.atomic.AtomicLong;

/**
 * Represents a unique subscription that's returned from a call to {@link Subscriber#subscribe}.
 * Can be passed to methods such as {@link Subscriber#unsubscribe} to remove a subscription.
 */
public class SubscriptionId {
    private final long id;

    protected SubscriptionId(final long id) {
        this.id = id;
    }

    static SubscriptionId fromCounter(final AtomicLong counter) {
        return new SubscriptionId(counter.getAndIncrement());
    }

    @Override
    public boolean equals(Object other) {
        if (other == this) { return true; }
        if (!(other instanceof SubscriptionId)) { return false; }
        SubscriptionId that = (SubscriptionId)other;
        return id == that.id;
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }

    @Override
    public String toString() {
        return "SubscriptionId { " + id + " }";
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy