Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -102,19 +102,27 @@ private static List<Subscription> selectSubscriptionsWithHigherQoSForEachSession

@Override
public boolean add(Subscription sub) {
if (sub.hasShareName()) {
throw new IllegalArgumentException("Adding a shared subscription using the non-shared method.");
}
checkIsShared(sub, "Adding a shared subscription using the non-shared method.");
boolean notExistingSubscription = ctrie.addToTree(sub);
subscriptionsRepository.addNewSubscription(sub);
return notExistingSubscription;
}

@Override
public void addShared(Subscription sub) {
private static void checkIsShared(Subscription sub, String errorMessage) {
if (sub.hasShareName()) {
throw new IllegalArgumentException(errorMessage);
}
}

private static void checkIsNotShared(Subscription sub, String errorMessage) {
if (!sub.hasShareName()) {
throw new IllegalArgumentException("Adding a non-shared subscription using the shared method.");
throw new IllegalArgumentException(errorMessage);
}
}

@Override
public void addShared(Subscription sub) {
checkIsNotShared(sub, "Adding a non-shared subscription using the shared method.");
ctrie.addToTree(sub);
subscriptionsRepository.addNewSharedSubscription(sub);
List<Subscription> sharedSubscriptions = clientSharedSubscriptions.computeIfAbsent(sub.getClientId(), unused -> new ArrayList<>());
Expand All @@ -129,18 +137,14 @@ public void addShared(Subscription sub) {
*/
@Override
public void removeSubscription(Subscription sub) {
if (sub.hasShareName()) {
throw new IllegalArgumentException("Removing a shared subscription using the non-shared method.");
}
checkIsShared(sub, "Removing a shared subscription using the non-shared method.");
ctrie.removeFromTree(sub);
subscriptionsRepository.removeSubscription(sub);
}

@Override
public void removeSharedSubscription(Subscription subscription) {
if (!subscription.hasShareName()) {
throw new IllegalArgumentException("Removing a non-shared subscription using the shared method.");
}
checkIsNotShared(subscription, "Removing a non-shared subscription using the shared method.");
ctrie.removeFromTree(subscription);

subscriptionsRepository.removeSharedSubscription(subscription);
Expand Down