Skip to content

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

@angelozerr

Description

@angelozerr

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"/>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions