From 9764aff7b148f9de33586409b1b3b287f668a95f Mon Sep 17 00:00:00 2001 From: Nikolay Matveev Date: Wed, 21 Mar 2012 17:16:51 +0400 Subject: [PATCH] IDEA-82358 IDEA occasionally locks up temporarly for a half until 2 minutes [rev=Sergey.Vasiliev] (cherry picked from commit 6e33b56) --- .../fileTypes/FileTypeUsagesCollector.java | 52 +++++++++++-------- .../AbstractApplicationUsagesCollector.java | 21 ++++++-- .../statistic/CollectUsagesException.java | 26 ++++++++++ .../statistic/StatisticsUploadAssistant.java | 13 ++++- .../internal/statistic/UsagesCollector.java | 6 +-- 5 files changed, 85 insertions(+), 33 deletions(-) create mode 100644 platform/platform-impl/src/com/intellij/internal/statistic/CollectUsagesException.java diff --git a/platform/lang-impl/src/com/intellij/openapi/fileTypes/FileTypeUsagesCollector.java b/platform/lang-impl/src/com/intellij/openapi/fileTypes/FileTypeUsagesCollector.java index a93b73fae882..8269d1d6e7e7 100644 --- a/platform/lang-impl/src/com/intellij/openapi/fileTypes/FileTypeUsagesCollector.java +++ b/platform/lang-impl/src/com/intellij/openapi/fileTypes/FileTypeUsagesCollector.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 JetBrains s.r.o. + * Copyright 2000-2012 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,7 @@ package com.intellij.openapi.fileTypes; import com.intellij.internal.statistic.AbstractApplicationUsagesCollector; +import com.intellij.internal.statistic.CollectUsagesException; import com.intellij.internal.statistic.beans.GroupDescriptor; import com.intellij.internal.statistic.beans.UsageDescriptor; import com.intellij.openapi.application.ApplicationManager; @@ -46,30 +47,35 @@ public class FileTypeUsagesCollector extends AbstractApplicationUsagesCollector @NotNull @Override - public Set getProjectUsages(@NotNull final Project project) { + public Set getProjectUsages(@NotNull final Project project) throws CollectUsagesException { final Set usedFileTypes = new HashSet(); - ApplicationManager.getApplication().runReadAction(new Runnable() { - @Override - public void run() { - if (!project.isDisposed()) { - final FileType[] registeredFileTypes = FileTypeManager.getInstance().getRegisteredFileTypes(); - for (final FileType fileType : registeredFileTypes) { - FileBasedIndex.getInstance().processValues( - FileTypeIndex.NAME, - fileType, - null, - new FileBasedIndex.ValueProcessor() { - @Override - public boolean process(VirtualFile file, Void value) { - usedFileTypes.add(fileType); - return false; - } - }, GlobalSearchScope.projectScope(project)); - } - usedFileTypes.add(UnknownFileType.INSTANCE); - } + final FileTypeManager fileTypeManager = FileTypeManager.getInstance(); + if (fileTypeManager == null) { + throw new CollectUsagesException("Cannot get instance of FileTypeManager"); + } + final FileType[] registeredFileTypes = fileTypeManager.getRegisteredFileTypes(); + for (final FileType fileType : registeredFileTypes) { + if (project.isDisposed()) { + throw new CollectUsagesException("Project is disposed"); } - }); + ApplicationManager.getApplication().runReadAction(new Runnable() { + @Override + public void run() { + FileBasedIndex.getInstance().processValues( + FileTypeIndex.NAME, + fileType, + null, + new FileBasedIndex.ValueProcessor() { + @Override + public boolean process(VirtualFile file, Void value) { + usedFileTypes.add(fileType); + return false; + } + }, GlobalSearchScope.projectScope(project)); + } + }); + } + usedFileTypes.add(UnknownFileType.INSTANCE); return ContainerUtil.map2Set(usedFileTypes, new NotNullFunction() { @NotNull @Override diff --git a/platform/platform-impl/src/com/intellij/internal/statistic/AbstractApplicationUsagesCollector.java b/platform/platform-impl/src/com/intellij/internal/statistic/AbstractApplicationUsagesCollector.java index 97a9340edf99..6b994c098505 100644 --- a/platform/platform-impl/src/com/intellij/internal/statistic/AbstractApplicationUsagesCollector.java +++ b/platform/platform-impl/src/com/intellij/internal/statistic/AbstractApplicationUsagesCollector.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2010 JetBrains s.r.o. + * Copyright 2000-2012 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,6 +18,7 @@ package com.intellij.internal.statistic; import com.intellij.internal.statistic.beans.UsageDescriptor; import com.intellij.internal.statistic.persistence.ApplicationStatisticsPersistence; import com.intellij.internal.statistic.persistence.ApplicationStatisticsPersistenceComponent; +import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; import com.intellij.util.Function; import com.intellij.util.containers.ContainerUtil; @@ -29,8 +30,17 @@ import java.util.Map; import java.util.Set; public abstract class AbstractApplicationUsagesCollector extends UsagesCollector { + + private static final Logger LOG = Logger.getInstance("#com.intellij.internal.statistic.AbstractApplicationUsagesCollector"); + public void persistProjectUsages(@NotNull Project project) { - persistProjectUsages(project, getProjectUsages(project)); + try { + final Set projectUsages = getProjectUsages(project); + persistProjectUsages(project, projectUsages); + } + catch (CollectUsagesException e) { + LOG.info(e); + } } public void persistProjectUsages(@NotNull Project project, @NotNull Set usages) { @@ -69,14 +79,15 @@ public abstract class AbstractApplicationUsagesCollector extends UsagesCollector } @NotNull - public Set getUsages(@Nullable Project project) { + public Set getUsages(@Nullable Project project) throws CollectUsagesException { if (project != null) { - persistProjectUsages(project, getProjectUsages(project)); + final Set projectUsages = getProjectUsages(project); + persistProjectUsages(project, projectUsages); } return getApplicationUsages(); } @NotNull - public abstract Set getProjectUsages(@NotNull Project project); + public abstract Set getProjectUsages(@NotNull Project project) throws CollectUsagesException; } diff --git a/platform/platform-impl/src/com/intellij/internal/statistic/CollectUsagesException.java b/platform/platform-impl/src/com/intellij/internal/statistic/CollectUsagesException.java new file mode 100644 index 000000000000..7c5d473759c5 --- /dev/null +++ b/platform/platform-impl/src/com/intellij/internal/statistic/CollectUsagesException.java @@ -0,0 +1,26 @@ +/* + * Copyright 2000-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.internal.statistic; + +/** + * @author Nikolay Matveev + */ +public class CollectUsagesException extends Exception { + + public CollectUsagesException(String message) { + super(message); + } +} diff --git a/platform/platform-impl/src/com/intellij/internal/statistic/StatisticsUploadAssistant.java b/platform/platform-impl/src/com/intellij/internal/statistic/StatisticsUploadAssistant.java index 5b11661f8c11..c4436275532a 100644 --- a/platform/platform-impl/src/com/intellij/internal/statistic/StatisticsUploadAssistant.java +++ b/platform/platform-impl/src/com/intellij/internal/statistic/StatisticsUploadAssistant.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2010 JetBrains s.r.o. + * Copyright 2000-2012 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,6 +24,7 @@ import com.intellij.internal.statistic.beans.UsageDescriptor; import com.intellij.internal.statistic.persistence.SentUsagesPersistence; import com.intellij.internal.statistic.persistence.UsageStatisticsPersistenceComponent; import com.intellij.openapi.application.ex.ApplicationManagerEx; +import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.project.Project; import com.intellij.openapi.project.ProjectManager; @@ -39,6 +40,8 @@ import java.util.*; public class StatisticsUploadAssistant { + private static final Logger LOG = Logger.getInstance("#com.intellij.internal.statistic.StatisticsUploadAssistant"); + public String getData() { return getData(Collections.emptySet()); } @@ -233,7 +236,13 @@ public class StatisticsUploadAssistant { final GroupDescriptor groupDescriptor = usagesCollector.getGroupId(); if (!disabledGroups.contains(groupDescriptor.getId())) { - usageDescriptors.put(groupDescriptor, usagesCollector.getUsages(project)); + try { + final Set usages = usagesCollector.getUsages(project); + usageDescriptors.put(groupDescriptor, usages); + } + catch (CollectUsagesException e) { + LOG.info(e); + } } } diff --git a/platform/platform-impl/src/com/intellij/internal/statistic/UsagesCollector.java b/platform/platform-impl/src/com/intellij/internal/statistic/UsagesCollector.java index 46e03564bf5d..e0c03c33625f 100644 --- a/platform/platform-impl/src/com/intellij/internal/statistic/UsagesCollector.java +++ b/platform/platform-impl/src/com/intellij/internal/statistic/UsagesCollector.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2010 JetBrains s.r.o. + * Copyright 2000-2012 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,9 +16,9 @@ package com.intellij.internal.statistic; import com.intellij.internal.statistic.beans.GroupDescriptor; +import com.intellij.internal.statistic.beans.UsageDescriptor; import com.intellij.openapi.extensions.ExtensionPointName; import com.intellij.openapi.project.Project; -import com.intellij.internal.statistic.beans.UsageDescriptor; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -27,7 +27,7 @@ import java.util.Set; public abstract class UsagesCollector { public static ExtensionPointName EP_NAME = ExtensionPointName.create("com.intellij.statistics.usagesCollector"); - public abstract @NotNull Set getUsages(@Nullable Project project); + public abstract @NotNull Set getUsages(@Nullable Project project) throws CollectUsagesException; public abstract @NotNull GroupDescriptor getGroupId(); }