Skip to content

Commit

Permalink
Add more adequate naming for subscription topics
Browse files Browse the repository at this point in the history
  • Loading branch information
rchomczyk committed Nov 14, 2024
1 parent 49f3a83 commit 05a07ef
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
16 changes: 8 additions & 8 deletions dew-common/src/dev/shiza/dew/event/EventBusImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,18 @@ public void subscribe(final Subscriber subscriber) {
}

@Override
public void publish(final Event event, final String... targets) {
public void publish(final Event event, final String... topics) {
final Set<Subscription> subscriptions =
subscriptionFacade.getSubscriptionsByEventType(event.getClass());
for (final Subscription subscription : subscriptions) {
notifySubscription(subscription, event, targets);
notifySubscription(subscription, event, topics);
}
}

private void notifySubscription(
final Subscription subscription, final Event event, final String[] targets) {
final Subscription subscription, final Event event, final String[] topics) {
final Subscriber subscriber = subscription.subscriber();
if (hasSpecifiedTarget(targets) && isExcludedSubscription(subscriber, targets)) {
if (hasSpecifiedTopic(topics) && isExcludedSubscription(subscriber, topics)) {
return;
}

Expand All @@ -67,11 +67,11 @@ private void notifySubscribedMethods(
}
}

private boolean hasSpecifiedTarget(final String[] targets) {
return targets.length > 0;
private boolean hasSpecifiedTopic(final String[] topics) {
return topics.length > 0;
}

private boolean isExcludedSubscription(final Subscriber subscriber, final String[] targets) {
return Arrays.stream(targets).noneMatch(identity -> subscriber.identity().equals(identity));
private boolean isExcludedSubscription(final Subscriber subscriber, final String[] topics) {
return Arrays.stream(topics).noneMatch(topic -> subscriber.topic().equals(topic));
}
}
2 changes: 1 addition & 1 deletion dew-common/src/dev/shiza/dew/subscription/Subscriber.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public interface Subscriber {

default String identity() {
default String topic() {
return null;
}
}

0 comments on commit 05a07ef

Please sign in to comment.