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

de.otto.synapse.subscription.Subscription Maven / Gradle / Ivy

Go to download

A library used at otto.de to implement Spring Boot based event-sourcing microservices.

There is a newer version: 0.33.1
Show newest version
package de.otto.synapse.subscription;

import java.util.Objects;
import java.util.Set;

import static com.google.common.collect.Sets.newConcurrentHashSet;

public class Subscription {
    private final String id;
    private final String channelName;
    private final String targetChannelName;
    private final Set subscribedEntities;

    public Subscription(final String id,
                        final String channelName,
                        final String targetChannelName) {
        this.id = id;
        this.channelName = channelName;
        this.targetChannelName = targetChannelName;
        this.subscribedEntities = newConcurrentHashSet();
    }

    public String getId() {
        return id;
    }

    public String getChannelName() {
        return channelName;
    }

    public String getTargetChannelName() {
        return targetChannelName;
    }

    public Set getSubscribedEntities() {
        return subscribedEntities;
    }

    public void subscribe(final Set subscribedEntities) {
        this.subscribedEntities.addAll(subscribedEntities);
    }

    public void unsubscribe(final Set unsubscribedEntities) {
        this.subscribedEntities.removeAll(unsubscribedEntities);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Subscription)) return false;
        Subscription that = (Subscription) o;
        return Objects.equals(id, that.id) &&
                Objects.equals(channelName, that.channelName) &&
                Objects.equals(targetChannelName, that.targetChannelName) &&
                Objects.equals(subscribedEntities, that.subscribedEntities);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, channelName, targetChannelName, subscribedEntities);
    }

    @Override
    public String toString() {
        return "Subscription{" +
                "id='" + id + '\'' +
                ", channelName='" + channelName + '\'' +
                ", targetChannelName='" + targetChannelName + '\'' +
                ", subscribedEntities=" + subscribedEntities +
                '}';
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy