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

Add sample with applicationService to create the telemetry singleton. #93

Open
angelozerr opened this issue Sep 5, 2024 · 1 comment

Comments

@angelozerr
Copy link

angelozerr commented Sep 5, 2024

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
Copy link
Contributor

@angelozerr thanks for the suggestion. Very good idea, I'll do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants