IDEA-82358 IDEA occasionally locks up temporarly for a half until 2 minutes [rev=Sergey.Vasiliev] (cherry picked from commit 6e33b56)

This commit is contained in:
Nikolay Matveev
2012-03-21 17:17:52 +04:00
parent 64df835f6c
commit 9764aff7b1
5 changed files with 85 additions and 33 deletions
@@ -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<UsageDescriptor> getProjectUsages(@NotNull final Project project) {
public Set<UsageDescriptor> getProjectUsages(@NotNull final Project project) throws CollectUsagesException {
final Set<FileType> usedFileTypes = new HashSet<FileType>();
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<Void>() {
@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<Void>() {
@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<FileType, UsageDescriptor>() {
@NotNull
@Override
@@ -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<UsageDescriptor> projectUsages = getProjectUsages(project);
persistProjectUsages(project, projectUsages);
}
catch (CollectUsagesException e) {
LOG.info(e);
}
}
public void persistProjectUsages(@NotNull Project project, @NotNull Set<UsageDescriptor> usages) {
@@ -69,14 +79,15 @@ public abstract class AbstractApplicationUsagesCollector extends UsagesCollector
}
@NotNull
public Set<UsageDescriptor> getUsages(@Nullable Project project) {
public Set<UsageDescriptor> getUsages(@Nullable Project project) throws CollectUsagesException {
if (project != null) {
persistProjectUsages(project, getProjectUsages(project));
final Set<UsageDescriptor> projectUsages = getProjectUsages(project);
persistProjectUsages(project, projectUsages);
}
return getApplicationUsages();
}
@NotNull
public abstract Set<UsageDescriptor> getProjectUsages(@NotNull Project project);
public abstract Set<UsageDescriptor> getProjectUsages(@NotNull Project project) throws CollectUsagesException;
}
@@ -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);
}
}
@@ -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.<String>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<UsageDescriptor> usages = usagesCollector.getUsages(project);
usageDescriptors.put(groupDescriptor, usages);
}
catch (CollectUsagesException e) {
LOG.info(e);
}
}
}
@@ -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<UsagesCollector> EP_NAME = ExtensionPointName.create("com.intellij.statistics.usagesCollector");
public abstract @NotNull Set<UsageDescriptor> getUsages(@Nullable Project project);
public abstract @NotNull Set<UsageDescriptor> getUsages(@Nullable Project project) throws CollectUsagesException;
public abstract @NotNull GroupDescriptor getGroupId();
}