Search in sources :

Example 1 with QueueProcessor

use of com.intellij.util.concurrency.QueueProcessor in project intellij-plugins by JetBrains.

the class DesignerApplicationManager method attachProjectAndModuleListeners.

void attachProjectAndModuleListeners(Disposable parentDisposable) {
    MessageBusConnection connection = ApplicationManager.getApplication().getMessageBus().connect(parentDisposable);
    connection.subscribe(ProjectManager.TOPIC, new ProjectManagerListener() {

        @Override
        public void projectClosed(Project project) {
            if (isApplicationClosed()) {
                return;
            }
            Client client = Client.getInstance();
            if (client.getRegisteredProjects().contains(project)) {
                client.closeProject(project);
            }
        }
    });
    // unregistered module is more complicated - we cannot just remove all document factories which belong to project as in case of close project
    // we must remove all document factories belong to module and all dependents (dependent may be from another module, so, we process moduleRemoved synchronous
    // one by one)
    connection.subscribe(ProjectTopics.MODULES, new ModuleListener() {

        @Override
        public void moduleRemoved(@NotNull Project project, @NotNull Module module) {
            Client client = Client.getInstance();
            if (!client.isModuleRegistered(module)) {
                return;
            }
            if (unregisterTaskQueueProcessor == null) {
                unregisterTaskQueueProcessor = new QueueProcessor<>(module1 -> {
                    boolean hasError = true;
                    final ActionCallback callback;
                    initialRenderQueue.suspend();
                    try {
                        callback = Client.getInstance().unregisterModule(module1);
                        hasError = false;
                    } finally {
                        if (hasError) {
                            initialRenderQueue.resume();
                        }
                    }
                    callback.doWhenProcessed(() -> initialRenderQueue.resume());
                });
            }
            unregisterTaskQueueProcessor.add(module);
        }
    });
}
Also used : Project(com.intellij.openapi.project.Project) MessageBusConnection(com.intellij.util.messages.MessageBusConnection) ProjectManagerListener(com.intellij.openapi.project.ProjectManagerListener) ModuleListener(com.intellij.openapi.project.ModuleListener) QueueProcessor(com.intellij.util.concurrency.QueueProcessor) ActionCallback(com.intellij.openapi.util.ActionCallback) Module(com.intellij.openapi.module.Module)

Aggregations

Module (com.intellij.openapi.module.Module)1 ModuleListener (com.intellij.openapi.project.ModuleListener)1 Project (com.intellij.openapi.project.Project)1 ProjectManagerListener (com.intellij.openapi.project.ProjectManagerListener)1 ActionCallback (com.intellij.openapi.util.ActionCallback)1 QueueProcessor (com.intellij.util.concurrency.QueueProcessor)1 MessageBusConnection (com.intellij.util.messages.MessageBusConnection)1