From 15bd45fc76837261f640525a3493305c0783fab8 Mon Sep 17 00:00:00 2001 From: Christoph Hochreiner Date: Mon, 7 Aug 2017 20:46:20 +0200 Subject: [PATCH 1/2] Only load the telementry service as a background task, if it actually used to improve the startup duration #2966 --- src/main/java/org/jabref/Globals.java | 10 +++++++--- src/main/java/org/jabref/gui/JabRefDialog.java | 4 +++- src/main/java/org/jabref/gui/JabRefFrame.java | 4 +++- .../gui/logging/ApplicationInsightsAppender.java | 4 +++- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/jabref/Globals.java b/src/main/java/org/jabref/Globals.java index 5e719a57184..6f2eaf60132 100644 --- a/src/main/java/org/jabref/Globals.java +++ b/src/main/java/org/jabref/Globals.java @@ -73,12 +73,16 @@ public static void startBackgroundTasks() { Globals.fileUpdateMonitor = new FileUpdateMonitor(); JabRefExecutorService.INSTANCE.executeInterruptableTask(Globals.fileUpdateMonitor, "FileUpdateMonitor"); - startTelemetryClient(); + if (Globals.prefs.shouldCollectTelemetry()) { + startTelemetryClient(); + } } private static void stopTelemetryClient() { - telemetryClient.trackSessionState(SessionState.End); - telemetryClient.flush(); + if (Globals.prefs.shouldCollectTelemetry()) { + telemetryClient.trackSessionState(SessionState.End); + telemetryClient.flush(); + } } private static void startTelemetryClient() { diff --git a/src/main/java/org/jabref/gui/JabRefDialog.java b/src/main/java/org/jabref/gui/JabRefDialog.java index 9bce43511d7..718f69439ae 100644 --- a/src/main/java/org/jabref/gui/JabRefDialog.java +++ b/src/main/java/org/jabref/gui/JabRefDialog.java @@ -54,6 +54,8 @@ public JabRefDialog(Window owner, String title, Class void trackDialogOpening(Class clazz) { - Globals.getTelemetryClient().trackPageView(clazz.getName()); + if (Globals.getTelemetryClient()!=null) { + Globals.getTelemetryClient().trackPageView(clazz.getName()); + } } } diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java index 1b25660beb2..c01c6f153b1 100644 --- a/src/main/java/org/jabref/gui/JabRefFrame.java +++ b/src/main/java/org/jabref/gui/JabRefFrame.java @@ -1584,7 +1584,9 @@ private void trackOpenNewDatabase(BasePanel basePanel) { Map measurements = new HashMap<>(); measurements.put("NumberOfEntries", (double)basePanel.getDatabaseContext().getDatabase().getEntryCount()); - Globals.getTelemetryClient().trackEvent("OpenNewDatabase", properties, measurements); + if (Globals.getTelemetryClient()!=null) { + Globals.getTelemetryClient().trackEvent("OpenNewDatabase", properties, measurements); + } } public BasePanel addTab(BibDatabaseContext databaseContext, boolean raisePanel) { diff --git a/src/main/java/org/jabref/gui/logging/ApplicationInsightsAppender.java b/src/main/java/org/jabref/gui/logging/ApplicationInsightsAppender.java index 4067f4a85c4..220bcde8059 100644 --- a/src/main/java/org/jabref/gui/logging/ApplicationInsightsAppender.java +++ b/src/main/java/org/jabref/gui/logging/ApplicationInsightsAppender.java @@ -48,6 +48,8 @@ public void append(LogEvent rawEvent) { } telemetry.getContext().getProperties().putAll(event.getCustomParameters()); - Globals.getTelemetryClient().track(telemetry); + if (Globals.getTelemetryClient()!=null) { + Globals.getTelemetryClient().track(telemetry); + } } } From 5e0aa2802aee894b2daae692a4ae082b596b466f Mon Sep 17 00:00:00 2001 From: Christoph Hochreiner Date: Mon, 7 Aug 2017 21:35:27 +0200 Subject: [PATCH 2/2] Make Telementry Client optional --- src/main/java/org/jabref/Globals.java | 9 +++++---- src/main/java/org/jabref/gui/JabRefDialog.java | 4 +--- src/main/java/org/jabref/gui/JabRefFrame.java | 4 +--- .../jabref/gui/logging/ApplicationInsightsAppender.java | 4 +--- 4 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/jabref/Globals.java b/src/main/java/org/jabref/Globals.java index 6f2eaf60132..27fa65c92a6 100644 --- a/src/main/java/org/jabref/Globals.java +++ b/src/main/java/org/jabref/Globals.java @@ -1,6 +1,7 @@ package org.jabref; import java.awt.Toolkit; +import java.util.Optional; import java.util.UUID; import org.jabref.collab.FileUpdateMonitor; @@ -80,8 +81,8 @@ public static void startBackgroundTasks() { private static void stopTelemetryClient() { if (Globals.prefs.shouldCollectTelemetry()) { - telemetryClient.trackSessionState(SessionState.End); - telemetryClient.flush(); + getTelemetryClient().ifPresent(client -> client.trackSessionState(SessionState.End)); + getTelemetryClient().ifPresent(client -> client.flush()); } } @@ -119,7 +120,7 @@ public static void stopBackgroundTasks() { stopTelemetryClient(); } - public static TelemetryClient getTelemetryClient() { - return telemetryClient; + public static Optional getTelemetryClient() { + return Optional.ofNullable(telemetryClient); } } diff --git a/src/main/java/org/jabref/gui/JabRefDialog.java b/src/main/java/org/jabref/gui/JabRefDialog.java index 718f69439ae..3a70de1a368 100644 --- a/src/main/java/org/jabref/gui/JabRefDialog.java +++ b/src/main/java/org/jabref/gui/JabRefDialog.java @@ -54,8 +54,6 @@ public JabRefDialog(Window owner, String title, Class void trackDialogOpening(Class clazz) { - if (Globals.getTelemetryClient()!=null) { - Globals.getTelemetryClient().trackPageView(clazz.getName()); - } + Globals.getTelemetryClient().ifPresent(client -> client.trackPageView(clazz.getName())); } } diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java index c01c6f153b1..92095b78852 100644 --- a/src/main/java/org/jabref/gui/JabRefFrame.java +++ b/src/main/java/org/jabref/gui/JabRefFrame.java @@ -1584,9 +1584,7 @@ private void trackOpenNewDatabase(BasePanel basePanel) { Map measurements = new HashMap<>(); measurements.put("NumberOfEntries", (double)basePanel.getDatabaseContext().getDatabase().getEntryCount()); - if (Globals.getTelemetryClient()!=null) { - Globals.getTelemetryClient().trackEvent("OpenNewDatabase", properties, measurements); - } + Globals.getTelemetryClient().ifPresent(client -> client.trackEvent("OpenNewDatabase", properties, measurements)); } public BasePanel addTab(BibDatabaseContext databaseContext, boolean raisePanel) { diff --git a/src/main/java/org/jabref/gui/logging/ApplicationInsightsAppender.java b/src/main/java/org/jabref/gui/logging/ApplicationInsightsAppender.java index 220bcde8059..2978bc187aa 100644 --- a/src/main/java/org/jabref/gui/logging/ApplicationInsightsAppender.java +++ b/src/main/java/org/jabref/gui/logging/ApplicationInsightsAppender.java @@ -48,8 +48,6 @@ public void append(LogEvent rawEvent) { } telemetry.getContext().getProperties().putAll(event.getCustomParameters()); - if (Globals.getTelemetryClient()!=null) { - Globals.getTelemetryClient().track(telemetry); - } + Globals.getTelemetryClient().ifPresent(client -> client.track(telemetry)); } }