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 ?
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: