Do not send statistics and persist usage information at the same time

This commit is contained in:
Ivan Chirkov
2015-02-02 03:35:08 +01:00
parent fe1d47479b
commit d61b79bfac
2 changed files with 36 additions and 27 deletions
@@ -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");
}
}
}
@@ -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);
}
}
}
}