Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only load the telementry service as a background task if used #3085

Merged
merged 2 commits into from
Aug 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/main/java/org/jabref/Globals.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.jabref;

import java.awt.Toolkit;
import java.util.Optional;
import java.util.UUID;

import org.jabref.collab.FileUpdateMonitor;
Expand Down Expand Up @@ -73,12 +74,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()) {
getTelemetryClient().ifPresent(client -> client.trackSessionState(SessionState.End));
getTelemetryClient().ifPresent(client -> client.flush());
Copy link
Member

@Siedlerchr Siedlerchr Aug 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you have only a single method call with zero or one parameter, you can do some syntactic sugar by doing ifPresent(TelementryClient::flush)
just for information ;)
https://docs.oracle.com/javase/tutorial/java/javaOO/methodreferences.html

}
}

private static void startTelemetryClient() {
Expand Down Expand Up @@ -115,7 +120,7 @@ public static void stopBackgroundTasks() {
stopTelemetryClient();
}

public static TelemetryClient getTelemetryClient() {
return telemetryClient;
public static Optional<TelemetryClient> getTelemetryClient() {
return Optional.ofNullable(telemetryClient);
}
}
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/JabRefDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ public <T extends JabRefDialog> JabRefDialog(Window owner, String title, Class<T
}

private <T extends JabRefDialog> void trackDialogOpening(Class<T> clazz) {
Globals.getTelemetryClient().trackPageView(clazz.getName());
Globals.getTelemetryClient().ifPresent(client -> client.trackPageView(clazz.getName()));
}
}
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -1584,7 +1584,7 @@ private void trackOpenNewDatabase(BasePanel basePanel) {
Map<String, Double> measurements = new HashMap<>();
measurements.put("NumberOfEntries", (double)basePanel.getDatabaseContext().getDatabase().getEntryCount());

Globals.getTelemetryClient().trackEvent("OpenNewDatabase", properties, measurements);
Globals.getTelemetryClient().ifPresent(client -> client.trackEvent("OpenNewDatabase", properties, measurements));
}

public BasePanel addTab(BibDatabaseContext databaseContext, boolean raisePanel) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ public void append(LogEvent rawEvent) {
}
telemetry.getContext().getProperties().putAll(event.getCustomParameters());

Globals.getTelemetryClient().track(telemetry);
Globals.getTelemetryClient().ifPresent(client -> client.track(telemetry));
}
}