Skip to content

Commit

Permalink
Get rid of duplicate check from subscription service, which breaks th…
Browse files Browse the repository at this point in the history
…e concept of shared subscribers
  • Loading branch information
shitzuu committed Aug 26, 2024
1 parent bb6d100 commit f326545
Showing 1 changed file with 0 additions and 10 deletions.
10 changes: 0 additions & 10 deletions dew-common/src/dev/shiza/dew/subscription/SubscriptionService.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,16 @@
final class SubscriptionService implements SubscriptionFacade {

private static final Lookup LOOKUP = MethodHandles.lookup();
private final Set<Class<? extends Subscriber>> subscribers;
private final Map<Class<? extends Event>, Set<Subscription>> subscriptionsByEventType;

SubscriptionService(
final Map<Class<? extends Event>, Set<Subscription>> subscriptionsByEventType) {
this.subscribers = new HashSet<>();
this.subscriptionsByEventType = subscriptionsByEventType;
}

@Override
public void subscribe(final Subscriber subscriber) throws SubscribingException {
final Class<? extends Subscriber> subscriberType = subscriber.getClass();
if (subscribers.contains(subscriberType)) {
throw new SubscribingException(
"Could not register subscription, because of duplicated call for %s subscriber."
.formatted(subscriberType.getSimpleName()));
}

final Map<Class<? extends Event>, Set<MethodHandle>> methodReferencesByEventType =
stream(subscriberType.getDeclaredMethods())
.filter(this::isSubscribedMethod)
Expand All @@ -49,8 +41,6 @@ public void subscribe(final Subscriber subscriber) throws SubscribingException {
.computeIfAbsent(entry.getKey(), key -> new HashSet<>())
.add(new Subscription(subscriber, entry.getValue()));
}

subscribers.add(subscriberType);
}

@Override
Expand Down

0 comments on commit f326545

Please sign in to comment.