2

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 ?

Ajay
  • 421
  • 3
  • 17
  • 4
    Possible duplicate of [Determine runmode in Adobe CQ](http://stackoverflow.com/questions/12245751/determine-runmode-in-adobe-cq) – Abhishek Sep 23 '16 at 17:09

1 Answers1

9

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

Jens
  • 20,533
  • 11
  • 60
  • 86