What is the proper way to IIORegistry.registerServiceProvider

Answered
I want to register a ImageReaderSpi. Here is my code. I must set preload="true". But IDE said I cannot use this outside IntelliJ.

 

 

```xml
<extensions defaultExtensionNs="com.intellij">
    <fileType name="Image" extensions="qoi"/>
    <applicationService serviceImplementation="io.github.xiaozhuai.jetbrains.qoi.QOIMetadataRegistrar" preload="true"/>
</extensions>
```

 

```java
package io.github.xiaozhuai.jetbrains.qoi;

 

import javax.imageio.spi.IIORegistry;
import javax.imageio.spi.ImageReaderSpi;
import javax.imageio.spi.ImageWriterSpi;

 

public class QOIMetadataRegistrar {
    public QOIMetadataRegistrar() {
        ensureQoiRegistered();
    }

 

    public static void ensureQoiRegistered() {
        IIORegistry defaultInstance = IIORegistry.getDefaultInstance();
        defaultInstance.registerServiceProvider(new QOIImageReaderSpi(), ImageReaderSpi.class);
        defaultInstance.registerServiceProvider(new QOIImageWriterSpi(), ImageWriterSpi.class);
    }
}
```
2 comments
Comment actions Permalink

Hi,

Please consider delaying loading these classes until the first usage. This is the recommended approach.

If you still want to load it as soon as possible, consider using PreloadingActivity:
https://upsource.jetbrains.com/idea-ce/file/idea-ce-6ed4281aa53e1672d2e5870243c6606bb48afc84/platform/ide-core/src/com/intellij/openapi/application/PreloadingActivity.java

0
Comment actions Permalink

Thanks for your suggestion! I succeed using PreloadingActivity with require-restart="true"

0

Please sign in to leave a comment.