de.otto.synapse.subscription.Subscription Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of synapse-core Show documentation
Show all versions of synapse-core Show documentation
A library used at otto.de to implement Spring Boot based event-sourcing microservices.
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 +
'}';
}
}