From d61b79bfac241c7c4810be0064493029dc2bf0cf Mon Sep 17 00:00:00 2001 From: Ivan Chirkov Date: Mon, 2 Feb 2015 03:35:08 +0100 Subject: [PATCH] Do not send statistics and persist usage information at the same time --- ...RemotelyConfigurableStatisticsService.java | 39 ++++++++++--------- ...icationStatisticsPersistenceComponent.java | 24 +++++++----- 2 files changed, 36 insertions(+), 27 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/internal/statistic/connect/RemotelyConfigurableStatisticsService.java b/platform/platform-impl/src/com/intellij/internal/statistic/connect/RemotelyConfigurableStatisticsService.java index ed71d9e109d7..c9e2fa207b6a 100755 --- a/platform/platform-impl/src/com/intellij/internal/statistic/connect/RemotelyConfigurableStatisticsService.java +++ b/platform/platform-impl/src/com/intellij/internal/statistic/connect/RemotelyConfigurableStatisticsService.java @@ -1,6 +1,7 @@ package com.intellij.internal.statistic.connect; import com.intellij.internal.statistic.StatisticsUploadAssistant; +import com.intellij.internal.statistic.persistence.ApplicationStatisticsPersistenceComponent; import com.intellij.notification.Notification; import com.intellij.notification.NotificationListener; import com.intellij.notification.NotificationType; @@ -28,30 +29,32 @@ public class RemotelyConfigurableStatisticsService implements StatisticsService @Override public StatisticsResult send() { - final String serviceUrl = myConnectionService.getServiceUrl(); + synchronized (ApplicationStatisticsPersistenceComponent.class) { + final String serviceUrl = myConnectionService.getServiceUrl(); - if (serviceUrl == null) { - return new StatisticsResult(StatisticsResult.ResultCode.ERROR_IN_CONFIG, "ERROR"); - } + if (serviceUrl == null) { + return new StatisticsResult(StatisticsResult.ResultCode.ERROR_IN_CONFIG, "ERROR"); + } - if (!myConnectionService.isTransmissionPermitted()) { - return new StatisticsResult(StatisticsResult.ResultCode.NOT_PERMITTED_SERVER, "NOT_PERMITTED"); - } + if (!myConnectionService.isTransmissionPermitted()) { + return new StatisticsResult(StatisticsResult.ResultCode.NOT_PERMITTED_SERVER, "NOT_PERMITTED"); + } - String content = myAssistant.getData(myConnectionService.getDisabledGroups()); + String content = myAssistant.getData(myConnectionService.getDisabledGroups()); - if (StringUtil.isEmptyOrSpaces(content)) { - return new StatisticsResult(StatisticsResult.ResultCode.NOTHING_TO_SEND, "NOTHING_TO_SEND"); - } + if (StringUtil.isEmptyOrSpaces(content)) { + return new StatisticsResult(StatisticsResult.ResultCode.NOTHING_TO_SEND, "NOTHING_TO_SEND"); + } - try { - sender.send(serviceUrl, content); - StatisticsUploadAssistant.updateSentTime(); + try { + sender.send(serviceUrl, content); + StatisticsUploadAssistant.updateSentTime(); - return new StatisticsResult(StatisticsResult.ResultCode.SEND, content); - } - catch (Exception e) { - return new StatisticsResult(StatisticsResult.ResultCode.SENT_WITH_ERRORS, e.getMessage() != null ? e.getMessage() : "NPE"); + return new StatisticsResult(StatisticsResult.ResultCode.SEND, content); + } + catch (Exception e) { + return new StatisticsResult(StatisticsResult.ResultCode.SENT_WITH_ERRORS, e.getMessage() != null ? e.getMessage() : "NPE"); + } } } diff --git a/platform/platform-impl/src/com/intellij/internal/statistic/persistence/ApplicationStatisticsPersistenceComponent.java b/platform/platform-impl/src/com/intellij/internal/statistic/persistence/ApplicationStatisticsPersistenceComponent.java index 65386d5afcb5..01283eb85ed5 100644 --- a/platform/platform-impl/src/com/intellij/internal/statistic/persistence/ApplicationStatisticsPersistenceComponent.java +++ b/platform/platform-impl/src/com/intellij/internal/statistic/persistence/ApplicationStatisticsPersistenceComponent.java @@ -173,9 +173,7 @@ public class ApplicationStatisticsPersistenceComponent extends ApplicationStatis ApplicationManager.getApplication().getMessageBus().connect().subscribe(AppLifecycleListener.TOPIC, new AppLifecycleListener.Adapter() { @Override public void appClosing() { - for (Project project : ProjectManager.getInstance().getOpenProjects()) { - doPersistProjectUsages(project); - } + persistOpenedProjects(); persistOnClosing = false; } }); @@ -190,14 +188,22 @@ public class ApplicationStatisticsPersistenceComponent extends ApplicationStatis }); } - private static void doPersistProjectUsages(@NotNull Project project) { - if (!project.isInitialized() || DumbService.isDumb(project)) { - return; + private static void persistOpenedProjects() { + for (Project project : ProjectManager.getInstance().getOpenProjects()) { + doPersistProjectUsages(project); } + } - for (UsagesCollector usagesCollector : Extensions.getExtensions(UsagesCollector.EP_NAME)) { - if (usagesCollector instanceof AbstractApplicationUsagesCollector) { - ((AbstractApplicationUsagesCollector)usagesCollector).persistProjectUsages(project); + private static void doPersistProjectUsages(@NotNull Project project) { + synchronized (ApplicationStatisticsPersistenceComponent.class) { + if (!project.isInitialized() || DumbService.isDumb(project)) { + return; + } + + for (UsagesCollector usagesCollector : Extensions.getExtensions(UsagesCollector.EP_NAME)) { + if (usagesCollector instanceof AbstractApplicationUsagesCollector) { + ((AbstractApplicationUsagesCollector)usagesCollector).persistProjectUsages(project); + } } } }