-
Notifications
You must be signed in to change notification settings - Fork 6
Open
Description
The sample at https://github.com/redhat-developer/intellij-redhat-telemetry?tab=readme-ov-file#create-a-telemetry-singleton suggest to create a class like this:
public class TelemetryService {
private static final TelemetryService INSTANCE = new TelemetryService();
private final Lazy<TelemetryMessageBuilder> builder = new Lazy<>(() -> new TelemetryMessageBuilder(TelemetryService.class.getClassLoader()));
public static TelemetryMessageBuilder instance() {
return INSTANCE.builder.get();
}
}If you see Jetbrains code, when they declare singleton, they use applicationService, see
https://github.com/search?q=repo%3AJetBrains%2Fintellij-community%20getInstance&type=code
It would be nice to add the following sample code too:
package com.youapp.telemetry;
public class TelemetryService implements Disposable {
private static final TelemetryService INSTANCE = new TelemetryService();
private final Lazy<TelemetryMessageBuilder> builder = new Lazy<>(() -> new TelemetryMessageBuilder(TelemetryService.class.getClassLoader()));
public static TelemetryMessageBuilder instance() {
return getInstance().builder.get();
}
private static TelemetryService getInstance() {
return ApplicationManager.getApplication().getService(TelemetryService.class);
}
@Override
public void dispose() {
// Do something when IJ IDEA is closing
}
}And declare in the plugin.xml the application service:
<applicationService
serviceImplementation="com.youapp.telemetry.TelemetryService"/>adietish
Metadata
Metadata
Assignees
Labels
No labels