Skip to content

add removeSubscriber method in MessageBusManager #991

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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 @@ -43,19 +43,22 @@ final class MessageBus {


private final Project _project;
private final Map<Object/*subscriber*/, Map<Topic<?>, Object/*handler*/>> _subscribers;
private final Map<Topic<?>, Object/*handler*/> _publisher;
private final ConcurrentHashMap<Object/*subscriber*/, Map<Topic<?>, Object/*handler*/>> _subscribers;
private final ConcurrentHashMap<Topic<?>, Object/*handler*/> _publisher;


MessageBus(@NotNull final Project project) {
_project = project;
_subscribers = new HashMap<>();
_publisher = new HashMap<>();
_subscribers = new ConcurrentHashMap<>();
_publisher = new ConcurrentHashMap<>();
}

public void remove(Object subscriber) {
_subscribers.remove(subscriber);
}

public <L> void subscribe(@NotNull final Object subscriber, @NotNull final Topic<L> topic, @NotNull final L handler) {
Map<Topic<?>, Object/*handler*/> handlerByTopic = _subscribers.computeIfAbsent(subscriber, k -> new HashMap<>());
Map<Topic<?>, Object/*handler*/> handlerByTopic = _subscribers.computeIfAbsent(subscriber, k -> new ConcurrentHashMap<>());
if (!handlerByTopic.containsKey(topic)) {
handlerByTopic.put(topic, handler);
} // else do nothing ; subscriber has already subscribed this topic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ private static MessageBus of(@NotNull final Project project) {
return ret;
}

public static void removeSubscriber(Project project, Object subscriber) {
of(project).remove(subscriber);
}

public static <L extends AnalysisStateListener> void subscribeAnalysisState(@NotNull final Project project, @NotNull final Object subscriber, @NotNull final L handler) {
subscribe(project, subscriber, AnalysisStartedListener.TOPIC, handler);
subscribe(project, subscriber, AnalysisAbortingListener.TOPIC, handler);
Expand Down Expand Up @@ -133,4 +137,4 @@ public static void dispose(@NotNull final Project project) {
EventDispatchThreadHelper.checkEDT();
_busByProject.remove(project);
}
}
}