Detect instance runmode programmatically in AEM as cloud service | Community
Skip to main content
rampai
Community Advisor
Community Advisor
August 11, 2021
Solved

Detect instance runmode programmatically in AEM as cloud service

  • August 11, 2021
  • 3 replies
  • 7382 views

Hi All,

 

Is there any alternative to detect run-mode of instance in AEM as cloud service as slingSettingsService shows as deprecated?

 

The use case is to execute code only on author or publish instances but not both.

 

Thanks,

Ram

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by joerghoh

Not sure if this blog article has been specifically been written for you 🙂 But it adresses your question quite good:

 

https://blog.osoco.de/2021/07/the-truth-about-aem-run-modes/

 

 

3 replies

Asutosh_Jena_
Community Advisor
Community Advisor
August 11, 2021

Hi @rampai 

 

The solution is still in planning phase and no API is exposed like SlingSettingService to get the run mode.

https://github.com/Adobe-Consulting-Services/acs-aem-commons/issues/2476

 

In the mean time you can create an OSGi service and set the run mode config value in OSGi configuration and read it in your code. That should resolve the issue.

Here is an article which will give a good idea:

https://cqdump.joerghoh.de/2018/09/12/referencing-runmodes-in-java/

 

Thanks!

Shubham_borole
Community Advisor
Community Advisor
August 11, 2021

Hello,

 

Please check https://medium.com/adobetech/custom-runmodes-on-aem-as-a-cloud-service-79b757f51a6b for custom runmodes (not to be used or used cautiously) which discusses about some good practices.

It seems to provide an example of refactored code.

From the reference above, we can try this

@Property(label = "Environment Type",
        description = "Should be dev/stage/prod/local - default is local")
private static final String ENVIRONMENT_TYPE = "environment.type";
private String environmentType;

@Activate
@Modified
protected void activate(final Map<String, String> config) {
    environmentType = PropertiesUtil.toString(config.get(ENVIRONMENT_TYPE), DEFAULT_ENVIRONMENT_TYPE);
    log.debug("Environment Type Service Activated with Environment Type of {}", environmentType);
}



public String getEnvironmentType() {
    return environmentType;
}
joerghoh
Adobe Employee
joerghohAdobe EmployeeAccepted solution
Adobe Employee
August 16, 2021

Not sure if this blog article has been specifically been written for you 🙂 But it adresses your question quite good:

 

https://blog.osoco.de/2021/07/the-truth-about-aem-run-modes/