Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get runmode in java using resourceResolver

Tags:

aem

aem-6

I have an OSGi service which needs to run only in publish instance. How do I get runmode in java when I only have a resourceResolver and not request ?

like image 450
Ajay Avatar asked Nov 27 '25 00:11

Ajay


1 Answers

To get a list of run modes the current AEM instance is using you can use the SlingSettingService in your service and/or servlet.

import org.apache.felix.scr.annotations.Component;
import org.apache.sling.settings.SlingSettingsService;

@Component
public class MyService {

    @Reference
    private SlingSettingsService slingSettingsService;

    private boolean isPublish() {
        return this.slingSettingsService.getRunModes().contains("publish");
    }
}

See:

AEM 6.1: https://docs.adobe.com/docs/en/aem/6-1/ref/javadoc/org/apache/sling/settings/SlingSettingsService.html

AEM 6.2: https://docs.adobe.com/docs/en/aem/6-2/develop/ref/javadoc/org/apache/sling/settings/SlingSettingsService.html

AEM 6.3: https://helpx.adobe.com/experience-manager/6-3/sites/developing/using/reference-materials/javadoc/org/apache/sling/settings/SlingSettingsService.html

AEM 6.4: https://helpx.adobe.com/experience-manager/6-4/sites/developing/using/reference-materials/javadoc/org/apache/sling/settings/SlingSettingsService.html

like image 166
Jens Avatar answered Nov 29 '25 22:11

Jens



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!